1 | The following changes since commit 98bfaac788be0ca63d7d010c8d4ba100ff1d8278: | 1 | The following changes since commit 281f327487c9c9b1599f93c589a408bbf4a651b8: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2017-09-01-v3' into staging (2017-09-04 13:28:09 +0100) | 3 | Merge remote-tracking branch 'remotes/vivier/tags/m68k-for-2.12-pull-request' into staging (2017-12-22 00:11:36 +0000) |
4 | 4 | ||
5 | are available in the git repository at: | 5 | are available in the git repository at: |
6 | 6 | ||
7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream | 7 | git://repo.or.cz/qemu/kevin.git tags/for-upstream |
8 | 8 | ||
9 | for you to fetch changes up to 83a8c775a8bf134eb18a719322939b74a818d750: | 9 | for you to fetch changes up to 1a63a907507fbbcfaee3f622907ec244b7eabda8: |
10 | 10 | ||
11 | qcow2: move qcow2_store_persistent_dirty_bitmaps() before cache flushing (2017-09-06 14:40:18 +0200) | 11 | block: Keep nodes drained between reopen_queue/multiple (2017-12-22 15:05:32 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block layer patches | 14 | Block layer patches |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Daniel P. Berrange (1): | 17 | Doug Gale (1): |
18 | block: document semantics of bdrv_co_preadv|pwritev | 18 | nvme: Add tracing |
19 | 19 | ||
20 | Eric Blake (2): | 20 | Edgar Kaziakhmedov (1): |
21 | qcow: Change signature of get_cluster_offset() | 21 | qcow2: get rid of qcow2_backing_read1 routine |
22 | qcow: Check failure of bdrv_getlength() and bdrv_truncate() | ||
23 | 22 | ||
24 | Manos Pitsidianakis (10): | 23 | Fam Zheng (2): |
25 | block: pass bdrv_* methods to bs->file by default in block filters | 24 | block: Open backing image in force share mode for size probe |
26 | block: remove unused bdrv_media_changed | 25 | block: Remove unused bdrv_requests_pending |
27 | block: remove bdrv_truncate callback in blkdebug | ||
28 | block: add default implementations for bdrv_co_get_block_status() | ||
29 | block: move ThrottleGroup membership to ThrottleGroupMember | ||
30 | block: add aio_context field in ThrottleGroupMember | ||
31 | block: tidy ThrottleGroupMember initializations | ||
32 | block: convert ThrottleGroup to object with QOM | ||
33 | block: add throttle block filter driver | ||
34 | qemu-iotests: add 184 for throttle filter driver | ||
35 | 26 | ||
36 | Pavel Butsykin (1): | 27 | John Snow (1): |
37 | qcow2: move qcow2_store_persistent_dirty_bitmaps() before cache flushing | 28 | iotests: fix 197 for vpc |
38 | 29 | ||
39 | qapi/block-core.json | 66 +++- | 30 | Kevin Wolf (27): |
40 | include/block/block.h | 1 - | 31 | block: Formats don't need CONSISTENT_READ with NO_IO |
41 | include/block/block_int.h | 56 ++- | 32 | block: Make bdrv_drain_invoke() recursive |
42 | include/block/throttle-groups.h | 52 ++- | 33 | block: Call .drain_begin only once in bdrv_drain_all_begin() |
43 | include/qemu/throttle-options.h | 60 +++- | 34 | test-bdrv-drain: Test BlockDriver callbacks for drain |
44 | include/qemu/throttle.h | 3 + | 35 | block: bdrv_drain_recurse(): Remove unused begin parameter |
45 | include/sysemu/block-backend.h | 20 +- | 36 | block: Don't wait for requests in bdrv_drain*_end() |
46 | block.c | 35 +- | 37 | block: Unify order in drain functions |
47 | block/blkdebug.c | 20 +- | 38 | block: Don't acquire AioContext in hmp_qemu_io() |
48 | block/block-backend.c | 62 ++-- | 39 | block: Document that x-blockdev-change breaks quorum children list |
49 | block/commit.c | 12 +- | 40 | block: Assert drain_all is only called from main AioContext |
50 | block/io.c | 26 ++ | 41 | block: Make bdrv_drain() driver callbacks non-recursive |
51 | block/mirror.c | 12 +- | 42 | test-bdrv-drain: Test callback for bdrv_drain |
52 | block/qapi.c | 8 +- | 43 | test-bdrv-drain: Test bs->quiesce_counter |
53 | block/qcow.c | 153 ++++---- | 44 | blockjob: Pause job on draining any job BDS |
54 | block/qcow2.c | 16 +- | 45 | test-bdrv-drain: Test drain vs. block jobs |
55 | block/raw-format.c | 6 - | 46 | block: Don't block_job_pause_all() in bdrv_drain_all() |
56 | block/throttle-groups.c | 750 ++++++++++++++++++++++++++++++---------- | 47 | block: Nested drain_end must still call callbacks |
57 | block/throttle.c | 237 +++++++++++++ | 48 | test-bdrv-drain: Test nested drain sections |
58 | blockdev.c | 4 +- | 49 | block: Don't notify parents in drain call chain |
59 | tests/test-throttle.c | 111 +++--- | 50 | block: Add bdrv_subtree_drained_begin/end() |
60 | util/throttle.c | 151 ++++++++ | 51 | test-bdrv-drain: Tests for bdrv_subtree_drain |
61 | block/Makefile.objs | 1 + | 52 | test-bdrv-drain: Test behaviour in coroutine context |
62 | tests/qemu-iotests/184 | 205 +++++++++++ | 53 | test-bdrv-drain: Recursive draining with multiple parents |
63 | tests/qemu-iotests/184.out | 302 ++++++++++++++++ | 54 | block: Allow graph changes in subtree drained section |
64 | tests/qemu-iotests/group | 1 + | 55 | test-bdrv-drain: Test graph changes in drained section |
65 | 26 files changed, 1917 insertions(+), 453 deletions(-) | 56 | commit: Simplify reopen of base |
66 | create mode 100644 block/throttle.c | 57 | block: Keep nodes drained between reopen_queue/multiple |
67 | create mode 100755 tests/qemu-iotests/184 | ||
68 | create mode 100644 tests/qemu-iotests/184.out | ||
69 | 58 | ||
59 | Thomas Huth (3): | ||
60 | block: Remove the obsolete -drive boot=on|off parameter | ||
61 | block: Remove the deprecated -hdachs option | ||
62 | block: Mention -drive cyls/heads/secs/trans/serial/addr in deprecation chapter | ||
63 | |||
64 | qapi/block-core.json | 4 + | ||
65 | block/qcow2.h | 3 - | ||
66 | include/block/block.h | 15 +- | ||
67 | include/block/block_int.h | 6 +- | ||
68 | block.c | 75 ++++- | ||
69 | block/commit.c | 8 +- | ||
70 | block/io.c | 164 +++++++--- | ||
71 | block/qcow2.c | 51 +-- | ||
72 | block/replication.c | 6 + | ||
73 | blockdev.c | 11 - | ||
74 | blockjob.c | 22 +- | ||
75 | hmp.c | 6 - | ||
76 | hw/block/nvme.c | 349 +++++++++++++++++---- | ||
77 | qemu-io-cmds.c | 3 + | ||
78 | tests/test-bdrv-drain.c | 651 +++++++++++++++++++++++++++++++++++++++ | ||
79 | vl.c | 86 +----- | ||
80 | hw/block/trace-events | 93 ++++++ | ||
81 | qemu-doc.texi | 29 +- | ||
82 | qemu-options.hx | 19 +- | ||
83 | tests/Makefile.include | 2 + | ||
84 | tests/qemu-iotests/197 | 4 + | ||
85 | tests/qemu-iotests/common.filter | 3 +- | ||
86 | 22 files changed, 1294 insertions(+), 316 deletions(-) | ||
87 | create mode 100644 tests/test-bdrv-drain.c | ||
88 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Commit 1f4ad7d fixed 'qemu-img info' for raw images that are currently | ||
2 | in use as a mirror target. It is not enough for image formats, though, | ||
3 | as these still unconditionally request BLK_PERM_CONSISTENT_READ. | ||
1 | 4 | ||
5 | As this permission is geared towards whether the guest-visible data is | ||
6 | consistent, and has no impact on whether the metadata is sane, and | ||
7 | 'qemu-img info' does not read guest-visible data (except for the raw | ||
8 | format), it makes sense to not require BLK_PERM_CONSISTENT_READ if there | ||
9 | is not going to be any guest I/O performed, regardless of image format. | ||
10 | |||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block.c | 6 +++++- | ||
14 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/block.c b/block.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block.c | ||
19 | +++ b/block.c | ||
20 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
21 | assert(role == &child_backing || role == &child_file); | ||
22 | |||
23 | if (!backing) { | ||
24 | + int flags = bdrv_reopen_get_flags(reopen_queue, bs); | ||
25 | + | ||
26 | /* Apart from the modifications below, the same permissions are | ||
27 | * forwarded and left alone as for filters */ | ||
28 | bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, | ||
29 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | ||
30 | |||
31 | /* bs->file always needs to be consistent because of the metadata. We | ||
32 | * can never allow other users to resize or write to it. */ | ||
33 | - perm |= BLK_PERM_CONSISTENT_READ; | ||
34 | + if (!(flags & BDRV_O_NO_IO)) { | ||
35 | + perm |= BLK_PERM_CONSISTENT_READ; | ||
36 | + } | ||
37 | shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); | ||
38 | } else { | ||
39 | /* We want consistent read from backing files if the parent needs it. | ||
40 | -- | ||
41 | 2.13.6 | ||
42 | |||
43 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | VPC has some difficulty creating geometries of particular size. | ||
4 | However, we can indeed force it to use a literal one, so let's | ||
5 | do that for the sake of test 197, which is testing some specific | ||
6 | offsets. | ||
7 | |||
8 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | Reviewed-by: Lukáš Doktor <ldoktor@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/197 | 4 ++++ | ||
15 | tests/qemu-iotests/common.filter | 3 ++- | ||
16 | 2 files changed, 6 insertions(+), 1 deletion(-) | ||
17 | |||
18 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 | ||
19 | index XXXXXXX..XXXXXXX 100755 | ||
20 | --- a/tests/qemu-iotests/197 | ||
21 | +++ b/tests/qemu-iotests/197 | ||
22 | @@ -XXX,XX +XXX,XX @@ echo '=== Copy-on-read ===' | ||
23 | echo | ||
24 | |||
25 | # Prep the images | ||
26 | +# VPC rounds image sizes to a specific geometry, force a specific size. | ||
27 | +if [ "$IMGFMT" = "vpc" ]; then | ||
28 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size") | ||
29 | +fi | ||
30 | _make_test_img 4G | ||
31 | $QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io | ||
32 | IMGPROTO=file IMGFMT=qcow2 IMGOPTS= TEST_IMG_FILE="$TEST_WRAP" \ | ||
33 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/tests/qemu-iotests/common.filter | ||
36 | +++ b/tests/qemu-iotests/common.filter | ||
37 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | ||
38 | -e "s# log_size=[0-9]\\+##g" \ | ||
39 | -e "s# refcount_bits=[0-9]\\+##g" \ | ||
40 | -e "s# key-secret=[a-zA-Z0-9]\\+##g" \ | ||
41 | - -e "s# iter-time=[0-9]\\+##g" | ||
42 | + -e "s# iter-time=[0-9]\\+##g" \ | ||
43 | + -e "s# force_size=\\(on\\|off\\)##g" | ||
44 | } | ||
45 | |||
46 | _filter_img_info() | ||
47 | -- | ||
48 | 2.13.6 | ||
49 | |||
50 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This change separates bdrv_drain_invoke(), which calls the BlockDriver | ||
2 | drain callbacks, from bdrv_drain_recurse(). Instead, the function | ||
3 | performs its own recursion now. | ||
1 | 4 | ||
5 | One reason for this is that bdrv_drain_recurse() can be called multiple | ||
6 | times by bdrv_drain_all_begin(), but the callbacks may only be called | ||
7 | once. The separation is necessary to fix this bug. | ||
8 | |||
9 | The other reason is that we intend to go to a model where we call all | ||
10 | driver callbacks first, and only then start polling. This is not fully | ||
11 | achieved yet with this patch, as bdrv_drain_invoke() contains a | ||
12 | BDRV_POLL_WHILE() loop for the block driver callbacks, which can still | ||
13 | call callbacks for any unrelated event. It's a step in this direction | ||
14 | anyway. | ||
15 | |||
16 | Cc: qemu-stable@nongnu.org | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | --- | ||
20 | block/io.c | 14 +++++++++++--- | ||
21 | 1 file changed, 11 insertions(+), 3 deletions(-) | ||
22 | |||
23 | diff --git a/block/io.c b/block/io.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/block/io.c | ||
26 | +++ b/block/io.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) | ||
28 | bdrv_wakeup(bs); | ||
29 | } | ||
30 | |||
31 | +/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ | ||
32 | static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) | ||
33 | { | ||
34 | + BdrvChild *child, *tmp; | ||
35 | BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; | ||
36 | |||
37 | if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) || | ||
38 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) | ||
39 | data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data); | ||
40 | bdrv_coroutine_enter(bs, data.co); | ||
41 | BDRV_POLL_WHILE(bs, !data.done); | ||
42 | + | ||
43 | + QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { | ||
44 | + bdrv_drain_invoke(child->bs, begin); | ||
45 | + } | ||
46 | } | ||
47 | |||
48 | static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) | ||
49 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) | ||
50 | BdrvChild *child, *tmp; | ||
51 | bool waited; | ||
52 | |||
53 | - /* Ensure any pending metadata writes are submitted to bs->file. */ | ||
54 | - bdrv_drain_invoke(bs, begin); | ||
55 | - | ||
56 | /* Wait for drained requests to finish */ | ||
57 | waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) | ||
60 | bdrv_parent_drained_begin(bs); | ||
61 | } | ||
62 | |||
63 | + bdrv_drain_invoke(bs, true); | ||
64 | bdrv_drain_recurse(bs, true); | ||
65 | } | ||
66 | |||
67 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
68 | } | ||
69 | |||
70 | bdrv_parent_drained_end(bs); | ||
71 | + bdrv_drain_invoke(bs, false); | ||
72 | bdrv_drain_recurse(bs, false); | ||
73 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
74 | } | ||
75 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
76 | aio_context_acquire(aio_context); | ||
77 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
78 | if (aio_context == bdrv_get_aio_context(bs)) { | ||
79 | + /* FIXME Calling this multiple times is wrong */ | ||
80 | + bdrv_drain_invoke(bs, true); | ||
81 | waited |= bdrv_drain_recurse(bs, true); | ||
82 | } | ||
83 | } | ||
84 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
85 | aio_context_acquire(aio_context); | ||
86 | aio_enable_external(aio_context); | ||
87 | bdrv_parent_drained_end(bs); | ||
88 | + bdrv_drain_invoke(bs, false); | ||
89 | bdrv_drain_recurse(bs, false); | ||
90 | aio_context_release(aio_context); | ||
91 | } | ||
92 | -- | ||
93 | 2.13.6 | ||
94 | |||
95 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | bdrv_drain_all_begin() used to call the .bdrv_co_drain_begin() driver | ||
2 | callback inside its polling loop. This means that how many times it got | ||
3 | called for each node depended on long it had to poll the event loop. | ||
1 | 4 | ||
5 | This is obviously not right and results in nodes that stay drained even | ||
6 | after bdrv_drain_all_end(), which calls .bdrv_co_drain_begin() once per | ||
7 | node. | ||
8 | |||
9 | Fix bdrv_drain_all_begin() to call the callback only once, too. | ||
10 | |||
11 | Cc: qemu-stable@nongnu.org | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | block/io.c | 3 +-- | ||
16 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/block/io.c b/block/io.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/io.c | ||
21 | +++ b/block/io.c | ||
22 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
23 | aio_context_acquire(aio_context); | ||
24 | bdrv_parent_drained_begin(bs); | ||
25 | aio_disable_external(aio_context); | ||
26 | + bdrv_drain_invoke(bs, true); | ||
27 | aio_context_release(aio_context); | ||
28 | |||
29 | if (!g_slist_find(aio_ctxs, aio_context)) { | ||
30 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
31 | aio_context_acquire(aio_context); | ||
32 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
33 | if (aio_context == bdrv_get_aio_context(bs)) { | ||
34 | - /* FIXME Calling this multiple times is wrong */ | ||
35 | - bdrv_drain_invoke(bs, true); | ||
36 | waited |= bdrv_drain_recurse(bs, true); | ||
37 | } | ||
38 | } | ||
39 | -- | ||
40 | 2.13.6 | ||
41 | |||
42 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | This adds a test case that the BlockDriver callbacks for drain are |
---|---|---|---|
2 | called in bdrv_drained_all_begin/end(), and that both of them are called | ||
3 | exactly once. | ||
2 | 4 | ||
3 | block/throttle.c uses existing I/O throttle infrastructure inside a | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
4 | block filter driver. I/O operations are intercepted in the filter's | 6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | read/write coroutines, and referred to block/throttle-groups.c | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
8 | --- | ||
9 | tests/test-bdrv-drain.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++ | ||
10 | tests/Makefile.include | 2 + | ||
11 | 2 files changed, 139 insertions(+) | ||
12 | create mode 100644 tests/test-bdrv-drain.c | ||
6 | 13 | ||
7 | The driver can be used with the syntax | 14 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
8 | -drive driver=throttle,file.filename=foo.qcow2,throttle-group=bar | ||
9 | |||
10 | which registers the throttle filter node with the ThrottleGroup 'bar'. The | ||
11 | given group must be created beforehand with object-add or -object. | ||
12 | |||
13 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
14 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
17 | --- | ||
18 | qapi/block-core.json | 18 ++- | ||
19 | include/block/throttle-groups.h | 5 + | ||
20 | include/qemu/throttle-options.h | 1 + | ||
21 | block/throttle-groups.c | 15 ++- | ||
22 | block/throttle.c | 237 ++++++++++++++++++++++++++++++++++++++++ | ||
23 | block/Makefile.objs | 1 + | ||
24 | 6 files changed, 275 insertions(+), 2 deletions(-) | ||
25 | create mode 100644 block/throttle.c | ||
26 | |||
27 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/qapi/block-core.json | ||
30 | +++ b/qapi/block-core.json | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | # Drivers that are supported in block device operations. | ||
33 | # | ||
34 | # @vxhs: Since 2.10 | ||
35 | +# @throttle: Since 2.11 | ||
36 | # | ||
37 | # Since: 2.9 | ||
38 | ## | ||
39 | @@ -XXX,XX +XXX,XX @@ | ||
40 | 'host_device', 'http', 'https', 'iscsi', 'luks', 'nbd', 'nfs', | ||
41 | 'null-aio', 'null-co', 'parallels', 'qcow', 'qcow2', 'qed', | ||
42 | 'quorum', 'raw', 'rbd', 'replication', 'sheepdog', 'ssh', | ||
43 | - 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } | ||
44 | + 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] } | ||
45 | |||
46 | ## | ||
47 | # @BlockdevOptionsFile: | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | '*tls-creds': 'str' } } | ||
50 | |||
51 | ## | ||
52 | +# @BlockdevOptionsThrottle: | ||
53 | +# | ||
54 | +# Driver specific block device options for the throttle driver | ||
55 | +# | ||
56 | +# @throttle-group: the name of the throttle-group object to use. It | ||
57 | +# must already exist. | ||
58 | +# @file: reference to or definition of the data source block device | ||
59 | +# Since: 2.11 | ||
60 | +## | ||
61 | +{ 'struct': 'BlockdevOptionsThrottle', | ||
62 | + 'data': { 'throttle-group': 'str', | ||
63 | + 'file' : 'BlockdevRef' | ||
64 | + } } | ||
65 | +## | ||
66 | # @BlockdevOptions: | ||
67 | # | ||
68 | # Options for creating a block device. Many options are available for all | ||
69 | @@ -XXX,XX +XXX,XX @@ | ||
70 | 'replication':'BlockdevOptionsReplication', | ||
71 | 'sheepdog': 'BlockdevOptionsSheepdog', | ||
72 | 'ssh': 'BlockdevOptionsSsh', | ||
73 | + 'throttle': 'BlockdevOptionsThrottle', | ||
74 | 'vdi': 'BlockdevOptionsGenericFormat', | ||
75 | 'vhdx': 'BlockdevOptionsGenericFormat', | ||
76 | 'vmdk': 'BlockdevOptionsGenericCOWFormat', | ||
77 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/include/block/throttle-groups.h | ||
80 | +++ b/include/block/throttle-groups.h | ||
81 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm | ||
82 | void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, | ||
83 | AioContext *new_context); | ||
84 | void throttle_group_detach_aio_context(ThrottleGroupMember *tgm); | ||
85 | +/* | ||
86 | + * throttle_group_exists() must be called under the global | ||
87 | + * mutex. | ||
88 | + */ | ||
89 | +bool throttle_group_exists(const char *name); | ||
90 | |||
91 | #endif | ||
92 | diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/include/qemu/throttle-options.h | ||
95 | +++ b/include/qemu/throttle-options.h | ||
96 | @@ -XXX,XX +XXX,XX @@ | ||
97 | #define QEMU_OPT_BPS_WRITE_MAX "bps-write-max" | ||
98 | #define QEMU_OPT_BPS_WRITE_MAX_LENGTH "bps-write-max-length" | ||
99 | #define QEMU_OPT_IOPS_SIZE "iops-size" | ||
100 | +#define QEMU_OPT_THROTTLE_GROUP_NAME "throttle-group" | ||
101 | |||
102 | #define THROTTLE_OPT_PREFIX "throttling." | ||
103 | #define THROTTLE_OPTS \ | ||
104 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/block/throttle-groups.c | ||
107 | +++ b/block/throttle-groups.c | ||
108 | @@ -XXX,XX +XXX,XX @@ static ThrottleGroup *throttle_group_by_name(const char *name) | ||
109 | return NULL; | ||
110 | } | ||
111 | |||
112 | +/* This function reads throttle_groups and must be called under the global | ||
113 | + * mutex. | ||
114 | + */ | ||
115 | +bool throttle_group_exists(const char *name) | ||
116 | +{ | ||
117 | + return throttle_group_by_name(name) != NULL; | ||
118 | +} | ||
119 | + | ||
120 | /* Increments the reference count of a ThrottleGroup given its name. | ||
121 | * | ||
122 | * If no ThrottleGroup is found with the given name a new one is | ||
123 | @@ -XXX,XX +XXX,XX @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) | ||
124 | ThrottleGroupMember *token; | ||
125 | int i; | ||
126 | |||
127 | + if (!ts) { | ||
128 | + /* Discard already unregistered tgm */ | ||
129 | + return; | ||
130 | + } | ||
131 | + | ||
132 | assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0); | ||
133 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); | ||
134 | assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); | ||
135 | @@ -XXX,XX +XXX,XX @@ static void throttle_group_obj_complete(UserCreatable *obj, Error **errp) | ||
136 | assert(tg->name); | ||
137 | |||
138 | /* error if name is duplicate */ | ||
139 | - if (throttle_group_by_name(tg->name) != NULL) { | ||
140 | + if (throttle_group_exists(tg->name)) { | ||
141 | error_setg(errp, "A group with this name already exists"); | ||
142 | return; | ||
143 | } | ||
144 | diff --git a/block/throttle.c b/block/throttle.c | ||
145 | new file mode 100644 | 15 | new file mode 100644 |
146 | index XXXXXXX..XXXXXXX | 16 | index XXXXXXX..XXXXXXX |
147 | --- /dev/null | 17 | --- /dev/null |
148 | +++ b/block/throttle.c | 18 | +++ b/tests/test-bdrv-drain.c |
149 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
150 | +/* | 20 | +/* |
151 | + * QEMU block throttling filter driver infrastructure | 21 | + * Block node draining tests |
152 | + * | 22 | + * |
153 | + * Copyright (c) 2017 Manos Pitsidianakis | 23 | + * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com> |
154 | + * | 24 | + * |
155 | + * This program is free software; you can redistribute it and/or | 25 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
156 | + * modify it under the terms of the GNU General Public License as | 26 | + * of this software and associated documentation files (the "Software"), to deal |
157 | + * published by the Free Software Foundation; either version 2 or | 27 | + * in the Software without restriction, including without limitation the rights |
158 | + * (at your option) version 3 of the License. | 28 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
29 | + * copies of the Software, and to permit persons to whom the Software is | ||
30 | + * furnished to do so, subject to the following conditions: | ||
159 | + * | 31 | + * |
160 | + * This program is distributed in the hope that it will be useful, | 32 | + * The above copyright notice and this permission notice shall be included in |
161 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 33 | + * all copies or substantial portions of the Software. |
162 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
163 | + * GNU General Public License for more details. | ||
164 | + * | 34 | + * |
165 | + * You should have received a copy of the GNU General Public License | 35 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
166 | + * along with this program; if not, see <http://www.gnu.org/licenses/>. | 36 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
37 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
38 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
39 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
40 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
41 | + * THE SOFTWARE. | ||
167 | + */ | 42 | + */ |
168 | + | 43 | + |
169 | +#include "qemu/osdep.h" | 44 | +#include "qemu/osdep.h" |
170 | +#include "block/throttle-groups.h" | 45 | +#include "block/block.h" |
171 | +#include "qemu/throttle-options.h" | 46 | +#include "sysemu/block-backend.h" |
172 | +#include "qapi/error.h" | 47 | +#include "qapi/error.h" |
173 | + | 48 | + |
174 | +static QemuOptsList throttle_opts = { | 49 | +typedef struct BDRVTestState { |
175 | + .name = "throttle", | 50 | + int drain_count; |
176 | + .head = QTAILQ_HEAD_INITIALIZER(throttle_opts.head), | 51 | +} BDRVTestState; |
177 | + .desc = { | ||
178 | + { | ||
179 | + .name = QEMU_OPT_THROTTLE_GROUP_NAME, | ||
180 | + .type = QEMU_OPT_STRING, | ||
181 | + .help = "Name of the throttle group", | ||
182 | + }, | ||
183 | + { /* end of list */ } | ||
184 | + }, | ||
185 | +}; | ||
186 | + | 52 | + |
187 | +static int throttle_configure_tgm(BlockDriverState *bs, | 53 | +static void coroutine_fn bdrv_test_co_drain_begin(BlockDriverState *bs) |
188 | + ThrottleGroupMember *tgm, | ||
189 | + QDict *options, Error **errp) | ||
190 | +{ | 54 | +{ |
191 | + int ret; | 55 | + BDRVTestState *s = bs->opaque; |
192 | + const char *group_name; | 56 | + s->drain_count++; |
193 | + Error *local_err = NULL; | ||
194 | + QemuOpts *opts = qemu_opts_create(&throttle_opts, NULL, 0, &error_abort); | ||
195 | + | ||
196 | + qemu_opts_absorb_qdict(opts, options, &local_err); | ||
197 | + if (local_err) { | ||
198 | + error_propagate(errp, local_err); | ||
199 | + ret = -EINVAL; | ||
200 | + goto fin; | ||
201 | + } | ||
202 | + | ||
203 | + group_name = qemu_opt_get(opts, QEMU_OPT_THROTTLE_GROUP_NAME); | ||
204 | + if (!group_name) { | ||
205 | + error_setg(errp, "Please specify a throttle group"); | ||
206 | + ret = -EINVAL; | ||
207 | + goto fin; | ||
208 | + } else if (!throttle_group_exists(group_name)) { | ||
209 | + error_setg(errp, "Throttle group '%s' does not exist", group_name); | ||
210 | + ret = -EINVAL; | ||
211 | + goto fin; | ||
212 | + } | ||
213 | + | ||
214 | + /* Register membership to group with name group_name */ | ||
215 | + throttle_group_register_tgm(tgm, group_name, bdrv_get_aio_context(bs)); | ||
216 | + ret = 0; | ||
217 | +fin: | ||
218 | + qemu_opts_del(opts); | ||
219 | + return ret; | ||
220 | +} | 57 | +} |
221 | + | 58 | + |
222 | +static int throttle_open(BlockDriverState *bs, QDict *options, | 59 | +static void coroutine_fn bdrv_test_co_drain_end(BlockDriverState *bs) |
223 | + int flags, Error **errp) | ||
224 | +{ | 60 | +{ |
225 | + ThrottleGroupMember *tgm = bs->opaque; | 61 | + BDRVTestState *s = bs->opaque; |
226 | + | 62 | + s->drain_count--; |
227 | + bs->file = bdrv_open_child(NULL, options, "file", bs, | ||
228 | + &child_file, false, errp); | ||
229 | + if (!bs->file) { | ||
230 | + return -EINVAL; | ||
231 | + } | ||
232 | + bs->supported_write_flags = bs->file->bs->supported_write_flags; | ||
233 | + bs->supported_zero_flags = bs->file->bs->supported_zero_flags; | ||
234 | + | ||
235 | + return throttle_configure_tgm(bs, tgm, options, errp); | ||
236 | +} | 63 | +} |
237 | + | 64 | + |
238 | +static void throttle_close(BlockDriverState *bs) | 65 | +static void bdrv_test_close(BlockDriverState *bs) |
239 | +{ | 66 | +{ |
240 | + ThrottleGroupMember *tgm = bs->opaque; | 67 | + BDRVTestState *s = bs->opaque; |
241 | + throttle_group_unregister_tgm(tgm); | 68 | + g_assert_cmpint(s->drain_count, >, 0); |
242 | +} | 69 | +} |
243 | + | 70 | + |
244 | + | 71 | +static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, |
245 | +static int64_t throttle_getlength(BlockDriverState *bs) | ||
246 | +{ | ||
247 | + return bdrv_getlength(bs->file->bs); | ||
248 | +} | ||
249 | + | ||
250 | +static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, | ||
251 | + uint64_t offset, uint64_t bytes, | ||
252 | + QEMUIOVector *qiov, int flags) | ||
253 | +{ | ||
254 | + | ||
255 | + ThrottleGroupMember *tgm = bs->opaque; | ||
256 | + throttle_group_co_io_limits_intercept(tgm, bytes, false); | ||
257 | + | ||
258 | + return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); | ||
259 | +} | ||
260 | + | ||
261 | +static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs, | ||
262 | + uint64_t offset, uint64_t bytes, | 72 | + uint64_t offset, uint64_t bytes, |
263 | + QEMUIOVector *qiov, int flags) | 73 | + QEMUIOVector *qiov, int flags) |
264 | +{ | 74 | +{ |
265 | + ThrottleGroupMember *tgm = bs->opaque; | 75 | + /* We want this request to stay until the polling loop in drain waits for |
266 | + throttle_group_co_io_limits_intercept(tgm, bytes, true); | 76 | + * it to complete. We need to sleep a while as bdrv_drain_invoke() comes |
77 | + * first and polls its result, too, but it shouldn't accidentally complete | ||
78 | + * this request yet. */ | ||
79 | + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); | ||
267 | + | 80 | + |
268 | + return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); | 81 | + return 0; |
269 | +} | 82 | +} |
270 | + | 83 | + |
271 | +static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs, | 84 | +static BlockDriver bdrv_test = { |
272 | + int64_t offset, int bytes, | 85 | + .format_name = "test", |
273 | + BdrvRequestFlags flags) | 86 | + .instance_size = sizeof(BDRVTestState), |
87 | + | ||
88 | + .bdrv_close = bdrv_test_close, | ||
89 | + .bdrv_co_preadv = bdrv_test_co_preadv, | ||
90 | + | ||
91 | + .bdrv_co_drain_begin = bdrv_test_co_drain_begin, | ||
92 | + .bdrv_co_drain_end = bdrv_test_co_drain_end, | ||
93 | +}; | ||
94 | + | ||
95 | +static void aio_ret_cb(void *opaque, int ret) | ||
274 | +{ | 96 | +{ |
275 | + ThrottleGroupMember *tgm = bs->opaque; | 97 | + int *aio_ret = opaque; |
276 | + throttle_group_co_io_limits_intercept(tgm, bytes, true); | 98 | + *aio_ret = ret; |
277 | + | ||
278 | + return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); | ||
279 | +} | 99 | +} |
280 | + | 100 | + |
281 | +static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs, | 101 | +static void test_drv_cb_drain_all(void) |
282 | + int64_t offset, int bytes) | ||
283 | +{ | 102 | +{ |
284 | + ThrottleGroupMember *tgm = bs->opaque; | 103 | + BlockBackend *blk; |
285 | + throttle_group_co_io_limits_intercept(tgm, bytes, true); | 104 | + BlockDriverState *bs; |
105 | + BDRVTestState *s; | ||
106 | + BlockAIOCB *acb; | ||
107 | + int aio_ret; | ||
286 | + | 108 | + |
287 | + return bdrv_co_pdiscard(bs->file->bs, offset, bytes); | 109 | + QEMUIOVector qiov; |
110 | + struct iovec iov = { | ||
111 | + .iov_base = NULL, | ||
112 | + .iov_len = 0, | ||
113 | + }; | ||
114 | + qemu_iovec_init_external(&qiov, &iov, 1); | ||
115 | + | ||
116 | + blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
117 | + bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, | ||
118 | + &error_abort); | ||
119 | + s = bs->opaque; | ||
120 | + blk_insert_bs(blk, bs, &error_abort); | ||
121 | + | ||
122 | + /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */ | ||
123 | + g_assert_cmpint(s->drain_count, ==, 0); | ||
124 | + bdrv_drain_all_begin(); | ||
125 | + g_assert_cmpint(s->drain_count, ==, 1); | ||
126 | + bdrv_drain_all_end(); | ||
127 | + g_assert_cmpint(s->drain_count, ==, 0); | ||
128 | + | ||
129 | + /* Now do the same while a request is pending */ | ||
130 | + aio_ret = -EINPROGRESS; | ||
131 | + acb = blk_aio_preadv(blk, 0, &qiov, 0, aio_ret_cb, &aio_ret); | ||
132 | + g_assert(acb != NULL); | ||
133 | + g_assert_cmpint(aio_ret, ==, -EINPROGRESS); | ||
134 | + | ||
135 | + g_assert_cmpint(s->drain_count, ==, 0); | ||
136 | + bdrv_drain_all_begin(); | ||
137 | + g_assert_cmpint(aio_ret, ==, 0); | ||
138 | + g_assert_cmpint(s->drain_count, ==, 1); | ||
139 | + bdrv_drain_all_end(); | ||
140 | + g_assert_cmpint(s->drain_count, ==, 0); | ||
141 | + | ||
142 | + bdrv_unref(bs); | ||
143 | + blk_unref(blk); | ||
288 | +} | 144 | +} |
289 | + | 145 | + |
290 | +static int throttle_co_flush(BlockDriverState *bs) | 146 | +int main(int argc, char **argv) |
291 | +{ | 147 | +{ |
292 | + return bdrv_co_flush(bs->file->bs); | 148 | + bdrv_init(); |
149 | + qemu_init_main_loop(&error_abort); | ||
150 | + | ||
151 | + g_test_init(&argc, &argv, NULL); | ||
152 | + | ||
153 | + g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all); | ||
154 | + | ||
155 | + return g_test_run(); | ||
293 | +} | 156 | +} |
294 | + | 157 | diff --git a/tests/Makefile.include b/tests/Makefile.include |
295 | +static void throttle_detach_aio_context(BlockDriverState *bs) | ||
296 | +{ | ||
297 | + ThrottleGroupMember *tgm = bs->opaque; | ||
298 | + throttle_group_detach_aio_context(tgm); | ||
299 | +} | ||
300 | + | ||
301 | +static void throttle_attach_aio_context(BlockDriverState *bs, | ||
302 | + AioContext *new_context) | ||
303 | +{ | ||
304 | + ThrottleGroupMember *tgm = bs->opaque; | ||
305 | + throttle_group_attach_aio_context(tgm, new_context); | ||
306 | +} | ||
307 | + | ||
308 | +static int throttle_reopen_prepare(BDRVReopenState *reopen_state, | ||
309 | + BlockReopenQueue *queue, Error **errp) | ||
310 | +{ | ||
311 | + ThrottleGroupMember *tgm; | ||
312 | + | ||
313 | + assert(reopen_state != NULL); | ||
314 | + assert(reopen_state->bs != NULL); | ||
315 | + | ||
316 | + reopen_state->opaque = g_new0(ThrottleGroupMember, 1); | ||
317 | + tgm = reopen_state->opaque; | ||
318 | + | ||
319 | + return throttle_configure_tgm(reopen_state->bs, tgm, reopen_state->options, | ||
320 | + errp); | ||
321 | +} | ||
322 | + | ||
323 | +static void throttle_reopen_commit(BDRVReopenState *reopen_state) | ||
324 | +{ | ||
325 | + ThrottleGroupMember *old_tgm = reopen_state->bs->opaque; | ||
326 | + ThrottleGroupMember *new_tgm = reopen_state->opaque; | ||
327 | + | ||
328 | + throttle_group_unregister_tgm(old_tgm); | ||
329 | + g_free(old_tgm); | ||
330 | + reopen_state->bs->opaque = new_tgm; | ||
331 | + reopen_state->opaque = NULL; | ||
332 | +} | ||
333 | + | ||
334 | +static void throttle_reopen_abort(BDRVReopenState *reopen_state) | ||
335 | +{ | ||
336 | + ThrottleGroupMember *tgm = reopen_state->opaque; | ||
337 | + | ||
338 | + throttle_group_unregister_tgm(tgm); | ||
339 | + g_free(tgm); | ||
340 | + reopen_state->opaque = NULL; | ||
341 | +} | ||
342 | + | ||
343 | +static bool throttle_recurse_is_first_non_filter(BlockDriverState *bs, | ||
344 | + BlockDriverState *candidate) | ||
345 | +{ | ||
346 | + return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); | ||
347 | +} | ||
348 | + | ||
349 | +static BlockDriver bdrv_throttle = { | ||
350 | + .format_name = "throttle", | ||
351 | + .protocol_name = "throttle", | ||
352 | + .instance_size = sizeof(ThrottleGroupMember), | ||
353 | + | ||
354 | + .bdrv_file_open = throttle_open, | ||
355 | + .bdrv_close = throttle_close, | ||
356 | + .bdrv_co_flush = throttle_co_flush, | ||
357 | + | ||
358 | + .bdrv_child_perm = bdrv_filter_default_perms, | ||
359 | + | ||
360 | + .bdrv_getlength = throttle_getlength, | ||
361 | + | ||
362 | + .bdrv_co_preadv = throttle_co_preadv, | ||
363 | + .bdrv_co_pwritev = throttle_co_pwritev, | ||
364 | + | ||
365 | + .bdrv_co_pwrite_zeroes = throttle_co_pwrite_zeroes, | ||
366 | + .bdrv_co_pdiscard = throttle_co_pdiscard, | ||
367 | + | ||
368 | + .bdrv_recurse_is_first_non_filter = throttle_recurse_is_first_non_filter, | ||
369 | + | ||
370 | + .bdrv_attach_aio_context = throttle_attach_aio_context, | ||
371 | + .bdrv_detach_aio_context = throttle_detach_aio_context, | ||
372 | + | ||
373 | + .bdrv_reopen_prepare = throttle_reopen_prepare, | ||
374 | + .bdrv_reopen_commit = throttle_reopen_commit, | ||
375 | + .bdrv_reopen_abort = throttle_reopen_abort, | ||
376 | + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_file, | ||
377 | + | ||
378 | + .is_filter = true, | ||
379 | +}; | ||
380 | + | ||
381 | +static void bdrv_throttle_init(void) | ||
382 | +{ | ||
383 | + bdrv_register(&bdrv_throttle); | ||
384 | +} | ||
385 | + | ||
386 | +block_init(bdrv_throttle_init); | ||
387 | diff --git a/block/Makefile.objs b/block/Makefile.objs | ||
388 | index XXXXXXX..XXXXXXX 100644 | 158 | index XXXXXXX..XXXXXXX 100644 |
389 | --- a/block/Makefile.objs | 159 | --- a/tests/Makefile.include |
390 | +++ b/block/Makefile.objs | 160 | +++ b/tests/Makefile.include |
391 | @@ -XXX,XX +XXX,XX @@ block-obj-y += accounting.o dirty-bitmap.o | 161 | @@ -XXX,XX +XXX,XX @@ gcov-files-test-thread-pool-y = thread-pool.c |
392 | block-obj-y += write-threshold.o | 162 | gcov-files-test-hbitmap-y = util/hbitmap.c |
393 | block-obj-y += backup.o | 163 | check-unit-y += tests/test-hbitmap$(EXESUF) |
394 | block-obj-$(CONFIG_REPLICATION) += replication.o | 164 | gcov-files-test-hbitmap-y = blockjob.c |
395 | +block-obj-y += throttle.o | 165 | +check-unit-y += tests/test-bdrv-drain$(EXESUF) |
396 | 166 | check-unit-y += tests/test-blockjob$(EXESUF) | |
397 | block-obj-y += crypto.o | 167 | check-unit-y += tests/test-blockjob-txn$(EXESUF) |
398 | 168 | check-unit-y += tests/test-x86-cpuid$(EXESUF) | |
169 | @@ -XXX,XX +XXX,XX @@ tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) | ||
170 | tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) | ||
171 | tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-block-obj-y) | ||
172 | tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y) | ||
173 | +tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y) $(test-util-obj-y) | ||
174 | tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-util-obj-y) | ||
175 | tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y) | ||
176 | tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y) | ||
399 | -- | 177 | -- |
400 | 2.13.5 | 178 | 2.13.6 |
401 | 179 | ||
402 | 180 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Now that the bdrv_drain_invoke() calls are pulled up to the callers of | ||
2 | bdrv_drain_recurse(), the 'begin' parameter isn't needed any more. | ||
1 | 3 | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | block/io.c | 12 ++++++------ | ||
8 | 1 file changed, 6 insertions(+), 6 deletions(-) | ||
9 | |||
10 | diff --git a/block/io.c b/block/io.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/block/io.c | ||
13 | +++ b/block/io.c | ||
14 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) | ||
15 | } | ||
16 | } | ||
17 | |||
18 | -static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) | ||
19 | +static bool bdrv_drain_recurse(BlockDriverState *bs) | ||
20 | { | ||
21 | BdrvChild *child, *tmp; | ||
22 | bool waited; | ||
23 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) | ||
24 | */ | ||
25 | bdrv_ref(bs); | ||
26 | } | ||
27 | - waited |= bdrv_drain_recurse(bs, begin); | ||
28 | + waited |= bdrv_drain_recurse(bs); | ||
29 | if (in_main_loop) { | ||
30 | bdrv_unref(bs); | ||
31 | } | ||
32 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) | ||
33 | } | ||
34 | |||
35 | bdrv_drain_invoke(bs, true); | ||
36 | - bdrv_drain_recurse(bs, true); | ||
37 | + bdrv_drain_recurse(bs); | ||
38 | } | ||
39 | |||
40 | void bdrv_drained_end(BlockDriverState *bs) | ||
41 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
42 | |||
43 | bdrv_parent_drained_end(bs); | ||
44 | bdrv_drain_invoke(bs, false); | ||
45 | - bdrv_drain_recurse(bs, false); | ||
46 | + bdrv_drain_recurse(bs); | ||
47 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
48 | } | ||
49 | |||
50 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
51 | aio_context_acquire(aio_context); | ||
52 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
53 | if (aio_context == bdrv_get_aio_context(bs)) { | ||
54 | - waited |= bdrv_drain_recurse(bs, true); | ||
55 | + waited |= bdrv_drain_recurse(bs); | ||
56 | } | ||
57 | } | ||
58 | aio_context_release(aio_context); | ||
59 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
60 | aio_enable_external(aio_context); | ||
61 | bdrv_parent_drained_end(bs); | ||
62 | bdrv_drain_invoke(bs, false); | ||
63 | - bdrv_drain_recurse(bs, false); | ||
64 | + bdrv_drain_recurse(bs); | ||
65 | aio_context_release(aio_context); | ||
66 | } | ||
67 | |||
68 | -- | ||
69 | 2.13.6 | ||
70 | |||
71 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The device is drained, so there is no point in waiting for requests at | ||
2 | the end of the drained section. Remove the bdrv_drain_recurse() calls | ||
3 | there. | ||
1 | 4 | ||
5 | The bdrv_drain_recurse() calls were introduced in commit 481cad48e5e | ||
6 | in order to call the .bdrv_co_drain_end() driver callback. This is now | ||
7 | done by a separate bdrv_drain_invoke() call. | ||
8 | |||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | ||
13 | block/io.c | 2 -- | ||
14 | 1 file changed, 2 deletions(-) | ||
15 | |||
16 | diff --git a/block/io.c b/block/io.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/io.c | ||
19 | +++ b/block/io.c | ||
20 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
21 | |||
22 | bdrv_parent_drained_end(bs); | ||
23 | bdrv_drain_invoke(bs, false); | ||
24 | - bdrv_drain_recurse(bs); | ||
25 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
26 | } | ||
27 | |||
28 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
29 | aio_enable_external(aio_context); | ||
30 | bdrv_parent_drained_end(bs); | ||
31 | bdrv_drain_invoke(bs, false); | ||
32 | - bdrv_drain_recurse(bs); | ||
33 | aio_context_release(aio_context); | ||
34 | } | ||
35 | |||
36 | -- | ||
37 | 2.13.6 | ||
38 | |||
39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Drain requests are propagated to child nodes, parent nodes and directly | ||
2 | to the AioContext. The order in which this happened was different | ||
3 | between all combinations of drain/drain_all and begin/end. | ||
1 | 4 | ||
5 | The correct order is to keep children only drained when their parents | ||
6 | are also drained. This means that at the start of a drained section, the | ||
7 | AioContext needs to be drained first, the parents second and only then | ||
8 | the children. The correct order for the end of a drained section is the | ||
9 | opposite. | ||
10 | |||
11 | This patch changes the three other functions to follow the example of | ||
12 | bdrv_drained_begin(), which is the only one that got it right. | ||
13 | |||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | ||
17 | block/io.c | 12 ++++++++---- | ||
18 | 1 file changed, 8 insertions(+), 4 deletions(-) | ||
19 | |||
20 | diff --git a/block/io.c b/block/io.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/block/io.c | ||
23 | +++ b/block/io.c | ||
24 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | + /* Stop things in parent-to-child order */ | ||
29 | if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { | ||
30 | aio_disable_external(bdrv_get_aio_context(bs)); | ||
31 | bdrv_parent_drained_begin(bs); | ||
32 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | - bdrv_parent_drained_end(bs); | ||
37 | + /* Re-enable things in child-to-parent order */ | ||
38 | bdrv_drain_invoke(bs, false); | ||
39 | + bdrv_parent_drained_end(bs); | ||
40 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
41 | } | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
44 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
45 | AioContext *aio_context = bdrv_get_aio_context(bs); | ||
46 | |||
47 | + /* Stop things in parent-to-child order */ | ||
48 | aio_context_acquire(aio_context); | ||
49 | - bdrv_parent_drained_begin(bs); | ||
50 | aio_disable_external(aio_context); | ||
51 | + bdrv_parent_drained_begin(bs); | ||
52 | bdrv_drain_invoke(bs, true); | ||
53 | aio_context_release(aio_context); | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
56 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
57 | AioContext *aio_context = bdrv_get_aio_context(bs); | ||
58 | |||
59 | + /* Re-enable things in child-to-parent order */ | ||
60 | aio_context_acquire(aio_context); | ||
61 | - aio_enable_external(aio_context); | ||
62 | - bdrv_parent_drained_end(bs); | ||
63 | bdrv_drain_invoke(bs, false); | ||
64 | + bdrv_parent_drained_end(bs); | ||
65 | + aio_enable_external(aio_context); | ||
66 | aio_context_release(aio_context); | ||
67 | } | ||
68 | |||
69 | -- | ||
70 | 2.13.6 | ||
71 | |||
72 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Commit 15afd94a047 added code to acquire and release the AioContext in | ||
2 | qemuio_command(). This means that the lock is taken twice now in the | ||
3 | call path from hmp_qemu_io(). This causes BDRV_POLL_WHILE() to hang for | ||
4 | any requests issued to nodes in a non-mainloop AioContext. | ||
1 | 5 | ||
6 | Dropping the first locking from hmp_qemu_io() fixes the problem. | ||
7 | |||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | ||
11 | hmp.c | 6 ------ | ||
12 | 1 file changed, 6 deletions(-) | ||
13 | |||
14 | diff --git a/hmp.c b/hmp.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hmp.c | ||
17 | +++ b/hmp.c | ||
18 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) | ||
19 | { | ||
20 | BlockBackend *blk; | ||
21 | BlockBackend *local_blk = NULL; | ||
22 | - AioContext *aio_context; | ||
23 | const char* device = qdict_get_str(qdict, "device"); | ||
24 | const char* command = qdict_get_str(qdict, "command"); | ||
25 | Error *err = NULL; | ||
26 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | - aio_context = blk_get_aio_context(blk); | ||
31 | - aio_context_acquire(aio_context); | ||
32 | - | ||
33 | /* | ||
34 | * Notably absent: Proper permission management. This is sad, but it seems | ||
35 | * almost impossible to achieve without changing the semantics and thereby | ||
36 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) | ||
37 | */ | ||
38 | qemuio_command(blk, command); | ||
39 | |||
40 | - aio_context_release(aio_context); | ||
41 | - | ||
42 | fail: | ||
43 | blk_unref(local_blk); | ||
44 | hmp_handle_error(mon, &err); | ||
45 | -- | ||
46 | 2.13.6 | ||
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Pavel Butsykin <pbutsykin@virtuozzo.com> | 1 | From: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | After calling qcow2_inactivate(), all qcow2 caches must be flushed, but this | 3 | Since bdrv_co_preadv does all neccessary checks including |
4 | may not happen, because the last call qcow2_store_persistent_dirty_bitmaps() | 4 | reading after the end of the backing file, avoid duplication |
5 | can lead to marking l2/refcont cache as dirty. | 5 | of verification before bdrv_co_preadv call. |
6 | 6 | ||
7 | Let's move qcow2_store_persistent_dirty_bitmaps() before the caсhe flushing | 7 | Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> |
8 | to fix it. | 8 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
9 | 9 | Reviewed-by: Eric Blake <eblake@redhat.com> | |
10 | Cc: qemu-stable@nongnu.org | ||
11 | Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
13 | --- | 11 | --- |
14 | block/qcow2.c | 16 ++++++++-------- | 12 | block/qcow2.h | 3 --- |
15 | 1 file changed, 8 insertions(+), 8 deletions(-) | 13 | block/qcow2.c | 51 ++++++++------------------------------------------- |
14 | 2 files changed, 8 insertions(+), 46 deletions(-) | ||
16 | 15 | ||
16 | diff --git a/block/qcow2.h b/block/qcow2.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/qcow2.h | ||
19 | +++ b/block/qcow2.h | ||
20 | @@ -XXX,XX +XXX,XX @@ uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset) | ||
21 | } | ||
22 | |||
23 | /* qcow2.c functions */ | ||
24 | -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, | ||
25 | - int64_t sector_num, int nb_sectors); | ||
26 | - | ||
27 | int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size, | ||
28 | int refcount_order, bool generous_increase, | ||
29 | uint64_t *refblock_count); | ||
17 | diff --git a/block/qcow2.c b/block/qcow2.c | 30 | diff --git a/block/qcow2.c b/block/qcow2.c |
18 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/qcow2.c | 32 | --- a/block/qcow2.c |
20 | +++ b/block/qcow2.c | 33 | +++ b/block/qcow2.c |
21 | @@ -XXX,XX +XXX,XX @@ static int qcow2_inactivate(BlockDriverState *bs) | 34 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, |
22 | int ret, result = 0; | 35 | return status; |
23 | Error *local_err = NULL; | 36 | } |
24 | 37 | ||
25 | + qcow2_store_persistent_dirty_bitmaps(bs, &local_err); | 38 | -/* handle reading after the end of the backing file */ |
26 | + if (local_err != NULL) { | 39 | -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, |
27 | + result = -EINVAL; | 40 | - int64_t offset, int bytes) |
28 | + error_report_err(local_err); | 41 | -{ |
29 | + error_report("Persistent bitmaps are lost for node '%s'", | 42 | - uint64_t bs_size = bs->total_sectors * BDRV_SECTOR_SIZE; |
30 | + bdrv_get_device_or_node_name(bs)); | 43 | - int n1; |
31 | + } | 44 | - |
32 | + | 45 | - if ((offset + bytes) <= bs_size) { |
33 | ret = qcow2_cache_flush(bs, s->l2_table_cache); | 46 | - return bytes; |
34 | if (ret) { | ||
35 | result = ret; | ||
36 | @@ -XXX,XX +XXX,XX @@ static int qcow2_inactivate(BlockDriverState *bs) | ||
37 | strerror(-ret)); | ||
38 | } | ||
39 | |||
40 | - qcow2_store_persistent_dirty_bitmaps(bs, &local_err); | ||
41 | - if (local_err != NULL) { | ||
42 | - result = -EINVAL; | ||
43 | - error_report_err(local_err); | ||
44 | - error_report("Persistent bitmaps are lost for node '%s'", | ||
45 | - bdrv_get_device_or_node_name(bs)); | ||
46 | - } | 47 | - } |
47 | - | 48 | - |
48 | if (result == 0) { | 49 | - if (offset >= bs_size) { |
49 | qcow2_mark_clean(bs); | 50 | - n1 = 0; |
50 | } | 51 | - } else { |
52 | - n1 = bs_size - offset; | ||
53 | - } | ||
54 | - | ||
55 | - qemu_iovec_memset(qiov, n1, 0, bytes - n1); | ||
56 | - | ||
57 | - return n1; | ||
58 | -} | ||
59 | - | ||
60 | static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, | ||
61 | uint64_t bytes, QEMUIOVector *qiov, | ||
62 | int flags) | ||
63 | { | ||
64 | BDRVQcow2State *s = bs->opaque; | ||
65 | - int offset_in_cluster, n1; | ||
66 | + int offset_in_cluster; | ||
67 | int ret; | ||
68 | unsigned int cur_bytes; /* number of bytes in current iteration */ | ||
69 | uint64_t cluster_offset = 0; | ||
70 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, | ||
71 | case QCOW2_CLUSTER_UNALLOCATED: | ||
72 | |||
73 | if (bs->backing) { | ||
74 | - /* read from the base image */ | ||
75 | - n1 = qcow2_backing_read1(bs->backing->bs, &hd_qiov, | ||
76 | - offset, cur_bytes); | ||
77 | - if (n1 > 0) { | ||
78 | - QEMUIOVector local_qiov; | ||
79 | - | ||
80 | - qemu_iovec_init(&local_qiov, hd_qiov.niov); | ||
81 | - qemu_iovec_concat(&local_qiov, &hd_qiov, 0, n1); | ||
82 | - | ||
83 | - BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); | ||
84 | - qemu_co_mutex_unlock(&s->lock); | ||
85 | - ret = bdrv_co_preadv(bs->backing, offset, n1, | ||
86 | - &local_qiov, 0); | ||
87 | - qemu_co_mutex_lock(&s->lock); | ||
88 | - | ||
89 | - qemu_iovec_destroy(&local_qiov); | ||
90 | - | ||
91 | - if (ret < 0) { | ||
92 | - goto fail; | ||
93 | - } | ||
94 | + BLKDBG_EVENT(bs->file, BLKDBG_READ_BACKING_AIO); | ||
95 | + qemu_co_mutex_unlock(&s->lock); | ||
96 | + ret = bdrv_co_preadv(bs->backing, offset, cur_bytes, | ||
97 | + &hd_qiov, 0); | ||
98 | + qemu_co_mutex_lock(&s->lock); | ||
99 | + if (ret < 0) { | ||
100 | + goto fail; | ||
101 | } | ||
102 | } else { | ||
103 | /* Note: in this case, no need to wait */ | ||
51 | -- | 104 | -- |
52 | 2.13.5 | 105 | 2.13.6 |
53 | 106 | ||
54 | 107 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Removing a quorum child node with x-blockdev-change results in a quorum | ||
2 | driver state that cannot be recreated with create options because it | ||
3 | would require a list with gaps. This causes trouble in at least | ||
4 | .bdrv_refresh_filename(). | ||
1 | 5 | ||
6 | Document this problem so that we won't accidentally mark the command | ||
7 | stable without having addressed it. | ||
8 | |||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
11 | --- | ||
12 | qapi/block-core.json | 4 ++++ | ||
13 | 1 file changed, 4 insertions(+) | ||
14 | |||
15 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/qapi/block-core.json | ||
18 | +++ b/qapi/block-core.json | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | # does not support all kinds of operations, all kinds of children, nor | ||
21 | # all block drivers. | ||
22 | # | ||
23 | +# FIXME Removing children from a quorum node means introducing gaps in the | ||
24 | +# child indices. This cannot be represented in the 'children' list of | ||
25 | +# BlockdevOptionsQuorum, as returned by .bdrv_refresh_filename(). | ||
26 | +# | ||
27 | # Warning: The data in a new quorum child MUST be consistent with that of | ||
28 | # the rest of the array. | ||
29 | # | ||
30 | -- | ||
31 | 2.13.6 | ||
32 | |||
33 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Doug Gale <doug16k@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Omitting the check for whether bdrv_getlength() and bdrv_truncate() | 3 | Add trace output for commands, errors, and undefined behavior. |
4 | failed meant that it was theoretically possible to return an | 4 | Add guest error log output for undefined behavior. |
5 | incorrect offset to the caller. More likely, conditions for either | 5 | Report invalid undefined accesses to MMIO. |
6 | of these functions to fail would also cause one of our other calls | 6 | Annotate unlikely error checks with unlikely. |
7 | (such as bdrv_pread() or bdrv_pwrite_sync()) to also fail, but | ||
8 | auditing that we are safe is difficult compared to just patching | ||
9 | things to always forward on the error rather than ignoring it. | ||
10 | 7 | ||
11 | Use osdep.h macros instead of open-coded rounding while in the | 8 | Signed-off-by: Doug Gale <doug16k@gmail.com> |
12 | area. | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
13 | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | |
14 | Reported-by: Markus Armbruster <armbru@redhat.com> | ||
15 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
17 | --- | 12 | --- |
18 | block/qcow.c | 30 ++++++++++++++++++++++-------- | 13 | hw/block/nvme.c | 349 ++++++++++++++++++++++++++++++++++++++++++-------- |
19 | 1 file changed, 22 insertions(+), 8 deletions(-) | 14 | hw/block/trace-events | 93 ++++++++++++++ |
15 | 2 files changed, 390 insertions(+), 52 deletions(-) | ||
20 | 16 | ||
21 | diff --git a/block/qcow.c b/block/qcow.c | 17 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c |
22 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/block/qcow.c | 19 | --- a/hw/block/nvme.c |
24 | +++ b/block/qcow.c | 20 | +++ b/hw/block/nvme.c |
25 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | 21 | @@ -XXX,XX +XXX,XX @@ |
22 | #include "qapi/visitor.h" | ||
23 | #include "sysemu/block-backend.h" | ||
24 | |||
25 | +#include "qemu/log.h" | ||
26 | +#include "trace.h" | ||
27 | #include "nvme.h" | ||
28 | |||
29 | +#define NVME_GUEST_ERR(trace, fmt, ...) \ | ||
30 | + do { \ | ||
31 | + (trace_##trace)(__VA_ARGS__); \ | ||
32 | + qemu_log_mask(LOG_GUEST_ERROR, #trace \ | ||
33 | + " in %s: " fmt "\n", __func__, ## __VA_ARGS__); \ | ||
34 | + } while (0) | ||
35 | + | ||
36 | static void nvme_process_sq(void *opaque); | ||
37 | |||
38 | static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size) | ||
39 | @@ -XXX,XX +XXX,XX @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq) | ||
26 | { | 40 | { |
27 | BDRVQcowState *s = bs->opaque; | 41 | if (cq->irq_enabled) { |
28 | int min_index, i, j, l1_index, l2_index, ret; | 42 | if (msix_enabled(&(n->parent_obj))) { |
29 | - uint64_t l2_offset, *l2_table, cluster_offset, tmp; | 43 | + trace_nvme_irq_msix(cq->vector); |
30 | + int64_t l2_offset; | 44 | msix_notify(&(n->parent_obj), cq->vector); |
31 | + uint64_t *l2_table, cluster_offset, tmp; | 45 | } else { |
32 | uint32_t min_count; | 46 | + trace_nvme_irq_pin(); |
33 | int new_l2_table; | 47 | pci_irq_pulse(&n->parent_obj); |
34 | 48 | } | |
35 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | 49 | + } else { |
36 | return 0; | 50 | + trace_nvme_irq_masked(); |
37 | /* allocate a new l2 entry */ | 51 | } |
38 | l2_offset = bdrv_getlength(bs->file->bs); | 52 | } |
39 | + if (l2_offset < 0) { | 53 | |
40 | + return l2_offset; | 54 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, |
41 | + } | 55 | trans_len = MIN(len, trans_len); |
42 | /* round to cluster size */ | 56 | int num_prps = (len >> n->page_bits) + 1; |
43 | - l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); | 57 | |
44 | + l2_offset = QEMU_ALIGN_UP(l2_offset, s->cluster_size); | 58 | - if (!prp1) { |
45 | /* update the L1 entry */ | 59 | + if (unlikely(!prp1)) { |
46 | s->l1_table[l1_index] = l2_offset; | 60 | + trace_nvme_err_invalid_prp(); |
47 | tmp = cpu_to_be64(l2_offset); | 61 | return NVME_INVALID_FIELD | NVME_DNR; |
48 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | 62 | } else if (n->cmbsz && prp1 >= n->ctrl_mem.addr && |
49 | return -EIO; | 63 | prp1 < n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size)) { |
50 | } | 64 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, |
51 | cluster_offset = bdrv_getlength(bs->file->bs); | 65 | } |
52 | - cluster_offset = (cluster_offset + s->cluster_size - 1) & | 66 | len -= trans_len; |
53 | - ~(s->cluster_size - 1); | 67 | if (len) { |
54 | + if ((int64_t) cluster_offset < 0) { | 68 | - if (!prp2) { |
55 | + return cluster_offset; | 69 | + if (unlikely(!prp2)) { |
56 | + } | 70 | + trace_nvme_err_invalid_prp2_missing(); |
57 | + cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size); | 71 | goto unmap; |
58 | /* write the cluster content */ | 72 | } |
59 | ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, | 73 | if (len > n->page_size) { |
60 | s->cluster_size); | 74 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, |
61 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | 75 | uint64_t prp_ent = le64_to_cpu(prp_list[i]); |
76 | |||
77 | if (i == n->max_prp_ents - 1 && len > n->page_size) { | ||
78 | - if (!prp_ent || prp_ent & (n->page_size - 1)) { | ||
79 | + if (unlikely(!prp_ent || prp_ent & (n->page_size - 1))) { | ||
80 | + trace_nvme_err_invalid_prplist_ent(prp_ent); | ||
81 | goto unmap; | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, | ||
85 | prp_ent = le64_to_cpu(prp_list[i]); | ||
86 | } | ||
87 | |||
88 | - if (!prp_ent || prp_ent & (n->page_size - 1)) { | ||
89 | + if (unlikely(!prp_ent || prp_ent & (n->page_size - 1))) { | ||
90 | + trace_nvme_err_invalid_prplist_ent(prp_ent); | ||
91 | goto unmap; | ||
92 | } | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, | ||
95 | i++; | ||
62 | } | 96 | } |
63 | } else { | 97 | } else { |
64 | cluster_offset = bdrv_getlength(bs->file->bs); | 98 | - if (prp2 & (n->page_size - 1)) { |
65 | + if ((int64_t) cluster_offset < 0) { | 99 | + if (unlikely(prp2 & (n->page_size - 1))) { |
66 | + return cluster_offset; | 100 | + trace_nvme_err_invalid_prp2_align(prp2); |
67 | + } | 101 | goto unmap; |
68 | if (allocate == 1) { | 102 | } |
69 | /* round to cluster size */ | 103 | if (qsg->nsg) { |
70 | - cluster_offset = (cluster_offset + s->cluster_size - 1) & | 104 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len, |
71 | - ~(s->cluster_size - 1); | 105 | QEMUIOVector iov; |
72 | - bdrv_truncate(bs->file, cluster_offset + s->cluster_size, | 106 | uint16_t status = NVME_SUCCESS; |
73 | - PREALLOC_MODE_OFF, NULL); | 107 | |
74 | + cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size); | 108 | + trace_nvme_dma_read(prp1, prp2); |
75 | + if (cluster_offset + s->cluster_size > INT64_MAX) { | 109 | + |
76 | + return -E2BIG; | 110 | if (nvme_map_prp(&qsg, &iov, prp1, prp2, len, n)) { |
77 | + } | 111 | return NVME_INVALID_FIELD | NVME_DNR; |
78 | + ret = bdrv_truncate(bs->file, cluster_offset + s->cluster_size, | 112 | } |
79 | + PREALLOC_MODE_OFF, NULL); | 113 | if (qsg.nsg > 0) { |
80 | + if (ret < 0) { | 114 | - if (dma_buf_read(ptr, len, &qsg)) { |
81 | + return ret; | 115 | + if (unlikely(dma_buf_read(ptr, len, &qsg))) { |
82 | + } | 116 | + trace_nvme_err_invalid_dma(); |
83 | /* if encrypted, we must initialize the cluster | 117 | status = NVME_INVALID_FIELD | NVME_DNR; |
84 | content which won't be written */ | 118 | } |
85 | if (bs->encrypted && | 119 | qemu_sglist_destroy(&qsg); |
120 | } else { | ||
121 | - if (qemu_iovec_to_buf(&iov, 0, ptr, len) != len) { | ||
122 | + if (unlikely(qemu_iovec_to_buf(&iov, 0, ptr, len) != len)) { | ||
123 | + trace_nvme_err_invalid_dma(); | ||
124 | status = NVME_INVALID_FIELD | NVME_DNR; | ||
125 | } | ||
126 | qemu_iovec_destroy(&iov); | ||
127 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_write_zeros(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd, | ||
128 | uint64_t aio_slba = slba << (data_shift - BDRV_SECTOR_BITS); | ||
129 | uint32_t aio_nlb = nlb << (data_shift - BDRV_SECTOR_BITS); | ||
130 | |||
131 | - if (slba + nlb > ns->id_ns.nsze) { | ||
132 | + if (unlikely(slba + nlb > ns->id_ns.nsze)) { | ||
133 | + trace_nvme_err_invalid_lba_range(slba, nlb, ns->id_ns.nsze); | ||
134 | return NVME_LBA_RANGE | NVME_DNR; | ||
135 | } | ||
136 | |||
137 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_rw(NvmeCtrl *n, NvmeNamespace *ns, NvmeCmd *cmd, | ||
138 | int is_write = rw->opcode == NVME_CMD_WRITE ? 1 : 0; | ||
139 | enum BlockAcctType acct = is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ; | ||
140 | |||
141 | - if ((slba + nlb) > ns->id_ns.nsze) { | ||
142 | + trace_nvme_rw(is_write ? "write" : "read", nlb, data_size, slba); | ||
143 | + | ||
144 | + if (unlikely((slba + nlb) > ns->id_ns.nsze)) { | ||
145 | block_acct_invalid(blk_get_stats(n->conf.blk), acct); | ||
146 | + trace_nvme_err_invalid_lba_range(slba, nlb, ns->id_ns.nsze); | ||
147 | return NVME_LBA_RANGE | NVME_DNR; | ||
148 | } | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | ||
151 | NvmeNamespace *ns; | ||
152 | uint32_t nsid = le32_to_cpu(cmd->nsid); | ||
153 | |||
154 | - if (nsid == 0 || nsid > n->num_namespaces) { | ||
155 | + if (unlikely(nsid == 0 || nsid > n->num_namespaces)) { | ||
156 | + trace_nvme_err_invalid_ns(nsid, n->num_namespaces); | ||
157 | return NVME_INVALID_NSID | NVME_DNR; | ||
158 | } | ||
159 | |||
160 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_io_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | ||
161 | case NVME_CMD_READ: | ||
162 | return nvme_rw(n, ns, cmd, req); | ||
163 | default: | ||
164 | + trace_nvme_err_invalid_opc(cmd->opcode); | ||
165 | return NVME_INVALID_OPCODE | NVME_DNR; | ||
166 | } | ||
167 | } | ||
168 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_del_sq(NvmeCtrl *n, NvmeCmd *cmd) | ||
169 | NvmeCQueue *cq; | ||
170 | uint16_t qid = le16_to_cpu(c->qid); | ||
171 | |||
172 | - if (!qid || nvme_check_sqid(n, qid)) { | ||
173 | + if (unlikely(!qid || nvme_check_sqid(n, qid))) { | ||
174 | + trace_nvme_err_invalid_del_sq(qid); | ||
175 | return NVME_INVALID_QID | NVME_DNR; | ||
176 | } | ||
177 | |||
178 | + trace_nvme_del_sq(qid); | ||
179 | + | ||
180 | sq = n->sq[qid]; | ||
181 | while (!QTAILQ_EMPTY(&sq->out_req_list)) { | ||
182 | req = QTAILQ_FIRST(&sq->out_req_list); | ||
183 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd) | ||
184 | uint16_t qflags = le16_to_cpu(c->sq_flags); | ||
185 | uint64_t prp1 = le64_to_cpu(c->prp1); | ||
186 | |||
187 | - if (!cqid || nvme_check_cqid(n, cqid)) { | ||
188 | + trace_nvme_create_sq(prp1, sqid, cqid, qsize, qflags); | ||
189 | + | ||
190 | + if (unlikely(!cqid || nvme_check_cqid(n, cqid))) { | ||
191 | + trace_nvme_err_invalid_create_sq_cqid(cqid); | ||
192 | return NVME_INVALID_CQID | NVME_DNR; | ||
193 | } | ||
194 | - if (!sqid || !nvme_check_sqid(n, sqid)) { | ||
195 | + if (unlikely(!sqid || !nvme_check_sqid(n, sqid))) { | ||
196 | + trace_nvme_err_invalid_create_sq_sqid(sqid); | ||
197 | return NVME_INVALID_QID | NVME_DNR; | ||
198 | } | ||
199 | - if (!qsize || qsize > NVME_CAP_MQES(n->bar.cap)) { | ||
200 | + if (unlikely(!qsize || qsize > NVME_CAP_MQES(n->bar.cap))) { | ||
201 | + trace_nvme_err_invalid_create_sq_size(qsize); | ||
202 | return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR; | ||
203 | } | ||
204 | - if (!prp1 || prp1 & (n->page_size - 1)) { | ||
205 | + if (unlikely(!prp1 || prp1 & (n->page_size - 1))) { | ||
206 | + trace_nvme_err_invalid_create_sq_addr(prp1); | ||
207 | return NVME_INVALID_FIELD | NVME_DNR; | ||
208 | } | ||
209 | - if (!(NVME_SQ_FLAGS_PC(qflags))) { | ||
210 | + if (unlikely(!(NVME_SQ_FLAGS_PC(qflags)))) { | ||
211 | + trace_nvme_err_invalid_create_sq_qflags(NVME_SQ_FLAGS_PC(qflags)); | ||
212 | return NVME_INVALID_FIELD | NVME_DNR; | ||
213 | } | ||
214 | sq = g_malloc0(sizeof(*sq)); | ||
215 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_del_cq(NvmeCtrl *n, NvmeCmd *cmd) | ||
216 | NvmeCQueue *cq; | ||
217 | uint16_t qid = le16_to_cpu(c->qid); | ||
218 | |||
219 | - if (!qid || nvme_check_cqid(n, qid)) { | ||
220 | + if (unlikely(!qid || nvme_check_cqid(n, qid))) { | ||
221 | + trace_nvme_err_invalid_del_cq_cqid(qid); | ||
222 | return NVME_INVALID_CQID | NVME_DNR; | ||
223 | } | ||
224 | |||
225 | cq = n->cq[qid]; | ||
226 | - if (!QTAILQ_EMPTY(&cq->sq_list)) { | ||
227 | + if (unlikely(!QTAILQ_EMPTY(&cq->sq_list))) { | ||
228 | + trace_nvme_err_invalid_del_cq_notempty(qid); | ||
229 | return NVME_INVALID_QUEUE_DEL; | ||
230 | } | ||
231 | + trace_nvme_del_cq(qid); | ||
232 | nvme_free_cq(cq, n); | ||
233 | return NVME_SUCCESS; | ||
234 | } | ||
235 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd) | ||
236 | uint16_t qflags = le16_to_cpu(c->cq_flags); | ||
237 | uint64_t prp1 = le64_to_cpu(c->prp1); | ||
238 | |||
239 | - if (!cqid || !nvme_check_cqid(n, cqid)) { | ||
240 | + trace_nvme_create_cq(prp1, cqid, vector, qsize, qflags, | ||
241 | + NVME_CQ_FLAGS_IEN(qflags) != 0); | ||
242 | + | ||
243 | + if (unlikely(!cqid || !nvme_check_cqid(n, cqid))) { | ||
244 | + trace_nvme_err_invalid_create_cq_cqid(cqid); | ||
245 | return NVME_INVALID_CQID | NVME_DNR; | ||
246 | } | ||
247 | - if (!qsize || qsize > NVME_CAP_MQES(n->bar.cap)) { | ||
248 | + if (unlikely(!qsize || qsize > NVME_CAP_MQES(n->bar.cap))) { | ||
249 | + trace_nvme_err_invalid_create_cq_size(qsize); | ||
250 | return NVME_MAX_QSIZE_EXCEEDED | NVME_DNR; | ||
251 | } | ||
252 | - if (!prp1) { | ||
253 | + if (unlikely(!prp1)) { | ||
254 | + trace_nvme_err_invalid_create_cq_addr(prp1); | ||
255 | return NVME_INVALID_FIELD | NVME_DNR; | ||
256 | } | ||
257 | - if (vector > n->num_queues) { | ||
258 | + if (unlikely(vector > n->num_queues)) { | ||
259 | + trace_nvme_err_invalid_create_cq_vector(vector); | ||
260 | return NVME_INVALID_IRQ_VECTOR | NVME_DNR; | ||
261 | } | ||
262 | - if (!(NVME_CQ_FLAGS_PC(qflags))) { | ||
263 | + if (unlikely(!(NVME_CQ_FLAGS_PC(qflags)))) { | ||
264 | + trace_nvme_err_invalid_create_cq_qflags(NVME_CQ_FLAGS_PC(qflags)); | ||
265 | return NVME_INVALID_FIELD | NVME_DNR; | ||
266 | } | ||
267 | |||
268 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_ctrl(NvmeCtrl *n, NvmeIdentify *c) | ||
269 | uint64_t prp1 = le64_to_cpu(c->prp1); | ||
270 | uint64_t prp2 = le64_to_cpu(c->prp2); | ||
271 | |||
272 | + trace_nvme_identify_ctrl(); | ||
273 | + | ||
274 | return nvme_dma_read_prp(n, (uint8_t *)&n->id_ctrl, sizeof(n->id_ctrl), | ||
275 | prp1, prp2); | ||
276 | } | ||
277 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify *c) | ||
278 | uint64_t prp1 = le64_to_cpu(c->prp1); | ||
279 | uint64_t prp2 = le64_to_cpu(c->prp2); | ||
280 | |||
281 | - if (nsid == 0 || nsid > n->num_namespaces) { | ||
282 | + trace_nvme_identify_ns(nsid); | ||
283 | + | ||
284 | + if (unlikely(nsid == 0 || nsid > n->num_namespaces)) { | ||
285 | + trace_nvme_err_invalid_ns(nsid, n->num_namespaces); | ||
286 | return NVME_INVALID_NSID | NVME_DNR; | ||
287 | } | ||
288 | |||
289 | ns = &n->namespaces[nsid - 1]; | ||
290 | + | ||
291 | return nvme_dma_read_prp(n, (uint8_t *)&ns->id_ns, sizeof(ns->id_ns), | ||
292 | prp1, prp2); | ||
293 | } | ||
294 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeIdentify *c) | ||
295 | uint16_t ret; | ||
296 | int i, j = 0; | ||
297 | |||
298 | + trace_nvme_identify_nslist(min_nsid); | ||
299 | + | ||
300 | list = g_malloc0(data_len); | ||
301 | for (i = 0; i < n->num_namespaces; i++) { | ||
302 | if (i < min_nsid) { | ||
303 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeCmd *cmd) | ||
304 | case 0x02: | ||
305 | return nvme_identify_nslist(n, c); | ||
306 | default: | ||
307 | + trace_nvme_err_invalid_identify_cns(le32_to_cpu(c->cns)); | ||
308 | return NVME_INVALID_FIELD | NVME_DNR; | ||
309 | } | ||
310 | } | ||
311 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | ||
312 | switch (dw10) { | ||
313 | case NVME_VOLATILE_WRITE_CACHE: | ||
314 | result = blk_enable_write_cache(n->conf.blk); | ||
315 | + trace_nvme_getfeat_vwcache(result ? "enabled" : "disabled"); | ||
316 | break; | ||
317 | case NVME_NUMBER_OF_QUEUES: | ||
318 | result = cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16)); | ||
319 | + trace_nvme_getfeat_numq(result); | ||
320 | break; | ||
321 | default: | ||
322 | + trace_nvme_err_invalid_getfeat(dw10); | ||
323 | return NVME_INVALID_FIELD | NVME_DNR; | ||
324 | } | ||
325 | |||
326 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_set_feature(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | ||
327 | blk_set_enable_write_cache(n->conf.blk, dw11 & 1); | ||
328 | break; | ||
329 | case NVME_NUMBER_OF_QUEUES: | ||
330 | + trace_nvme_setfeat_numq((dw11 & 0xFFFF) + 1, | ||
331 | + ((dw11 >> 16) & 0xFFFF) + 1, | ||
332 | + n->num_queues - 1, n->num_queues - 1); | ||
333 | req->cqe.result = | ||
334 | cpu_to_le32((n->num_queues - 2) | ((n->num_queues - 2) << 16)); | ||
335 | break; | ||
336 | default: | ||
337 | + trace_nvme_err_invalid_setfeat(dw10); | ||
338 | return NVME_INVALID_FIELD | NVME_DNR; | ||
339 | } | ||
340 | return NVME_SUCCESS; | ||
341 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_admin_cmd(NvmeCtrl *n, NvmeCmd *cmd, NvmeRequest *req) | ||
342 | case NVME_ADM_CMD_GET_FEATURES: | ||
343 | return nvme_get_feature(n, cmd, req); | ||
344 | default: | ||
345 | + trace_nvme_err_invalid_admin_opc(cmd->opcode); | ||
346 | return NVME_INVALID_OPCODE | NVME_DNR; | ||
347 | } | ||
348 | } | ||
349 | @@ -XXX,XX +XXX,XX @@ static int nvme_start_ctrl(NvmeCtrl *n) | ||
350 | uint32_t page_bits = NVME_CC_MPS(n->bar.cc) + 12; | ||
351 | uint32_t page_size = 1 << page_bits; | ||
352 | |||
353 | - if (n->cq[0] || n->sq[0] || !n->bar.asq || !n->bar.acq || | ||
354 | - n->bar.asq & (page_size - 1) || n->bar.acq & (page_size - 1) || | ||
355 | - NVME_CC_MPS(n->bar.cc) < NVME_CAP_MPSMIN(n->bar.cap) || | ||
356 | - NVME_CC_MPS(n->bar.cc) > NVME_CAP_MPSMAX(n->bar.cap) || | ||
357 | - NVME_CC_IOCQES(n->bar.cc) < NVME_CTRL_CQES_MIN(n->id_ctrl.cqes) || | ||
358 | - NVME_CC_IOCQES(n->bar.cc) > NVME_CTRL_CQES_MAX(n->id_ctrl.cqes) || | ||
359 | - NVME_CC_IOSQES(n->bar.cc) < NVME_CTRL_SQES_MIN(n->id_ctrl.sqes) || | ||
360 | - NVME_CC_IOSQES(n->bar.cc) > NVME_CTRL_SQES_MAX(n->id_ctrl.sqes) || | ||
361 | - !NVME_AQA_ASQS(n->bar.aqa) || !NVME_AQA_ACQS(n->bar.aqa)) { | ||
362 | + if (unlikely(n->cq[0])) { | ||
363 | + trace_nvme_err_startfail_cq(); | ||
364 | + return -1; | ||
365 | + } | ||
366 | + if (unlikely(n->sq[0])) { | ||
367 | + trace_nvme_err_startfail_sq(); | ||
368 | + return -1; | ||
369 | + } | ||
370 | + if (unlikely(!n->bar.asq)) { | ||
371 | + trace_nvme_err_startfail_nbarasq(); | ||
372 | + return -1; | ||
373 | + } | ||
374 | + if (unlikely(!n->bar.acq)) { | ||
375 | + trace_nvme_err_startfail_nbaracq(); | ||
376 | + return -1; | ||
377 | + } | ||
378 | + if (unlikely(n->bar.asq & (page_size - 1))) { | ||
379 | + trace_nvme_err_startfail_asq_misaligned(n->bar.asq); | ||
380 | + return -1; | ||
381 | + } | ||
382 | + if (unlikely(n->bar.acq & (page_size - 1))) { | ||
383 | + trace_nvme_err_startfail_acq_misaligned(n->bar.acq); | ||
384 | + return -1; | ||
385 | + } | ||
386 | + if (unlikely(NVME_CC_MPS(n->bar.cc) < | ||
387 | + NVME_CAP_MPSMIN(n->bar.cap))) { | ||
388 | + trace_nvme_err_startfail_page_too_small( | ||
389 | + NVME_CC_MPS(n->bar.cc), | ||
390 | + NVME_CAP_MPSMIN(n->bar.cap)); | ||
391 | + return -1; | ||
392 | + } | ||
393 | + if (unlikely(NVME_CC_MPS(n->bar.cc) > | ||
394 | + NVME_CAP_MPSMAX(n->bar.cap))) { | ||
395 | + trace_nvme_err_startfail_page_too_large( | ||
396 | + NVME_CC_MPS(n->bar.cc), | ||
397 | + NVME_CAP_MPSMAX(n->bar.cap)); | ||
398 | + return -1; | ||
399 | + } | ||
400 | + if (unlikely(NVME_CC_IOCQES(n->bar.cc) < | ||
401 | + NVME_CTRL_CQES_MIN(n->id_ctrl.cqes))) { | ||
402 | + trace_nvme_err_startfail_cqent_too_small( | ||
403 | + NVME_CC_IOCQES(n->bar.cc), | ||
404 | + NVME_CTRL_CQES_MIN(n->bar.cap)); | ||
405 | + return -1; | ||
406 | + } | ||
407 | + if (unlikely(NVME_CC_IOCQES(n->bar.cc) > | ||
408 | + NVME_CTRL_CQES_MAX(n->id_ctrl.cqes))) { | ||
409 | + trace_nvme_err_startfail_cqent_too_large( | ||
410 | + NVME_CC_IOCQES(n->bar.cc), | ||
411 | + NVME_CTRL_CQES_MAX(n->bar.cap)); | ||
412 | + return -1; | ||
413 | + } | ||
414 | + if (unlikely(NVME_CC_IOSQES(n->bar.cc) < | ||
415 | + NVME_CTRL_SQES_MIN(n->id_ctrl.sqes))) { | ||
416 | + trace_nvme_err_startfail_sqent_too_small( | ||
417 | + NVME_CC_IOSQES(n->bar.cc), | ||
418 | + NVME_CTRL_SQES_MIN(n->bar.cap)); | ||
419 | + return -1; | ||
420 | + } | ||
421 | + if (unlikely(NVME_CC_IOSQES(n->bar.cc) > | ||
422 | + NVME_CTRL_SQES_MAX(n->id_ctrl.sqes))) { | ||
423 | + trace_nvme_err_startfail_sqent_too_large( | ||
424 | + NVME_CC_IOSQES(n->bar.cc), | ||
425 | + NVME_CTRL_SQES_MAX(n->bar.cap)); | ||
426 | + return -1; | ||
427 | + } | ||
428 | + if (unlikely(!NVME_AQA_ASQS(n->bar.aqa))) { | ||
429 | + trace_nvme_err_startfail_asqent_sz_zero(); | ||
430 | + return -1; | ||
431 | + } | ||
432 | + if (unlikely(!NVME_AQA_ACQS(n->bar.aqa))) { | ||
433 | + trace_nvme_err_startfail_acqent_sz_zero(); | ||
434 | return -1; | ||
435 | } | ||
436 | |||
437 | @@ -XXX,XX +XXX,XX @@ static int nvme_start_ctrl(NvmeCtrl *n) | ||
438 | static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data, | ||
439 | unsigned size) | ||
440 | { | ||
441 | + if (unlikely(offset & (sizeof(uint32_t) - 1))) { | ||
442 | + NVME_GUEST_ERR(nvme_ub_mmiowr_misaligned32, | ||
443 | + "MMIO write not 32-bit aligned," | ||
444 | + " offset=0x%"PRIx64"", offset); | ||
445 | + /* should be ignored, fall through for now */ | ||
446 | + } | ||
447 | + | ||
448 | + if (unlikely(size < sizeof(uint32_t))) { | ||
449 | + NVME_GUEST_ERR(nvme_ub_mmiowr_toosmall, | ||
450 | + "MMIO write smaller than 32-bits," | ||
451 | + " offset=0x%"PRIx64", size=%u", | ||
452 | + offset, size); | ||
453 | + /* should be ignored, fall through for now */ | ||
454 | + } | ||
455 | + | ||
456 | switch (offset) { | ||
457 | - case 0xc: | ||
458 | + case 0xc: /* INTMS */ | ||
459 | + if (unlikely(msix_enabled(&(n->parent_obj)))) { | ||
460 | + NVME_GUEST_ERR(nvme_ub_mmiowr_intmask_with_msix, | ||
461 | + "undefined access to interrupt mask set" | ||
462 | + " when MSI-X is enabled"); | ||
463 | + /* should be ignored, fall through for now */ | ||
464 | + } | ||
465 | n->bar.intms |= data & 0xffffffff; | ||
466 | n->bar.intmc = n->bar.intms; | ||
467 | + trace_nvme_mmio_intm_set(data & 0xffffffff, | ||
468 | + n->bar.intmc); | ||
469 | break; | ||
470 | - case 0x10: | ||
471 | + case 0x10: /* INTMC */ | ||
472 | + if (unlikely(msix_enabled(&(n->parent_obj)))) { | ||
473 | + NVME_GUEST_ERR(nvme_ub_mmiowr_intmask_with_msix, | ||
474 | + "undefined access to interrupt mask clr" | ||
475 | + " when MSI-X is enabled"); | ||
476 | + /* should be ignored, fall through for now */ | ||
477 | + } | ||
478 | n->bar.intms &= ~(data & 0xffffffff); | ||
479 | n->bar.intmc = n->bar.intms; | ||
480 | + trace_nvme_mmio_intm_clr(data & 0xffffffff, | ||
481 | + n->bar.intmc); | ||
482 | break; | ||
483 | - case 0x14: | ||
484 | + case 0x14: /* CC */ | ||
485 | + trace_nvme_mmio_cfg(data & 0xffffffff); | ||
486 | /* Windows first sends data, then sends enable bit */ | ||
487 | if (!NVME_CC_EN(data) && !NVME_CC_EN(n->bar.cc) && | ||
488 | !NVME_CC_SHN(data) && !NVME_CC_SHN(n->bar.cc)) | ||
489 | @@ -XXX,XX +XXX,XX @@ static void nvme_write_bar(NvmeCtrl *n, hwaddr offset, uint64_t data, | ||
490 | |||
491 | if (NVME_CC_EN(data) && !NVME_CC_EN(n->bar.cc)) { | ||
492 | n->bar.cc = data; | ||
493 | - if (nvme_start_ctrl(n)) { | ||
494 | + if (unlikely(nvme_start_ctrl(n))) { | ||
495 | + trace_nvme_err_startfail(); | ||
496 | n->bar.csts = NVME_CSTS_FAILED; | ||
497 | } else { | ||
498 | + trace_nvme_mmio_start_success(); | ||
499 | n->bar.csts = NVME_CSTS_READY; | ||
500 | } | ||
501 | } else if (!NVME_CC_EN(data) && NVME_CC_EN(n->bar.cc)) { | ||
502 | + trace_nvme_mmio_stopped(); | ||
503 | nvme_clear_ctrl(n); | ||
504 | n->bar.csts &= ~NVME_CSTS_READY; | ||
505 | } | ||
506 | if (NVME_CC_SHN(data) && !(NVME_CC_SHN(n->bar.cc))) { | ||
507 | - nvme_clear_ctrl(n); | ||
508 | - n->bar.cc = data; | ||
509 | - n->bar.csts |= NVME_CSTS_SHST_COMPLETE; | ||
510 | + trace_nvme_mmio_shutdown_set(); | ||
511 | + nvme_clear_ctrl(n); | ||
512 | + n->bar.cc = data; | ||
513 | + n->bar.csts |= NVME_CSTS_SHST_COMPLETE; | ||
514 | } else if (!NVME_CC_SHN(data) && NVME_CC_SHN(n->bar.cc)) { | ||
515 | - n->bar.csts &= ~NVME_CSTS_SHST_COMPLETE; | ||
516 | - n->bar.cc = data; | ||
517 | + trace_nvme_mmio_shutdown_cleared(); | ||
518 | + n->bar.csts &= ~NVME_CSTS_SHST_COMPLETE; | ||
519 | + n->bar.cc = data; | ||
520 | + } | ||
521 | + break; | ||
522 | + case 0x1C: /* CSTS */ | ||
523 | + if (data & (1 << 4)) { | ||
524 | + NVME_GUEST_ERR(nvme_ub_mmiowr_ssreset_w1c_unsupported, | ||
525 | + "attempted to W1C CSTS.NSSRO" | ||
526 | + " but CAP.NSSRS is zero (not supported)"); | ||
527 | + } else if (data != 0) { | ||
528 | + NVME_GUEST_ERR(nvme_ub_mmiowr_ro_csts, | ||
529 | + "attempted to set a read only bit" | ||
530 | + " of controller status"); | ||
531 | + } | ||
532 | + break; | ||
533 | + case 0x20: /* NSSR */ | ||
534 | + if (data == 0x4E564D65) { | ||
535 | + trace_nvme_ub_mmiowr_ssreset_unsupported(); | ||
536 | + } else { | ||
537 | + /* The spec says that writes of other values have no effect */ | ||
538 | + return; | ||
539 | } | ||
540 | break; | ||
541 | - case 0x24: | ||
542 | + case 0x24: /* AQA */ | ||
543 | n->bar.aqa = data & 0xffffffff; | ||
544 | + trace_nvme_mmio_aqattr(data & 0xffffffff); | ||
545 | break; | ||
546 | - case 0x28: | ||
547 | + case 0x28: /* ASQ */ | ||
548 | n->bar.asq = data; | ||
549 | + trace_nvme_mmio_asqaddr(data); | ||
550 | break; | ||
551 | - case 0x2c: | ||
552 | + case 0x2c: /* ASQ hi */ | ||
553 | n->bar.asq |= data << 32; | ||
554 | + trace_nvme_mmio_asqaddr_hi(data, n->bar.asq); | ||
555 | break; | ||
556 | - case 0x30: | ||
557 | + case 0x30: /* ACQ */ | ||
558 | + trace_nvme_mmio_acqaddr(data); | ||
559 | n->bar.acq = data; | ||
560 | break; | ||
561 | - case 0x34: | ||
562 | + case 0x34: /* ACQ hi */ | ||
563 | n->bar.acq |= data << 32; | ||
564 | + trace_nvme_mmio_acqaddr_hi(data, n->bar.acq); | ||
565 | break; | ||
566 | + case 0x38: /* CMBLOC */ | ||
567 | + NVME_GUEST_ERR(nvme_ub_mmiowr_cmbloc_reserved, | ||
568 | + "invalid write to reserved CMBLOC" | ||
569 | + " when CMBSZ is zero, ignored"); | ||
570 | + return; | ||
571 | + case 0x3C: /* CMBSZ */ | ||
572 | + NVME_GUEST_ERR(nvme_ub_mmiowr_cmbsz_readonly, | ||
573 | + "invalid write to read only CMBSZ, ignored"); | ||
574 | + return; | ||
575 | default: | ||
576 | + NVME_GUEST_ERR(nvme_ub_mmiowr_invalid, | ||
577 | + "invalid MMIO write," | ||
578 | + " offset=0x%"PRIx64", data=%"PRIx64"", | ||
579 | + offset, data); | ||
580 | break; | ||
581 | } | ||
582 | } | ||
583 | @@ -XXX,XX +XXX,XX @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size) | ||
584 | uint8_t *ptr = (uint8_t *)&n->bar; | ||
585 | uint64_t val = 0; | ||
586 | |||
587 | + if (unlikely(addr & (sizeof(uint32_t) - 1))) { | ||
588 | + NVME_GUEST_ERR(nvme_ub_mmiord_misaligned32, | ||
589 | + "MMIO read not 32-bit aligned," | ||
590 | + " offset=0x%"PRIx64"", addr); | ||
591 | + /* should RAZ, fall through for now */ | ||
592 | + } else if (unlikely(size < sizeof(uint32_t))) { | ||
593 | + NVME_GUEST_ERR(nvme_ub_mmiord_toosmall, | ||
594 | + "MMIO read smaller than 32-bits," | ||
595 | + " offset=0x%"PRIx64"", addr); | ||
596 | + /* should RAZ, fall through for now */ | ||
597 | + } | ||
598 | + | ||
599 | if (addr < sizeof(n->bar)) { | ||
600 | memcpy(&val, ptr + addr, size); | ||
601 | + } else { | ||
602 | + NVME_GUEST_ERR(nvme_ub_mmiord_invalid_ofs, | ||
603 | + "MMIO read beyond last register," | ||
604 | + " offset=0x%"PRIx64", returning 0", addr); | ||
605 | } | ||
606 | + | ||
607 | return val; | ||
608 | } | ||
609 | |||
610 | @@ -XXX,XX +XXX,XX @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) | ||
611 | { | ||
612 | uint32_t qid; | ||
613 | |||
614 | - if (addr & ((1 << 2) - 1)) { | ||
615 | + if (unlikely(addr & ((1 << 2) - 1))) { | ||
616 | + NVME_GUEST_ERR(nvme_ub_db_wr_misaligned, | ||
617 | + "doorbell write not 32-bit aligned," | ||
618 | + " offset=0x%"PRIx64", ignoring", addr); | ||
619 | return; | ||
620 | } | ||
621 | |||
622 | if (((addr - 0x1000) >> 2) & 1) { | ||
623 | + /* Completion queue doorbell write */ | ||
624 | + | ||
625 | uint16_t new_head = val & 0xffff; | ||
626 | int start_sqs; | ||
627 | NvmeCQueue *cq; | ||
628 | |||
629 | qid = (addr - (0x1000 + (1 << 2))) >> 3; | ||
630 | - if (nvme_check_cqid(n, qid)) { | ||
631 | + if (unlikely(nvme_check_cqid(n, qid))) { | ||
632 | + NVME_GUEST_ERR(nvme_ub_db_wr_invalid_cq, | ||
633 | + "completion queue doorbell write" | ||
634 | + " for nonexistent queue," | ||
635 | + " sqid=%"PRIu32", ignoring", qid); | ||
636 | return; | ||
637 | } | ||
638 | |||
639 | cq = n->cq[qid]; | ||
640 | - if (new_head >= cq->size) { | ||
641 | + if (unlikely(new_head >= cq->size)) { | ||
642 | + NVME_GUEST_ERR(nvme_ub_db_wr_invalid_cqhead, | ||
643 | + "completion queue doorbell write value" | ||
644 | + " beyond queue size, sqid=%"PRIu32"," | ||
645 | + " new_head=%"PRIu16", ignoring", | ||
646 | + qid, new_head); | ||
647 | return; | ||
648 | } | ||
649 | |||
650 | @@ -XXX,XX +XXX,XX @@ static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val) | ||
651 | nvme_isr_notify(n, cq); | ||
652 | } | ||
653 | } else { | ||
654 | + /* Submission queue doorbell write */ | ||
655 | + | ||
656 | uint16_t new_tail = val & 0xffff; | ||
657 | NvmeSQueue *sq; | ||
658 | |||
659 | qid = (addr - 0x1000) >> 3; | ||
660 | - if (nvme_check_sqid(n, qid)) { | ||
661 | + if (unlikely(nvme_check_sqid(n, qid))) { | ||
662 | + NVME_GUEST_ERR(nvme_ub_db_wr_invalid_sq, | ||
663 | + "submission queue doorbell write" | ||
664 | + " for nonexistent queue," | ||
665 | + " sqid=%"PRIu32", ignoring", qid); | ||
666 | return; | ||
667 | } | ||
668 | |||
669 | sq = n->sq[qid]; | ||
670 | - if (new_tail >= sq->size) { | ||
671 | + if (unlikely(new_tail >= sq->size)) { | ||
672 | + NVME_GUEST_ERR(nvme_ub_db_wr_invalid_sqtail, | ||
673 | + "submission queue doorbell write value" | ||
674 | + " beyond queue size, sqid=%"PRIu32"," | ||
675 | + " new_tail=%"PRIu16", ignoring", | ||
676 | + qid, new_tail); | ||
677 | return; | ||
678 | } | ||
679 | |||
680 | diff --git a/hw/block/trace-events b/hw/block/trace-events | ||
681 | index XXXXXXX..XXXXXXX 100644 | ||
682 | --- a/hw/block/trace-events | ||
683 | +++ b/hw/block/trace-events | ||
684 | @@ -XXX,XX +XXX,XX @@ virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs, uint6 | ||
685 | hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p LCHS %d %d %d" | ||
686 | hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs, int trans) "blk %p CHS %u %u %u trans %d" | ||
687 | |||
688 | +# hw/block/nvme.c | ||
689 | +# nvme traces for successful events | ||
690 | +nvme_irq_msix(uint32_t vector) "raising MSI-X IRQ vector %u" | ||
691 | +nvme_irq_pin(void) "pulsing IRQ pin" | ||
692 | +nvme_irq_masked(void) "IRQ is masked" | ||
693 | +nvme_dma_read(uint64_t prp1, uint64_t prp2) "DMA read, prp1=0x%"PRIx64" prp2=0x%"PRIx64"" | ||
694 | +nvme_rw(char const *verb, uint32_t blk_count, uint64_t byte_count, uint64_t lba) "%s %"PRIu32" blocks (%"PRIu64" bytes) from LBA %"PRIu64"" | ||
695 | +nvme_create_sq(uint64_t addr, uint16_t sqid, uint16_t cqid, uint16_t qsize, uint16_t qflags) "create submission queue, addr=0x%"PRIx64", sqid=%"PRIu16", cqid=%"PRIu16", qsize=%"PRIu16", qflags=%"PRIu16"" | ||
696 | +nvme_create_cq(uint64_t addr, uint16_t cqid, uint16_t vector, uint16_t size, uint16_t qflags, int ien) "create completion queue, addr=0x%"PRIx64", cqid=%"PRIu16", vector=%"PRIu16", qsize=%"PRIu16", qflags=%"PRIu16", ien=%d" | ||
697 | +nvme_del_sq(uint16_t qid) "deleting submission queue sqid=%"PRIu16"" | ||
698 | +nvme_del_cq(uint16_t cqid) "deleted completion queue, sqid=%"PRIu16"" | ||
699 | +nvme_identify_ctrl(void) "identify controller" | ||
700 | +nvme_identify_ns(uint16_t ns) "identify namespace, nsid=%"PRIu16"" | ||
701 | +nvme_identify_nslist(uint16_t ns) "identify namespace list, nsid=%"PRIu16"" | ||
702 | +nvme_getfeat_vwcache(char const* result) "get feature volatile write cache, result=%s" | ||
703 | +nvme_getfeat_numq(int result) "get feature number of queues, result=%d" | ||
704 | +nvme_setfeat_numq(int reqcq, int reqsq, int gotcq, int gotsq) "requested cq_count=%d sq_count=%d, responding with cq_count=%d sq_count=%d" | ||
705 | +nvme_mmio_intm_set(uint64_t data, uint64_t new_mask) "wrote MMIO, interrupt mask set, data=0x%"PRIx64", new_mask=0x%"PRIx64"" | ||
706 | +nvme_mmio_intm_clr(uint64_t data, uint64_t new_mask) "wrote MMIO, interrupt mask clr, data=0x%"PRIx64", new_mask=0x%"PRIx64"" | ||
707 | +nvme_mmio_cfg(uint64_t data) "wrote MMIO, config controller config=0x%"PRIx64"" | ||
708 | +nvme_mmio_aqattr(uint64_t data) "wrote MMIO, admin queue attributes=0x%"PRIx64"" | ||
709 | +nvme_mmio_asqaddr(uint64_t data) "wrote MMIO, admin submission queue address=0x%"PRIx64"" | ||
710 | +nvme_mmio_acqaddr(uint64_t data) "wrote MMIO, admin completion queue address=0x%"PRIx64"" | ||
711 | +nvme_mmio_asqaddr_hi(uint64_t data, uint64_t new_addr) "wrote MMIO, admin submission queue high half=0x%"PRIx64", new_address=0x%"PRIx64"" | ||
712 | +nvme_mmio_acqaddr_hi(uint64_t data, uint64_t new_addr) "wrote MMIO, admin completion queue high half=0x%"PRIx64", new_address=0x%"PRIx64"" | ||
713 | +nvme_mmio_start_success(void) "setting controller enable bit succeeded" | ||
714 | +nvme_mmio_stopped(void) "cleared controller enable bit" | ||
715 | +nvme_mmio_shutdown_set(void) "shutdown bit set" | ||
716 | +nvme_mmio_shutdown_cleared(void) "shutdown bit cleared" | ||
717 | + | ||
718 | +# nvme traces for error conditions | ||
719 | +nvme_err_invalid_dma(void) "PRP/SGL is too small for transfer size" | ||
720 | +nvme_err_invalid_prplist_ent(uint64_t prplist) "PRP list entry is null or not page aligned: 0x%"PRIx64"" | ||
721 | +nvme_err_invalid_prp2_align(uint64_t prp2) "PRP2 is not page aligned: 0x%"PRIx64"" | ||
722 | +nvme_err_invalid_prp2_missing(void) "PRP2 is null and more data to be transferred" | ||
723 | +nvme_err_invalid_field(void) "invalid field" | ||
724 | +nvme_err_invalid_prp(void) "invalid PRP" | ||
725 | +nvme_err_invalid_sgl(void) "invalid SGL" | ||
726 | +nvme_err_invalid_ns(uint32_t ns, uint32_t limit) "invalid namespace %u not within 1-%u" | ||
727 | +nvme_err_invalid_opc(uint8_t opc) "invalid opcode 0x%"PRIx8"" | ||
728 | +nvme_err_invalid_admin_opc(uint8_t opc) "invalid admin opcode 0x%"PRIx8"" | ||
729 | +nvme_err_invalid_lba_range(uint64_t start, uint64_t len, uint64_t limit) "Invalid LBA start=%"PRIu64" len=%"PRIu64" limit=%"PRIu64"" | ||
730 | +nvme_err_invalid_del_sq(uint16_t qid) "invalid submission queue deletion, sid=%"PRIu16"" | ||
731 | +nvme_err_invalid_create_sq_cqid(uint16_t cqid) "failed creating submission queue, invalid cqid=%"PRIu16"" | ||
732 | +nvme_err_invalid_create_sq_sqid(uint16_t sqid) "failed creating submission queue, invalid sqid=%"PRIu16"" | ||
733 | +nvme_err_invalid_create_sq_size(uint16_t qsize) "failed creating submission queue, invalid qsize=%"PRIu16"" | ||
734 | +nvme_err_invalid_create_sq_addr(uint64_t addr) "failed creating submission queue, addr=0x%"PRIx64"" | ||
735 | +nvme_err_invalid_create_sq_qflags(uint16_t qflags) "failed creating submission queue, qflags=%"PRIu16"" | ||
736 | +nvme_err_invalid_del_cq_cqid(uint16_t cqid) "failed deleting completion queue, cqid=%"PRIu16"" | ||
737 | +nvme_err_invalid_del_cq_notempty(uint16_t cqid) "failed deleting completion queue, it is not empty, cqid=%"PRIu16"" | ||
738 | +nvme_err_invalid_create_cq_cqid(uint16_t cqid) "failed creating completion queue, cqid=%"PRIu16"" | ||
739 | +nvme_err_invalid_create_cq_size(uint16_t size) "failed creating completion queue, size=%"PRIu16"" | ||
740 | +nvme_err_invalid_create_cq_addr(uint64_t addr) "failed creating completion queue, addr=0x%"PRIx64"" | ||
741 | +nvme_err_invalid_create_cq_vector(uint16_t vector) "failed creating completion queue, vector=%"PRIu16"" | ||
742 | +nvme_err_invalid_create_cq_qflags(uint16_t qflags) "failed creating completion queue, qflags=%"PRIu16"" | ||
743 | +nvme_err_invalid_identify_cns(uint16_t cns) "identify, invalid cns=0x%"PRIx16"" | ||
744 | +nvme_err_invalid_getfeat(int dw10) "invalid get features, dw10=0x%"PRIx32"" | ||
745 | +nvme_err_invalid_setfeat(uint32_t dw10) "invalid set features, dw10=0x%"PRIx32"" | ||
746 | +nvme_err_startfail_cq(void) "nvme_start_ctrl failed because there are non-admin completion queues" | ||
747 | +nvme_err_startfail_sq(void) "nvme_start_ctrl failed because there are non-admin submission queues" | ||
748 | +nvme_err_startfail_nbarasq(void) "nvme_start_ctrl failed because the admin submission queue address is null" | ||
749 | +nvme_err_startfail_nbaracq(void) "nvme_start_ctrl failed because the admin completion queue address is null" | ||
750 | +nvme_err_startfail_asq_misaligned(uint64_t addr) "nvme_start_ctrl failed because the admin submission queue address is misaligned: 0x%"PRIx64"" | ||
751 | +nvme_err_startfail_acq_misaligned(uint64_t addr) "nvme_start_ctrl failed because the admin completion queue address is misaligned: 0x%"PRIx64"" | ||
752 | +nvme_err_startfail_page_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the page size is too small: log2size=%u, min=%u" | ||
753 | +nvme_err_startfail_page_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the page size is too large: log2size=%u, max=%u" | ||
754 | +nvme_err_startfail_cqent_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the completion queue entry size is too small: log2size=%u, min=%u" | ||
755 | +nvme_err_startfail_cqent_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the completion queue entry size is too large: log2size=%u, max=%u" | ||
756 | +nvme_err_startfail_sqent_too_small(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the submission queue entry size is too small: log2size=%u, min=%u" | ||
757 | +nvme_err_startfail_sqent_too_large(uint8_t log2ps, uint8_t maxlog2ps) "nvme_start_ctrl failed because the submission queue entry size is too large: log2size=%u, max=%u" | ||
758 | +nvme_err_startfail_asqent_sz_zero(void) "nvme_start_ctrl failed because the admin submission queue size is zero" | ||
759 | +nvme_err_startfail_acqent_sz_zero(void) "nvme_start_ctrl failed because the admin completion queue size is zero" | ||
760 | +nvme_err_startfail(void) "setting controller enable bit failed" | ||
761 | + | ||
762 | +# Traces for undefined behavior | ||
763 | +nvme_ub_mmiowr_misaligned32(uint64_t offset) "MMIO write not 32-bit aligned, offset=0x%"PRIx64"" | ||
764 | +nvme_ub_mmiowr_toosmall(uint64_t offset, unsigned size) "MMIO write smaller than 32 bits, offset=0x%"PRIx64", size=%u" | ||
765 | +nvme_ub_mmiowr_intmask_with_msix(void) "undefined access to interrupt mask set when MSI-X is enabled" | ||
766 | +nvme_ub_mmiowr_ro_csts(void) "attempted to set a read only bit of controller status" | ||
767 | +nvme_ub_mmiowr_ssreset_w1c_unsupported(void) "attempted to W1C CSTS.NSSRO but CAP.NSSRS is zero (not supported)" | ||
768 | +nvme_ub_mmiowr_ssreset_unsupported(void) "attempted NVM subsystem reset but CAP.NSSRS is zero (not supported)" | ||
769 | +nvme_ub_mmiowr_cmbloc_reserved(void) "invalid write to reserved CMBLOC when CMBSZ is zero, ignored" | ||
770 | +nvme_ub_mmiowr_cmbsz_readonly(void) "invalid write to read only CMBSZ, ignored" | ||
771 | +nvme_ub_mmiowr_invalid(uint64_t offset, uint64_t data) "invalid MMIO write, offset=0x%"PRIx64", data=0x%"PRIx64"" | ||
772 | +nvme_ub_mmiord_misaligned32(uint64_t offset) "MMIO read not 32-bit aligned, offset=0x%"PRIx64"" | ||
773 | +nvme_ub_mmiord_toosmall(uint64_t offset) "MMIO read smaller than 32-bits, offset=0x%"PRIx64"" | ||
774 | +nvme_ub_mmiord_invalid_ofs(uint64_t offset) "MMIO read beyond last register, offset=0x%"PRIx64", returning 0" | ||
775 | +nvme_ub_db_wr_misaligned(uint64_t offset) "doorbell write not 32-bit aligned, offset=0x%"PRIx64", ignoring" | ||
776 | +nvme_ub_db_wr_invalid_cq(uint32_t qid) "completion queue doorbell write for nonexistent queue, cqid=%"PRIu32", ignoring" | ||
777 | +nvme_ub_db_wr_invalid_cqhead(uint32_t qid, uint16_t new_head) "completion queue doorbell write value beyond queue size, cqid=%"PRIu32", new_head=%"PRIu16", ignoring" | ||
778 | +nvme_ub_db_wr_invalid_sq(uint32_t qid) "submission queue doorbell write for nonexistent queue, sqid=%"PRIu32", ignoring" | ||
779 | +nvme_ub_db_wr_invalid_sqtail(uint32_t qid, uint16_t new_tail) "submission queue doorbell write value beyond queue size, sqid=%"PRIu32", new_head=%"PRIu16", ignoring" | ||
780 | + | ||
781 | # hw/block/xen_disk.c | ||
782 | xen_disk_alloc(char *name) "%s" | ||
783 | xen_disk_init(char *name) "%s" | ||
86 | -- | 784 | -- |
87 | 2.13.5 | 785 | 2.13.6 |
88 | 786 | ||
89 | 787 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The following functions fail if bs->drv is a filter and does not | 3 | Management tools create overlays of running guests with qemu-img: |
4 | implement them: | ||
5 | 4 | ||
6 | bdrv_probe_blocksizes | 5 | $ qemu-img create -b /image/in/use.qcow2 -f qcow2 /overlay/image.qcow2 |
7 | bdrv_probe_geometry | ||
8 | bdrv_truncate | ||
9 | bdrv_has_zero_init | ||
10 | bdrv_get_info | ||
11 | 6 | ||
12 | Instead, the call should be passed to bs->file if it exists, to allow | 7 | but this doesn't work anymore due to image locking: |
13 | filter drivers to support those methods without implementing them. This | ||
14 | commit makes `drv->is_filter = true` imply that these callbacks will be | ||
15 | forwarded to bs->file by default, so disabling support for these | ||
16 | functions must be done explicitly. | ||
17 | 8 | ||
9 | qemu-img: /overlay/image.qcow2: Failed to get shared "write" lock | ||
10 | Is another process using the image? | ||
11 | Could not open backing image to determine size. | ||
12 | Use the force share option to allow this use case again. | ||
13 | |||
14 | Cc: qemu-stable@nongnu.org | ||
15 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | 16 | Reviewed-by: Eric Blake <eblake@redhat.com> |
19 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
20 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
21 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
22 | --- | 18 | --- |
23 | include/block/block_int.h | 6 +++++- | 19 | block.c | 3 ++- |
24 | block.c | 21 +++++++++++++++++++-- | 20 | 1 file changed, 2 insertions(+), 1 deletion(-) |
25 | 2 files changed, 24 insertions(+), 3 deletions(-) | ||
26 | 21 | ||
27 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/block/block_int.h | ||
30 | +++ b/include/block/block_int.h | ||
31 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
32 | const char *format_name; | ||
33 | int instance_size; | ||
34 | |||
35 | - /* set to true if the BlockDriver is a block filter */ | ||
36 | + /* set to true if the BlockDriver is a block filter. Block filters pass | ||
37 | + * certain callbacks that refer to data (see block.c) to their bs->file if | ||
38 | + * the driver doesn't implement them. Drivers that do not wish to forward | ||
39 | + * must implement them and return -ENOTSUP. | ||
40 | + */ | ||
41 | bool is_filter; | ||
42 | /* for snapshots block filter like Quorum can implement the | ||
43 | * following recursive callback. | ||
44 | diff --git a/block.c b/block.c | 22 | diff --git a/block.c b/block.c |
45 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/block.c | 24 | --- a/block.c |
47 | +++ b/block.c | 25 | +++ b/block.c |
48 | @@ -XXX,XX +XXX,XX @@ int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz) | 26 | @@ -XXX,XX +XXX,XX @@ void bdrv_img_create(const char *filename, const char *fmt, |
49 | 27 | back_flags = flags; | |
50 | if (drv && drv->bdrv_probe_blocksizes) { | 28 | back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); |
51 | return drv->bdrv_probe_blocksizes(bs, bsz); | 29 | |
52 | + } else if (drv && drv->is_filter && bs->file) { | 30 | + backing_options = qdict_new(); |
53 | + return bdrv_probe_blocksizes(bs->file->bs, bsz); | 31 | if (backing_fmt) { |
54 | } | 32 | - backing_options = qdict_new(); |
55 | 33 | qdict_put_str(backing_options, "driver", backing_fmt); | |
56 | return -ENOTSUP; | 34 | } |
57 | @@ -XXX,XX +XXX,XX @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo) | 35 | + qdict_put_bool(backing_options, BDRV_OPT_FORCE_SHARE, true); |
58 | 36 | ||
59 | if (drv && drv->bdrv_probe_geometry) { | 37 | bs = bdrv_open(full_backing, NULL, backing_options, back_flags, |
60 | return drv->bdrv_probe_geometry(bs, geo); | 38 | &local_err); |
61 | + } else if (drv && drv->is_filter && bs->file) { | ||
62 | + return bdrv_probe_geometry(bs->file->bs, geo); | ||
63 | } | ||
64 | |||
65 | return -ENOTSUP; | ||
66 | @@ -XXX,XX +XXX,XX @@ int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, | ||
67 | |||
68 | assert(child->perm & BLK_PERM_RESIZE); | ||
69 | |||
70 | + /* if bs->drv == NULL, bs is closed, so there's nothing to do here */ | ||
71 | if (!drv) { | ||
72 | error_setg(errp, "No medium inserted"); | ||
73 | return -ENOMEDIUM; | ||
74 | } | ||
75 | if (!drv->bdrv_truncate) { | ||
76 | + if (bs->file && drv->is_filter) { | ||
77 | + return bdrv_truncate(bs->file, offset, prealloc, errp); | ||
78 | + } | ||
79 | error_setg(errp, "Image format driver does not support resize"); | ||
80 | return -ENOTSUP; | ||
81 | } | ||
82 | @@ -XXX,XX +XXX,XX @@ int bdrv_has_zero_init(BlockDriverState *bs) | ||
83 | if (bs->drv->bdrv_has_zero_init) { | ||
84 | return bs->drv->bdrv_has_zero_init(bs); | ||
85 | } | ||
86 | + if (bs->file && bs->drv->is_filter) { | ||
87 | + return bdrv_has_zero_init(bs->file->bs); | ||
88 | + } | ||
89 | |||
90 | /* safe default */ | ||
91 | return 0; | ||
92 | @@ -XXX,XX +XXX,XX @@ void bdrv_get_backing_filename(BlockDriverState *bs, | ||
93 | int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) | ||
94 | { | ||
95 | BlockDriver *drv = bs->drv; | ||
96 | - if (!drv) | ||
97 | + /* if bs->drv == NULL, bs is closed, so there's nothing to do here */ | ||
98 | + if (!drv) { | ||
99 | return -ENOMEDIUM; | ||
100 | - if (!drv->bdrv_get_info) | ||
101 | + } | ||
102 | + if (!drv->bdrv_get_info) { | ||
103 | + if (bs->file && drv->is_filter) { | ||
104 | + return bdrv_get_info(bs->file->bs, bdi); | ||
105 | + } | ||
106 | return -ENOTSUP; | ||
107 | + } | ||
108 | memset(bdi, 0, sizeof(*bdi)); | ||
109 | return drv->bdrv_get_info(bs, bdi); | ||
110 | } | ||
111 | -- | 39 | -- |
112 | 2.13.5 | 40 | 2.13.6 |
113 | 41 | ||
114 | 42 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | It's not working anymore since QEMU v1.3.0 - time to remove it now. | ||
4 | |||
5 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
6 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
7 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | --- | ||
10 | blockdev.c | 11 ----------- | ||
11 | qemu-doc.texi | 6 ------ | ||
12 | 2 files changed, 17 deletions(-) | ||
13 | |||
14 | diff --git a/blockdev.c b/blockdev.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/blockdev.c | ||
17 | +++ b/blockdev.c | ||
18 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = { | ||
19 | .type = QEMU_OPT_STRING, | ||
20 | .help = "chs translation (auto, lba, none)", | ||
21 | },{ | ||
22 | - .name = "boot", | ||
23 | - .type = QEMU_OPT_BOOL, | ||
24 | - .help = "(deprecated, ignored)", | ||
25 | - },{ | ||
26 | .name = "addr", | ||
27 | .type = QEMU_OPT_STRING, | ||
28 | .help = "pci address (virtio only)", | ||
29 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) | ||
30 | goto fail; | ||
31 | } | ||
32 | |||
33 | - /* Deprecated option boot=[on|off] */ | ||
34 | - if (qemu_opt_get(legacy_opts, "boot") != NULL) { | ||
35 | - fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be " | ||
36 | - "ignored. Future versions will reject this parameter. Please " | ||
37 | - "update your scripts.\n"); | ||
38 | - } | ||
39 | - | ||
40 | /* Other deprecated options */ | ||
41 | if (!qtest_enabled()) { | ||
42 | for (i = 0; i < ARRAY_SIZE(deprecated); i++) { | ||
43 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/qemu-doc.texi | ||
46 | +++ b/qemu-doc.texi | ||
47 | @@ -XXX,XX +XXX,XX @@ deprecated. | ||
48 | |||
49 | @section System emulator command line arguments | ||
50 | |||
51 | -@subsection -drive boot=on|off (since 1.3.0) | ||
52 | - | ||
53 | -The ``boot=on|off'' option to the ``-drive'' argument is | ||
54 | -ignored. Applications should use the ``bootindex=N'' parameter | ||
55 | -to set an absolute ordering between devices instead. | ||
56 | - | ||
57 | @subsection -tdf (since 1.3.0) | ||
58 | |||
59 | The ``-tdf'' argument is ignored. The behaviour implemented | ||
60 | -- | ||
61 | 2.13.6 | ||
62 | |||
63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Thomas Huth <thuth@redhat.com> | |
2 | |||
3 | It's been marked as deprecated since QEMU v2.10.0, and so far nobody | ||
4 | complained that we should keep it, so let's remove this legacy option | ||
5 | now to simplify the code quite a bit. | ||
6 | |||
7 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | vl.c | 86 ++------------------------------------------------------- | ||
13 | qemu-doc.texi | 8 ------ | ||
14 | qemu-options.hx | 19 ++----------- | ||
15 | 3 files changed, 4 insertions(+), 109 deletions(-) | ||
16 | |||
17 | diff --git a/vl.c b/vl.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/vl.c | ||
20 | +++ b/vl.c | ||
21 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
22 | const char *boot_order = NULL; | ||
23 | const char *boot_once = NULL; | ||
24 | DisplayState *ds; | ||
25 | - int cyls, heads, secs, translation; | ||
26 | QemuOpts *opts, *machine_opts; | ||
27 | - QemuOpts *hda_opts = NULL, *icount_opts = NULL, *accel_opts = NULL; | ||
28 | + QemuOpts *icount_opts = NULL, *accel_opts = NULL; | ||
29 | QemuOptsList *olist; | ||
30 | int optind; | ||
31 | const char *optarg; | ||
32 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
33 | |||
34 | cpu_model = NULL; | ||
35 | snapshot = 0; | ||
36 | - cyls = heads = secs = 0; | ||
37 | - translation = BIOS_ATA_TRANSLATION_AUTO; | ||
38 | |||
39 | nb_nics = 0; | ||
40 | |||
41 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
42 | if (optind >= argc) | ||
43 | break; | ||
44 | if (argv[optind][0] != '-') { | ||
45 | - hda_opts = drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); | ||
46 | + drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS); | ||
47 | } else { | ||
48 | const QEMUOption *popt; | ||
49 | |||
50 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
51 | cpu_model = optarg; | ||
52 | break; | ||
53 | case QEMU_OPTION_hda: | ||
54 | - { | ||
55 | - char buf[256]; | ||
56 | - if (cyls == 0) | ||
57 | - snprintf(buf, sizeof(buf), "%s", HD_OPTS); | ||
58 | - else | ||
59 | - snprintf(buf, sizeof(buf), | ||
60 | - "%s,cyls=%d,heads=%d,secs=%d%s", | ||
61 | - HD_OPTS , cyls, heads, secs, | ||
62 | - translation == BIOS_ATA_TRANSLATION_LBA ? | ||
63 | - ",trans=lba" : | ||
64 | - translation == BIOS_ATA_TRANSLATION_NONE ? | ||
65 | - ",trans=none" : ""); | ||
66 | - drive_add(IF_DEFAULT, 0, optarg, buf); | ||
67 | - break; | ||
68 | - } | ||
69 | case QEMU_OPTION_hdb: | ||
70 | case QEMU_OPTION_hdc: | ||
71 | case QEMU_OPTION_hdd: | ||
72 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
73 | case QEMU_OPTION_snapshot: | ||
74 | snapshot = 1; | ||
75 | break; | ||
76 | - case QEMU_OPTION_hdachs: | ||
77 | - { | ||
78 | - const char *p; | ||
79 | - p = optarg; | ||
80 | - cyls = strtol(p, (char **)&p, 0); | ||
81 | - if (cyls < 1 || cyls > 16383) | ||
82 | - goto chs_fail; | ||
83 | - if (*p != ',') | ||
84 | - goto chs_fail; | ||
85 | - p++; | ||
86 | - heads = strtol(p, (char **)&p, 0); | ||
87 | - if (heads < 1 || heads > 16) | ||
88 | - goto chs_fail; | ||
89 | - if (*p != ',') | ||
90 | - goto chs_fail; | ||
91 | - p++; | ||
92 | - secs = strtol(p, (char **)&p, 0); | ||
93 | - if (secs < 1 || secs > 63) | ||
94 | - goto chs_fail; | ||
95 | - if (*p == ',') { | ||
96 | - p++; | ||
97 | - if (!strcmp(p, "large")) { | ||
98 | - translation = BIOS_ATA_TRANSLATION_LARGE; | ||
99 | - } else if (!strcmp(p, "rechs")) { | ||
100 | - translation = BIOS_ATA_TRANSLATION_RECHS; | ||
101 | - } else if (!strcmp(p, "none")) { | ||
102 | - translation = BIOS_ATA_TRANSLATION_NONE; | ||
103 | - } else if (!strcmp(p, "lba")) { | ||
104 | - translation = BIOS_ATA_TRANSLATION_LBA; | ||
105 | - } else if (!strcmp(p, "auto")) { | ||
106 | - translation = BIOS_ATA_TRANSLATION_AUTO; | ||
107 | - } else { | ||
108 | - goto chs_fail; | ||
109 | - } | ||
110 | - } else if (*p != '\0') { | ||
111 | - chs_fail: | ||
112 | - error_report("invalid physical CHS format"); | ||
113 | - exit(1); | ||
114 | - } | ||
115 | - if (hda_opts != NULL) { | ||
116 | - qemu_opt_set_number(hda_opts, "cyls", cyls, | ||
117 | - &error_abort); | ||
118 | - qemu_opt_set_number(hda_opts, "heads", heads, | ||
119 | - &error_abort); | ||
120 | - qemu_opt_set_number(hda_opts, "secs", secs, | ||
121 | - &error_abort); | ||
122 | - if (translation == BIOS_ATA_TRANSLATION_LARGE) { | ||
123 | - qemu_opt_set(hda_opts, "trans", "large", | ||
124 | - &error_abort); | ||
125 | - } else if (translation == BIOS_ATA_TRANSLATION_RECHS) { | ||
126 | - qemu_opt_set(hda_opts, "trans", "rechs", | ||
127 | - &error_abort); | ||
128 | - } else if (translation == BIOS_ATA_TRANSLATION_LBA) { | ||
129 | - qemu_opt_set(hda_opts, "trans", "lba", | ||
130 | - &error_abort); | ||
131 | - } else if (translation == BIOS_ATA_TRANSLATION_NONE) { | ||
132 | - qemu_opt_set(hda_opts, "trans", "none", | ||
133 | - &error_abort); | ||
134 | - } | ||
135 | - } | ||
136 | - } | ||
137 | - error_report("'-hdachs' is deprecated, please use '-device" | ||
138 | - " ide-hd,cyls=c,heads=h,secs=s,...' instead"); | ||
139 | - break; | ||
140 | case QEMU_OPTION_numa: | ||
141 | opts = qemu_opts_parse_noisily(qemu_find_opts("numa"), | ||
142 | optarg, true); | ||
143 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/qemu-doc.texi | ||
146 | +++ b/qemu-doc.texi | ||
147 | @@ -XXX,XX +XXX,XX @@ The ``--net dump'' argument is now replaced with the | ||
148 | ``-object filter-dump'' argument which works in combination | ||
149 | with the modern ``-netdev`` backends instead. | ||
150 | |||
151 | -@subsection -hdachs (since 2.10.0) | ||
152 | - | ||
153 | -The ``-hdachs'' argument is now a synonym for setting | ||
154 | -the ``cyls'', ``heads'', ``secs'', and ``trans'' properties | ||
155 | -on the ``ide-hd'' device using the ``-device'' argument. | ||
156 | -The new syntax allows different settings to be provided | ||
157 | -per disk. | ||
158 | - | ||
159 | @subsection -usbdevice (since 2.10.0) | ||
160 | |||
161 | The ``-usbdevice DEV'' argument is now a synonym for setting | ||
162 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/qemu-options.hx | ||
165 | +++ b/qemu-options.hx | ||
166 | @@ -XXX,XX +XXX,XX @@ of available connectors of a given interface type. | ||
167 | @item media=@var{media} | ||
168 | This option defines the type of the media: disk or cdrom. | ||
169 | @item cyls=@var{c},heads=@var{h},secs=@var{s}[,trans=@var{t}] | ||
170 | -These options have the same definition as they have in @option{-hdachs}. | ||
171 | -These parameters are deprecated, use the corresponding parameters | ||
172 | +Force disk physical geometry and the optional BIOS translation (trans=none or | ||
173 | +lba). These parameters are deprecated, use the corresponding parameters | ||
174 | of @code{-device} instead. | ||
175 | @item snapshot=@var{snapshot} | ||
176 | @var{snapshot} is "on" or "off" and controls snapshot mode for the given drive | ||
177 | @@ -XXX,XX +XXX,XX @@ the raw disk image you use is not written back. You can however force | ||
178 | the write back by pressing @key{C-a s} (@pxref{disk_images}). | ||
179 | ETEXI | ||
180 | |||
181 | -DEF("hdachs", HAS_ARG, QEMU_OPTION_hdachs, \ | ||
182 | - "-hdachs c,h,s[,t]\n" \ | ||
183 | - " force hard disk 0 physical geometry and the optional BIOS\n" \ | ||
184 | - " translation (t=none or lba) (usually QEMU can guess them)\n", | ||
185 | - QEMU_ARCH_ALL) | ||
186 | -STEXI | ||
187 | -@item -hdachs @var{c},@var{h},@var{s},[,@var{t}] | ||
188 | -@findex -hdachs | ||
189 | -Force hard disk 0 physical geometry (1 <= @var{c} <= 16383, 1 <= | ||
190 | -@var{h} <= 16, 1 <= @var{s} <= 63) and optionally force the BIOS | ||
191 | -translation mode (@var{t}=none, lba or auto). Usually QEMU can guess | ||
192 | -all those parameters. This option is deprecated, please use | ||
193 | -@code{-device ide-hd,cyls=c,heads=h,secs=s,...} instead. | ||
194 | -ETEXI | ||
195 | - | ||
196 | DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, | ||
197 | "-fsdev fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}]\n" | ||
198 | " [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd][,fmode=fmode][,dmode=dmode]\n" | ||
199 | -- | ||
200 | 2.13.6 | ||
201 | |||
202 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | Looks like we forgot to announce the deprecation of these options in | ||
4 | the corresponding chapter of the qemu-doc text, so let's do that now. | ||
5 | |||
6 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | qemu-doc.texi | 15 +++++++++++++++ | ||
12 | 1 file changed, 15 insertions(+) | ||
13 | |||
14 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/qemu-doc.texi | ||
17 | +++ b/qemu-doc.texi | ||
18 | @@ -XXX,XX +XXX,XX @@ longer be directly supported in QEMU. | ||
19 | The ``-drive if=scsi'' argument is replaced by the the | ||
20 | ``-device BUS-TYPE'' argument combined with ``-drive if=none''. | ||
21 | |||
22 | +@subsection -drive cyls=...,heads=...,secs=...,trans=... (since 2.10.0) | ||
23 | + | ||
24 | +The drive geometry arguments are replaced by the the geometry arguments | ||
25 | +that can be specified with the ``-device'' parameter. | ||
26 | + | ||
27 | +@subsection -drive serial=... (since 2.10.0) | ||
28 | + | ||
29 | +The drive serial argument is replaced by the the serial argument | ||
30 | +that can be specified with the ``-device'' parameter. | ||
31 | + | ||
32 | +@subsection -drive addr=... (since 2.10.0) | ||
33 | + | ||
34 | +The drive addr argument is replaced by the the addr argument | ||
35 | +that can be specified with the ``-device'' parameter. | ||
36 | + | ||
37 | @subsection -net dump (since 2.10.0) | ||
38 | |||
39 | The ``--net dump'' argument is now replaced with the | ||
40 | -- | ||
41 | 2.13.6 | ||
42 | |||
43 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | bdrv_co_get_block_status_from_file() and | 3 | Signed-off-by: Fam Zheng <famz@redhat.com> |
4 | bdrv_co_get_block_status_from_backing() set *file to bs->file and | ||
5 | bs->backing respectively, so that bdrv_co_get_block_status() can recurse | ||
6 | to them. Future block drivers won't have to duplicate code to implement | ||
7 | this. | ||
8 | |||
9 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
11 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
15 | --- | 5 | --- |
16 | include/block/block_int.h | 18 ++++++++++++++++++ | 6 | include/block/block_int.h | 1 - |
17 | block/blkdebug.c | 12 +----------- | 7 | block/io.c | 18 ------------------ |
18 | block/commit.c | 12 +----------- | 8 | 2 files changed, 19 deletions(-) |
19 | block/io.c | 26 ++++++++++++++++++++++++++ | ||
20 | block/mirror.c | 12 +----------- | ||
21 | 5 files changed, 47 insertions(+), 33 deletions(-) | ||
22 | 9 | ||
23 | diff --git a/include/block/block_int.h b/include/block/block_int.h | 10 | diff --git a/include/block/block_int.h b/include/block/block_int.h |
24 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/block/block_int.h | 12 | --- a/include/block/block_int.h |
26 | +++ b/include/block/block_int.h | 13 | +++ b/include/block/block_int.h |
27 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, | 14 | @@ -XXX,XX +XXX,XX @@ bool blk_dev_is_tray_open(BlockBackend *blk); |
28 | uint64_t perm, uint64_t shared, | 15 | bool blk_dev_is_medium_locked(BlockBackend *blk); |
29 | uint64_t *nperm, uint64_t *nshared); | 16 | |
30 | 17 | void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); | |
31 | +/* | 18 | -bool bdrv_requests_pending(BlockDriverState *bs); |
32 | + * Default implementation for drivers to pass bdrv_co_get_block_status() to | 19 | |
33 | + * their file. | 20 | void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); |
34 | + */ | 21 | void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); |
35 | +int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *bs, | ||
36 | + int64_t sector_num, | ||
37 | + int nb_sectors, | ||
38 | + int *pnum, | ||
39 | + BlockDriverState **file); | ||
40 | +/* | ||
41 | + * Default implementation for drivers to pass bdrv_co_get_block_status() to | ||
42 | + * their backing file. | ||
43 | + */ | ||
44 | +int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverState *bs, | ||
45 | + int64_t sector_num, | ||
46 | + int nb_sectors, | ||
47 | + int *pnum, | ||
48 | + BlockDriverState **file); | ||
49 | const char *bdrv_get_parent_name(const BlockDriverState *bs); | ||
50 | void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp); | ||
51 | bool blk_dev_has_removable_media(BlockBackend *blk); | ||
52 | diff --git a/block/blkdebug.c b/block/blkdebug.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/block/blkdebug.c | ||
55 | +++ b/block/blkdebug.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, | ||
57 | return bdrv_co_pdiscard(bs->file->bs, offset, bytes); | ||
58 | } | ||
59 | |||
60 | -static int64_t coroutine_fn blkdebug_co_get_block_status( | ||
61 | - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, | ||
62 | - BlockDriverState **file) | ||
63 | -{ | ||
64 | - *pnum = nb_sectors; | ||
65 | - *file = bs->file->bs; | ||
66 | - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | | ||
67 | - (sector_num << BDRV_SECTOR_BITS); | ||
68 | -} | ||
69 | - | ||
70 | static void blkdebug_close(BlockDriverState *bs) | ||
71 | { | ||
72 | BDRVBlkdebugState *s = bs->opaque; | ||
73 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkdebug = { | ||
74 | .bdrv_co_flush_to_disk = blkdebug_co_flush, | ||
75 | .bdrv_co_pwrite_zeroes = blkdebug_co_pwrite_zeroes, | ||
76 | .bdrv_co_pdiscard = blkdebug_co_pdiscard, | ||
77 | - .bdrv_co_get_block_status = blkdebug_co_get_block_status, | ||
78 | + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_file, | ||
79 | |||
80 | .bdrv_debug_event = blkdebug_debug_event, | ||
81 | .bdrv_debug_breakpoint = blkdebug_debug_breakpoint, | ||
82 | diff --git a/block/commit.c b/block/commit.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/block/commit.c | ||
85 | +++ b/block/commit.c | ||
86 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs, | ||
87 | return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); | ||
88 | } | ||
89 | |||
90 | -static int64_t coroutine_fn bdrv_commit_top_get_block_status( | ||
91 | - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, | ||
92 | - BlockDriverState **file) | ||
93 | -{ | ||
94 | - *pnum = nb_sectors; | ||
95 | - *file = bs->backing->bs; | ||
96 | - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | | ||
97 | - (sector_num << BDRV_SECTOR_BITS); | ||
98 | -} | ||
99 | - | ||
100 | static void bdrv_commit_top_refresh_filename(BlockDriverState *bs, QDict *opts) | ||
101 | { | ||
102 | bdrv_refresh_filename(bs->backing->bs); | ||
103 | @@ -XXX,XX +XXX,XX @@ static void bdrv_commit_top_child_perm(BlockDriverState *bs, BdrvChild *c, | ||
104 | static BlockDriver bdrv_commit_top = { | ||
105 | .format_name = "commit_top", | ||
106 | .bdrv_co_preadv = bdrv_commit_top_preadv, | ||
107 | - .bdrv_co_get_block_status = bdrv_commit_top_get_block_status, | ||
108 | + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_backing, | ||
109 | .bdrv_refresh_filename = bdrv_commit_top_refresh_filename, | ||
110 | .bdrv_close = bdrv_commit_top_close, | ||
111 | .bdrv_child_perm = bdrv_commit_top_child_perm, | ||
112 | diff --git a/block/io.c b/block/io.c | 22 | diff --git a/block/io.c b/block/io.c |
113 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
114 | --- a/block/io.c | 24 | --- a/block/io.c |
115 | +++ b/block/io.c | 25 | +++ b/block/io.c |
116 | @@ -XXX,XX +XXX,XX @@ typedef struct BdrvCoGetBlockStatusData { | 26 | @@ -XXX,XX +XXX,XX @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) |
117 | bool done; | 27 | assert(old >= 1); |
118 | } BdrvCoGetBlockStatusData; | ||
119 | |||
120 | +int64_t coroutine_fn bdrv_co_get_block_status_from_file(BlockDriverState *bs, | ||
121 | + int64_t sector_num, | ||
122 | + int nb_sectors, | ||
123 | + int *pnum, | ||
124 | + BlockDriverState **file) | ||
125 | +{ | ||
126 | + assert(bs->file && bs->file->bs); | ||
127 | + *pnum = nb_sectors; | ||
128 | + *file = bs->file->bs; | ||
129 | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | | ||
130 | + (sector_num << BDRV_SECTOR_BITS); | ||
131 | +} | ||
132 | + | ||
133 | +int64_t coroutine_fn bdrv_co_get_block_status_from_backing(BlockDriverState *bs, | ||
134 | + int64_t sector_num, | ||
135 | + int nb_sectors, | ||
136 | + int *pnum, | ||
137 | + BlockDriverState **file) | ||
138 | +{ | ||
139 | + assert(bs->backing && bs->backing->bs); | ||
140 | + *pnum = nb_sectors; | ||
141 | + *file = bs->backing->bs; | ||
142 | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | | ||
143 | + (sector_num << BDRV_SECTOR_BITS); | ||
144 | +} | ||
145 | + | ||
146 | /* | ||
147 | * Returns the allocation status of the specified sectors. | ||
148 | * Drivers not implementing the functionality are assumed to not support | ||
149 | diff --git a/block/mirror.c b/block/mirror.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/block/mirror.c | ||
152 | +++ b/block/mirror.c | ||
153 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs) | ||
154 | return bdrv_co_flush(bs->backing->bs); | ||
155 | } | 28 | } |
156 | 29 | ||
157 | -static int64_t coroutine_fn bdrv_mirror_top_get_block_status( | 30 | -/* Check if any requests are in-flight (including throttled requests) */ |
158 | - BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, | 31 | -bool bdrv_requests_pending(BlockDriverState *bs) |
159 | - BlockDriverState **file) | ||
160 | -{ | 32 | -{ |
161 | - *pnum = nb_sectors; | 33 | - BdrvChild *child; |
162 | - *file = bs->backing->bs; | 34 | - |
163 | - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | | 35 | - if (atomic_read(&bs->in_flight)) { |
164 | - (sector_num << BDRV_SECTOR_BITS); | 36 | - return true; |
37 | - } | ||
38 | - | ||
39 | - QLIST_FOREACH(child, &bs->children, next) { | ||
40 | - if (bdrv_requests_pending(child->bs)) { | ||
41 | - return true; | ||
42 | - } | ||
43 | - } | ||
44 | - | ||
45 | - return false; | ||
165 | -} | 46 | -} |
166 | - | 47 | - |
167 | static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, | 48 | typedef struct { |
168 | int64_t offset, int bytes, BdrvRequestFlags flags) | 49 | Coroutine *co; |
169 | { | 50 | BlockDriverState *bs; |
170 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_mirror_top = { | ||
171 | .bdrv_co_pwrite_zeroes = bdrv_mirror_top_pwrite_zeroes, | ||
172 | .bdrv_co_pdiscard = bdrv_mirror_top_pdiscard, | ||
173 | .bdrv_co_flush = bdrv_mirror_top_flush, | ||
174 | - .bdrv_co_get_block_status = bdrv_mirror_top_get_block_status, | ||
175 | + .bdrv_co_get_block_status = bdrv_co_get_block_status_from_backing, | ||
176 | .bdrv_refresh_filename = bdrv_mirror_top_refresh_filename, | ||
177 | .bdrv_close = bdrv_mirror_top_close, | ||
178 | .bdrv_child_perm = bdrv_mirror_top_child_perm, | ||
179 | -- | 51 | -- |
180 | 2.13.5 | 52 | 2.13.6 |
181 | 53 | ||
182 | 54 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
2 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
3 | --- | ||
4 | block/io.c | 6 ++++++ | ||
5 | 1 file changed, 6 insertions(+) | ||
1 | 6 | ||
7 | diff --git a/block/io.c b/block/io.c | ||
8 | index XXXXXXX..XXXXXXX 100644 | ||
9 | --- a/block/io.c | ||
10 | +++ b/block/io.c | ||
11 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
12 | BdrvNextIterator it; | ||
13 | GSList *aio_ctxs = NULL, *ctx; | ||
14 | |||
15 | + /* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread | ||
16 | + * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on | ||
17 | + * nodes in several different AioContexts, so make sure we're in the main | ||
18 | + * context. */ | ||
19 | + assert(qemu_get_current_aio_context() == qemu_get_aio_context()); | ||
20 | + | ||
21 | block_job_pause_all(); | ||
22 | |||
23 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
24 | -- | ||
25 | 2.13.6 | ||
26 | |||
27 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | bdrv_drained_begin() doesn't increase bs->quiesce_counter recursively | ||
2 | and also doesn't notify other parent nodes of children, which both means | ||
3 | that the child nodes are not actually drained, and bdrv_drained_begin() | ||
4 | is providing useful functionality only on a single node. | ||
1 | 5 | ||
6 | To keep things consistent, we also shouldn't call the block driver | ||
7 | callbacks recursively. | ||
8 | |||
9 | A proper recursive drain version that provides an actually working | ||
10 | drained section for child nodes will be introduced later. | ||
11 | |||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
14 | --- | ||
15 | block/io.c | 16 +++++++++------- | ||
16 | 1 file changed, 9 insertions(+), 7 deletions(-) | ||
17 | |||
18 | diff --git a/block/io.c b/block/io.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/io.c | ||
21 | +++ b/block/io.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) | ||
23 | } | ||
24 | |||
25 | /* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ | ||
26 | -static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) | ||
27 | +static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, bool recursive) | ||
28 | { | ||
29 | BdrvChild *child, *tmp; | ||
30 | BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; | ||
31 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) | ||
32 | bdrv_coroutine_enter(bs, data.co); | ||
33 | BDRV_POLL_WHILE(bs, !data.done); | ||
34 | |||
35 | - QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { | ||
36 | - bdrv_drain_invoke(child->bs, begin); | ||
37 | + if (recursive) { | ||
38 | + QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { | ||
39 | + bdrv_drain_invoke(child->bs, begin, true); | ||
40 | + } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) | ||
45 | bdrv_parent_drained_begin(bs); | ||
46 | } | ||
47 | |||
48 | - bdrv_drain_invoke(bs, true); | ||
49 | + bdrv_drain_invoke(bs, true, false); | ||
50 | bdrv_drain_recurse(bs); | ||
51 | } | ||
52 | |||
53 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
54 | } | ||
55 | |||
56 | /* Re-enable things in child-to-parent order */ | ||
57 | - bdrv_drain_invoke(bs, false); | ||
58 | + bdrv_drain_invoke(bs, false, false); | ||
59 | bdrv_parent_drained_end(bs); | ||
60 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
63 | aio_context_acquire(aio_context); | ||
64 | aio_disable_external(aio_context); | ||
65 | bdrv_parent_drained_begin(bs); | ||
66 | - bdrv_drain_invoke(bs, true); | ||
67 | + bdrv_drain_invoke(bs, true, true); | ||
68 | aio_context_release(aio_context); | ||
69 | |||
70 | if (!g_slist_find(aio_ctxs, aio_context)) { | ||
71 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
72 | |||
73 | /* Re-enable things in child-to-parent order */ | ||
74 | aio_context_acquire(aio_context); | ||
75 | - bdrv_drain_invoke(bs, false); | ||
76 | + bdrv_drain_invoke(bs, false, true); | ||
77 | bdrv_parent_drained_end(bs); | ||
78 | aio_enable_external(aio_context); | ||
79 | aio_context_release(aio_context); | ||
80 | -- | ||
81 | 2.13.6 | ||
82 | |||
83 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The existing test is for bdrv_drain_all_begin/end() only. Generalise the | ||
2 | test case so that it can be run for the other variants as well. At the | ||
3 | moment this is only bdrv_drain_begin/end(), but in a while, we'll add | ||
4 | another one. | ||
1 | 5 | ||
6 | Also, add a backing file to the test node to test whether the operations | ||
7 | work recursively. | ||
8 | |||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | --- | ||
11 | tests/test-bdrv-drain.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----- | ||
12 | 1 file changed, 62 insertions(+), 7 deletions(-) | ||
13 | |||
14 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/tests/test-bdrv-drain.c | ||
17 | +++ b/tests/test-bdrv-drain.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test = { | ||
19 | |||
20 | .bdrv_co_drain_begin = bdrv_test_co_drain_begin, | ||
21 | .bdrv_co_drain_end = bdrv_test_co_drain_end, | ||
22 | + | ||
23 | + .bdrv_child_perm = bdrv_format_default_perms, | ||
24 | }; | ||
25 | |||
26 | static void aio_ret_cb(void *opaque, int ret) | ||
27 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) | ||
28 | *aio_ret = ret; | ||
29 | } | ||
30 | |||
31 | -static void test_drv_cb_drain_all(void) | ||
32 | +enum drain_type { | ||
33 | + BDRV_DRAIN_ALL, | ||
34 | + BDRV_DRAIN, | ||
35 | +}; | ||
36 | + | ||
37 | +static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs) | ||
38 | +{ | ||
39 | + switch (drain_type) { | ||
40 | + case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; | ||
41 | + case BDRV_DRAIN: bdrv_drained_begin(bs); break; | ||
42 | + default: g_assert_not_reached(); | ||
43 | + } | ||
44 | +} | ||
45 | + | ||
46 | +static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs) | ||
47 | +{ | ||
48 | + switch (drain_type) { | ||
49 | + case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; | ||
50 | + case BDRV_DRAIN: bdrv_drained_end(bs); break; | ||
51 | + default: g_assert_not_reached(); | ||
52 | + } | ||
53 | +} | ||
54 | + | ||
55 | +static void test_drv_cb_common(enum drain_type drain_type, bool recursive) | ||
56 | { | ||
57 | BlockBackend *blk; | ||
58 | - BlockDriverState *bs; | ||
59 | - BDRVTestState *s; | ||
60 | + BlockDriverState *bs, *backing; | ||
61 | + BDRVTestState *s, *backing_s; | ||
62 | BlockAIOCB *acb; | ||
63 | int aio_ret; | ||
64 | |||
65 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_all(void) | ||
66 | s = bs->opaque; | ||
67 | blk_insert_bs(blk, bs, &error_abort); | ||
68 | |||
69 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); | ||
70 | + backing_s = backing->opaque; | ||
71 | + bdrv_set_backing_hd(bs, backing, &error_abort); | ||
72 | + | ||
73 | /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */ | ||
74 | g_assert_cmpint(s->drain_count, ==, 0); | ||
75 | - bdrv_drain_all_begin(); | ||
76 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
77 | + | ||
78 | + do_drain_begin(drain_type, bs); | ||
79 | + | ||
80 | g_assert_cmpint(s->drain_count, ==, 1); | ||
81 | - bdrv_drain_all_end(); | ||
82 | + g_assert_cmpint(backing_s->drain_count, ==, !!recursive); | ||
83 | + | ||
84 | + do_drain_end(drain_type, bs); | ||
85 | + | ||
86 | g_assert_cmpint(s->drain_count, ==, 0); | ||
87 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
88 | |||
89 | /* Now do the same while a request is pending */ | ||
90 | aio_ret = -EINPROGRESS; | ||
91 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_all(void) | ||
92 | g_assert_cmpint(aio_ret, ==, -EINPROGRESS); | ||
93 | |||
94 | g_assert_cmpint(s->drain_count, ==, 0); | ||
95 | - bdrv_drain_all_begin(); | ||
96 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
97 | + | ||
98 | + do_drain_begin(drain_type, bs); | ||
99 | + | ||
100 | g_assert_cmpint(aio_ret, ==, 0); | ||
101 | g_assert_cmpint(s->drain_count, ==, 1); | ||
102 | - bdrv_drain_all_end(); | ||
103 | + g_assert_cmpint(backing_s->drain_count, ==, !!recursive); | ||
104 | + | ||
105 | + do_drain_end(drain_type, bs); | ||
106 | + | ||
107 | g_assert_cmpint(s->drain_count, ==, 0); | ||
108 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
109 | |||
110 | + bdrv_unref(backing); | ||
111 | bdrv_unref(bs); | ||
112 | blk_unref(blk); | ||
113 | } | ||
114 | |||
115 | +static void test_drv_cb_drain_all(void) | ||
116 | +{ | ||
117 | + test_drv_cb_common(BDRV_DRAIN_ALL, true); | ||
118 | +} | ||
119 | + | ||
120 | +static void test_drv_cb_drain(void) | ||
121 | +{ | ||
122 | + test_drv_cb_common(BDRV_DRAIN, false); | ||
123 | +} | ||
124 | + | ||
125 | int main(int argc, char **argv) | ||
126 | { | ||
127 | bdrv_init(); | ||
128 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
129 | g_test_init(&argc, &argv, NULL); | ||
130 | |||
131 | g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all); | ||
132 | + g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); | ||
133 | |||
134 | return g_test_run(); | ||
135 | } | ||
136 | -- | ||
137 | 2.13.6 | ||
138 | |||
139 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | This is currently only working correctly for bdrv_drain(), not for |
---|---|---|---|
2 | bdrv_drain_all(). Leave a comment for the drain_all case, we'll address | ||
3 | it later. | ||
2 | 4 | ||
3 | Move the CoMutex and CoQueue inits inside throttle_group_register_tgm() | ||
4 | which is called whenever a ThrottleGroupMember is initialized. There's | ||
5 | no need for them to be separate. | ||
6 | |||
7 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | --- | 6 | --- |
12 | block/block-backend.c | 3 --- | 7 | tests/test-bdrv-drain.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ |
13 | block/throttle-groups.c | 3 +++ | 8 | 1 file changed, 45 insertions(+) |
14 | 2 files changed, 3 insertions(+), 3 deletions(-) | ||
15 | 9 | ||
16 | diff --git a/block/block-backend.c b/block/block-backend.c | 10 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
17 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/block-backend.c | 12 | --- a/tests/test-bdrv-drain.c |
19 | +++ b/block/block-backend.c | 13 | +++ b/tests/test-bdrv-drain.c |
20 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) | 14 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void) |
21 | blk->shared_perm = shared_perm; | 15 | test_drv_cb_common(BDRV_DRAIN, false); |
22 | blk_set_enable_write_cache(blk, true); | 16 | } |
23 | 17 | ||
24 | - qemu_co_mutex_init(&blk->public.throttle_group_member.throttled_reqs_lock); | 18 | +static void test_quiesce_common(enum drain_type drain_type, bool recursive) |
25 | - qemu_co_queue_init(&blk->public.throttle_group_member.throttled_reqs[0]); | 19 | +{ |
26 | - qemu_co_queue_init(&blk->public.throttle_group_member.throttled_reqs[1]); | 20 | + BlockBackend *blk; |
27 | block_acct_init(&blk->stats); | 21 | + BlockDriverState *bs, *backing; |
28 | 22 | + | |
29 | notifier_list_init(&blk->remove_bs_notifiers); | 23 | + blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
30 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | 24 | + bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, |
31 | index XXXXXXX..XXXXXXX 100644 | 25 | + &error_abort); |
32 | --- a/block/throttle-groups.c | 26 | + blk_insert_bs(blk, bs, &error_abort); |
33 | +++ b/block/throttle-groups.c | 27 | + |
34 | @@ -XXX,XX +XXX,XX @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm, | 28 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); |
35 | read_timer_cb, | 29 | + bdrv_set_backing_hd(bs, backing, &error_abort); |
36 | write_timer_cb, | 30 | + |
37 | tgm); | 31 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); |
38 | + qemu_co_mutex_init(&tgm->throttled_reqs_lock); | 32 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); |
39 | + qemu_co_queue_init(&tgm->throttled_reqs[0]); | 33 | + |
40 | + qemu_co_queue_init(&tgm->throttled_reqs[1]); | 34 | + do_drain_begin(drain_type, bs); |
41 | 35 | + | |
42 | qemu_mutex_unlock(&tg->lock); | 36 | + g_assert_cmpint(bs->quiesce_counter, ==, 1); |
37 | + g_assert_cmpint(backing->quiesce_counter, ==, !!recursive); | ||
38 | + | ||
39 | + do_drain_end(drain_type, bs); | ||
40 | + | ||
41 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); | ||
42 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | ||
43 | + | ||
44 | + bdrv_unref(backing); | ||
45 | + bdrv_unref(bs); | ||
46 | + blk_unref(blk); | ||
47 | +} | ||
48 | + | ||
49 | +static void test_quiesce_drain_all(void) | ||
50 | +{ | ||
51 | + // XXX drain_all doesn't quiesce | ||
52 | + //test_quiesce_common(BDRV_DRAIN_ALL, true); | ||
53 | +} | ||
54 | + | ||
55 | +static void test_quiesce_drain(void) | ||
56 | +{ | ||
57 | + test_quiesce_common(BDRV_DRAIN, false); | ||
58 | +} | ||
59 | + | ||
60 | int main(int argc, char **argv) | ||
61 | { | ||
62 | bdrv_init(); | ||
63 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
64 | g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all); | ||
65 | g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); | ||
66 | |||
67 | + g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); | ||
68 | + g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); | ||
69 | + | ||
70 | return g_test_run(); | ||
43 | } | 71 | } |
44 | -- | 72 | -- |
45 | 2.13.5 | 73 | 2.13.6 |
46 | 74 | ||
47 | 75 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | Block jobs already paused themselves when their main BlockBackend |
---|---|---|---|
2 | entered a drained section. This is not good enough: We also want to | ||
3 | pause a block job and may not submit new requests if, for example, the | ||
4 | mirror target node should be drained. | ||
2 | 5 | ||
3 | The old signature has an ambiguous meaning for a return of 0: | 6 | This implements .drained_begin/end callbacks in child_job in order to |
4 | either no allocation was requested or necessary, or an error | 7 | consider all block nodes related to the job, and removes the |
5 | occurred (but any errno associated with the error is lost to | 8 | BlockBackend callbacks which are unnecessary now because the root of the |
6 | the caller, which then has to assume EIO). | 9 | job main BlockBackend is always referenced with a child_job, too. |
7 | 10 | ||
8 | Better is to follow the example of qcow2, by changing the | ||
9 | signature to have a separate return value that cleanly | ||
10 | distinguishes between failure and success, along with a | ||
11 | parameter that cleanly holds a 64-bit value. Then update all | ||
12 | callers. | ||
13 | |||
14 | While auditing that all return paths return a negative errno | ||
15 | (rather than -1), I also simplified places where we can pass | ||
16 | NULL rather than a local Error that just gets thrown away. | ||
17 | |||
18 | Suggested-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
20 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
21 | --- | 12 | --- |
22 | block/qcow.c | 123 +++++++++++++++++++++++++++++++++++------------------------ | 13 | blockjob.c | 22 +++++++++------------- |
23 | 1 file changed, 73 insertions(+), 50 deletions(-) | 14 | 1 file changed, 9 insertions(+), 13 deletions(-) |
24 | 15 | ||
25 | diff --git a/block/qcow.c b/block/qcow.c | 16 | diff --git a/blockjob.c b/blockjob.c |
26 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/block/qcow.c | 18 | --- a/blockjob.c |
28 | +++ b/block/qcow.c | 19 | +++ b/blockjob.c |
29 | @@ -XXX,XX +XXX,XX @@ static int qcow_reopen_prepare(BDRVReopenState *state, | 20 | @@ -XXX,XX +XXX,XX @@ static char *child_job_get_parent_desc(BdrvChild *c) |
30 | * 'compressed_size'. 'compressed_size' must be > 0 and < | 21 | job->id); |
31 | * cluster_size | 22 | } |
32 | * | 23 | |
33 | - * return 0 if not allocated. | 24 | -static const BdrvChildRole child_job = { |
34 | + * return 0 if not allocated, 1 if *result is assigned, and negative | 25 | - .get_parent_desc = child_job_get_parent_desc, |
35 | + * errno on failure. | 26 | - .stay_at_node = true, |
36 | */ | 27 | -}; |
37 | -static uint64_t get_cluster_offset(BlockDriverState *bs, | 28 | - |
38 | - uint64_t offset, int allocate, | 29 | -static void block_job_drained_begin(void *opaque) |
39 | - int compressed_size, | 30 | +static void child_job_drained_begin(BdrvChild *c) |
40 | - int n_start, int n_end) | ||
41 | +static int get_cluster_offset(BlockDriverState *bs, | ||
42 | + uint64_t offset, int allocate, | ||
43 | + int compressed_size, | ||
44 | + int n_start, int n_end, uint64_t *result) | ||
45 | { | 31 | { |
46 | BDRVQcowState *s = bs->opaque; | 32 | - BlockJob *job = opaque; |
47 | - int min_index, i, j, l1_index, l2_index; | 33 | + BlockJob *job = c->opaque; |
48 | + int min_index, i, j, l1_index, l2_index, ret; | 34 | block_job_pause(job); |
49 | uint64_t l2_offset, *l2_table, cluster_offset, tmp; | ||
50 | uint32_t min_count; | ||
51 | int new_l2_table; | ||
52 | |||
53 | + *result = 0; | ||
54 | l1_index = offset >> (s->l2_bits + s->cluster_bits); | ||
55 | l2_offset = s->l1_table[l1_index]; | ||
56 | new_l2_table = 0; | ||
57 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
58 | /* update the L1 entry */ | ||
59 | s->l1_table[l1_index] = l2_offset; | ||
60 | tmp = cpu_to_be64(l2_offset); | ||
61 | - if (bdrv_pwrite_sync(bs->file, | ||
62 | - s->l1_table_offset + l1_index * sizeof(tmp), | ||
63 | - &tmp, sizeof(tmp)) < 0) | ||
64 | - return 0; | ||
65 | + ret = bdrv_pwrite_sync(bs->file, | ||
66 | + s->l1_table_offset + l1_index * sizeof(tmp), | ||
67 | + &tmp, sizeof(tmp)); | ||
68 | + if (ret < 0) { | ||
69 | + return ret; | ||
70 | + } | ||
71 | new_l2_table = 1; | ||
72 | } | ||
73 | for(i = 0; i < L2_CACHE_SIZE; i++) { | ||
74 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
75 | l2_table = s->l2_cache + (min_index << s->l2_bits); | ||
76 | if (new_l2_table) { | ||
77 | memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); | ||
78 | - if (bdrv_pwrite_sync(bs->file, l2_offset, l2_table, | ||
79 | - s->l2_size * sizeof(uint64_t)) < 0) | ||
80 | - return 0; | ||
81 | + ret = bdrv_pwrite_sync(bs->file, l2_offset, l2_table, | ||
82 | + s->l2_size * sizeof(uint64_t)); | ||
83 | + if (ret < 0) { | ||
84 | + return ret; | ||
85 | + } | ||
86 | } else { | ||
87 | - if (bdrv_pread(bs->file, l2_offset, l2_table, | ||
88 | - s->l2_size * sizeof(uint64_t)) != | ||
89 | - s->l2_size * sizeof(uint64_t)) | ||
90 | - return 0; | ||
91 | + ret = bdrv_pread(bs->file, l2_offset, l2_table, | ||
92 | + s->l2_size * sizeof(uint64_t)); | ||
93 | + if (ret < 0) { | ||
94 | + return ret; | ||
95 | + } | ||
96 | } | ||
97 | s->l2_cache_offsets[min_index] = l2_offset; | ||
98 | s->l2_cache_counts[min_index] = 1; | ||
99 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
100 | /* if the cluster is already compressed, we must | ||
101 | decompress it in the case it is not completely | ||
102 | overwritten */ | ||
103 | - if (decompress_cluster(bs, cluster_offset) < 0) | ||
104 | - return 0; | ||
105 | + if (decompress_cluster(bs, cluster_offset) < 0) { | ||
106 | + return -EIO; | ||
107 | + } | ||
108 | cluster_offset = bdrv_getlength(bs->file->bs); | ||
109 | cluster_offset = (cluster_offset + s->cluster_size - 1) & | ||
110 | ~(s->cluster_size - 1); | ||
111 | /* write the cluster content */ | ||
112 | - if (bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, | ||
113 | - s->cluster_size) != | ||
114 | - s->cluster_size) | ||
115 | - return -1; | ||
116 | + ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, | ||
117 | + s->cluster_size); | ||
118 | + if (ret < 0) { | ||
119 | + return ret; | ||
120 | + } | ||
121 | } else { | ||
122 | cluster_offset = bdrv_getlength(bs->file->bs); | ||
123 | if (allocate == 1) { | ||
124 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
125 | s->cluster_data, | ||
126 | BDRV_SECTOR_SIZE, | ||
127 | NULL) < 0) { | ||
128 | - errno = EIO; | ||
129 | - return -1; | ||
130 | + return -EIO; | ||
131 | + } | ||
132 | + ret = bdrv_pwrite(bs->file, | ||
133 | + cluster_offset + i * 512, | ||
134 | + s->cluster_data, 512); | ||
135 | + if (ret < 0) { | ||
136 | + return ret; | ||
137 | } | ||
138 | - if (bdrv_pwrite(bs->file, | ||
139 | - cluster_offset + i * 512, | ||
140 | - s->cluster_data, 512) != 512) | ||
141 | - return -1; | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_cluster_offset(BlockDriverState *bs, | ||
146 | /* update L2 table */ | ||
147 | tmp = cpu_to_be64(cluster_offset); | ||
148 | l2_table[l2_index] = tmp; | ||
149 | - if (bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp), | ||
150 | - &tmp, sizeof(tmp)) < 0) | ||
151 | - return 0; | ||
152 | + ret = bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp), | ||
153 | + &tmp, sizeof(tmp)); | ||
154 | + if (ret < 0) { | ||
155 | + return ret; | ||
156 | + } | ||
157 | } | ||
158 | - return cluster_offset; | ||
159 | + *result = cluster_offset; | ||
160 | + return 1; | ||
161 | } | 35 | } |
162 | 36 | ||
163 | static int64_t coroutine_fn qcow_co_get_block_status(BlockDriverState *bs, | 37 | -static void block_job_drained_end(void *opaque) |
164 | int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file) | 38 | +static void child_job_drained_end(BdrvChild *c) |
165 | { | 39 | { |
166 | BDRVQcowState *s = bs->opaque; | 40 | - BlockJob *job = opaque; |
167 | - int index_in_cluster, n; | 41 | + BlockJob *job = c->opaque; |
168 | + int index_in_cluster, n, ret; | 42 | block_job_resume(job); |
169 | uint64_t cluster_offset; | ||
170 | |||
171 | qemu_co_mutex_lock(&s->lock); | ||
172 | - cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); | ||
173 | + ret = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0, &cluster_offset); | ||
174 | qemu_co_mutex_unlock(&s->lock); | ||
175 | + if (ret < 0) { | ||
176 | + return ret; | ||
177 | + } | ||
178 | index_in_cluster = sector_num & (s->cluster_sectors - 1); | ||
179 | n = s->cluster_sectors - index_in_cluster; | ||
180 | if (n > nb_sectors) | ||
181 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
182 | |||
183 | while (nb_sectors != 0) { | ||
184 | /* prepare next request */ | ||
185 | - cluster_offset = get_cluster_offset(bs, sector_num << 9, | ||
186 | - 0, 0, 0, 0); | ||
187 | + ret = get_cluster_offset(bs, sector_num << 9, | ||
188 | + 0, 0, 0, 0, &cluster_offset); | ||
189 | + if (ret < 0) { | ||
190 | + break; | ||
191 | + } | ||
192 | index_in_cluster = sector_num & (s->cluster_sectors - 1); | ||
193 | n = s->cluster_sectors - index_in_cluster; | ||
194 | if (n > nb_sectors) { | ||
195 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
196 | ret = bdrv_co_readv(bs->backing, sector_num, n, &hd_qiov); | ||
197 | qemu_co_mutex_lock(&s->lock); | ||
198 | if (ret < 0) { | ||
199 | - goto fail; | ||
200 | + break; | ||
201 | } | ||
202 | } else { | ||
203 | /* Note: in this case, no need to wait */ | ||
204 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
205 | } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { | ||
206 | /* add AIO support for compressed blocks ? */ | ||
207 | if (decompress_cluster(bs, cluster_offset) < 0) { | ||
208 | - goto fail; | ||
209 | + ret = -EIO; | ||
210 | + break; | ||
211 | } | ||
212 | memcpy(buf, | ||
213 | s->cluster_cache + index_in_cluster * 512, 512 * n); | ||
214 | } else { | ||
215 | if ((cluster_offset & 511) != 0) { | ||
216 | - goto fail; | ||
217 | + ret = -EIO; | ||
218 | + break; | ||
219 | } | ||
220 | hd_iov.iov_base = (void *)buf; | ||
221 | hd_iov.iov_len = n * 512; | ||
222 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
223 | assert(s->crypto); | ||
224 | if (qcrypto_block_decrypt(s->crypto, sector_num, buf, | ||
225 | n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
226 | - goto fail; | ||
227 | + ret = -EIO; | ||
228 | + break; | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
233 | buf += n * 512; | ||
234 | } | ||
235 | |||
236 | -done: | ||
237 | qemu_co_mutex_unlock(&s->lock); | ||
238 | |||
239 | if (qiov->niov > 1) { | ||
240 | @@ -XXX,XX +XXX,XX @@ done: | ||
241 | } | ||
242 | |||
243 | return ret; | ||
244 | - | ||
245 | -fail: | ||
246 | - ret = -EIO; | ||
247 | - goto done; | ||
248 | } | 43 | } |
249 | 44 | ||
250 | static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, | 45 | -static const BlockDevOps block_job_dev_ops = { |
251 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, | 46 | - .drained_begin = block_job_drained_begin, |
252 | if (n > nb_sectors) { | 47 | - .drained_end = block_job_drained_end, |
253 | n = nb_sectors; | 48 | +static const BdrvChildRole child_job = { |
254 | } | 49 | + .get_parent_desc = child_job_get_parent_desc, |
255 | - cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0, | 50 | + .drained_begin = child_job_drained_begin, |
256 | - index_in_cluster, | 51 | + .drained_end = child_job_drained_end, |
257 | - index_in_cluster + n); | 52 | + .stay_at_node = true, |
258 | + ret = get_cluster_offset(bs, sector_num << 9, 1, 0, | 53 | }; |
259 | + index_in_cluster, | 54 | |
260 | + index_in_cluster + n, &cluster_offset); | 55 | void block_job_remove_all_bdrv(BlockJob *job) |
261 | + if (ret < 0) { | 56 | @@ -XXX,XX +XXX,XX @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, |
262 | + break; | 57 | block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort); |
263 | + } | 58 | bs->job = job; |
264 | if (!cluster_offset || (cluster_offset & 511) != 0) { | 59 | |
265 | ret = -EIO; | 60 | - blk_set_dev_ops(blk, &block_job_dev_ops, job); |
266 | break; | 61 | bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); |
267 | @@ -XXX,XX +XXX,XX @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, | 62 | |
268 | goto success; | 63 | QLIST_INSERT_HEAD(&block_jobs, job, job_list); |
269 | } | ||
270 | qemu_co_mutex_lock(&s->lock); | ||
271 | - cluster_offset = get_cluster_offset(bs, offset, 2, out_len, 0, 0); | ||
272 | + ret = get_cluster_offset(bs, offset, 2, out_len, 0, 0, &cluster_offset); | ||
273 | qemu_co_mutex_unlock(&s->lock); | ||
274 | + if (ret < 0) { | ||
275 | + goto fail; | ||
276 | + } | ||
277 | if (cluster_offset == 0) { | ||
278 | ret = -EIO; | ||
279 | goto fail; | ||
280 | -- | 64 | -- |
281 | 2.13.5 | 65 | 2.13.6 |
282 | 66 | ||
283 | 67 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | Block jobs must be paused if any of the involved nodes are drained. |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
4 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | --- | 4 | --- |
8 | tests/qemu-iotests/184 | 205 ++++++++++++++++++++++++++++++ | 5 | tests/test-bdrv-drain.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | tests/qemu-iotests/184.out | 302 +++++++++++++++++++++++++++++++++++++++++++++ | 6 | 1 file changed, 121 insertions(+) |
10 | tests/qemu-iotests/group | 1 + | ||
11 | 3 files changed, 508 insertions(+) | ||
12 | create mode 100755 tests/qemu-iotests/184 | ||
13 | create mode 100644 tests/qemu-iotests/184.out | ||
14 | 7 | ||
15 | diff --git a/tests/qemu-iotests/184 b/tests/qemu-iotests/184 | 8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
16 | new file mode 100755 | 9 | index XXXXXXX..XXXXXXX 100644 |
17 | index XXXXXXX..XXXXXXX | 10 | --- a/tests/test-bdrv-drain.c |
18 | --- /dev/null | 11 | +++ b/tests/test-bdrv-drain.c |
19 | +++ b/tests/qemu-iotests/184 | ||
20 | @@ -XXX,XX +XXX,XX @@ | 12 | @@ -XXX,XX +XXX,XX @@ |
21 | +#!/bin/bash | 13 | |
22 | +# | 14 | #include "qemu/osdep.h" |
23 | +# Test I/O throttle block filter driver interface | 15 | #include "block/block.h" |
24 | +# | 16 | +#include "block/blockjob_int.h" |
25 | +# Copyright (C) 2017 Manos Pitsidianakis | 17 | #include "sysemu/block-backend.h" |
26 | +# | 18 | #include "qapi/error.h" |
27 | +# This program is free software; you can redistribute it and/or modify | 19 | |
28 | +# it under the terms of the GNU General Public License as published by | 20 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void) |
29 | +# the Free Software Foundation; either version 2 of the License, or | 21 | test_quiesce_common(BDRV_DRAIN, false); |
30 | +# (at your option) any later version. | 22 | } |
31 | +# | 23 | |
32 | +# This program is distributed in the hope that it will be useful, | ||
33 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
34 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
35 | +# GNU General Public License for more details. | ||
36 | +# | ||
37 | +# 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/>. | ||
39 | +# | ||
40 | + | 24 | + |
41 | +# creator | 25 | +typedef struct TestBlockJob { |
42 | +owner="Manos Pitsidianakis" | 26 | + BlockJob common; |
27 | + bool should_complete; | ||
28 | +} TestBlockJob; | ||
43 | + | 29 | + |
44 | +seq=`basename $0` | 30 | +static void test_job_completed(BlockJob *job, void *opaque) |
45 | +echo "QA output created by $seq" | ||
46 | + | ||
47 | +here=`pwd` | ||
48 | +status=1 # failure is the default! | ||
49 | + | ||
50 | +_cleanup() | ||
51 | +{ | 31 | +{ |
52 | + _cleanup_test_img | 32 | + block_job_completed(job, 0); |
53 | +} | ||
54 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
55 | + | ||
56 | +# get standard environment, filters and checks | ||
57 | +. ./common.rc | ||
58 | +. ./common.filter | ||
59 | + | ||
60 | +_supported_fmt qcow2 | ||
61 | +_supported_proto file | ||
62 | +_supported_os Linux | ||
63 | + | ||
64 | +function do_run_qemu() | ||
65 | +{ | ||
66 | + echo Testing: "$@" | _filter_imgfmt | ||
67 | + $QEMU -nographic -qmp-pretty stdio -serial none "$@" | ||
68 | + echo | ||
69 | +} | 33 | +} |
70 | + | 34 | + |
71 | +function run_qemu() | 35 | +static void coroutine_fn test_job_start(void *opaque) |
72 | +{ | 36 | +{ |
73 | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\ | 37 | + TestBlockJob *s = opaque; |
74 | + | _filter_qemu_io | _filter_generated_node_ids | 38 | + |
39 | + while (!s->should_complete) { | ||
40 | + block_job_sleep_ns(&s->common, 100000); | ||
41 | + } | ||
42 | + | ||
43 | + block_job_defer_to_main_loop(&s->common, test_job_completed, NULL); | ||
75 | +} | 44 | +} |
76 | + | 45 | + |
77 | +_make_test_img 64M | 46 | +static void test_job_complete(BlockJob *job, Error **errp) |
78 | +test_throttle=$($QEMU_IMG --help|grep throttle) | ||
79 | +[ "$test_throttle" = "" ] && _supported_fmt throttle | ||
80 | + | ||
81 | +echo | ||
82 | +echo "== checking interface ==" | ||
83 | + | ||
84 | +run_qemu <<EOF | ||
85 | +{ "execute": "qmp_capabilities" } | ||
86 | +{ "execute": "blockdev-add", | ||
87 | + "arguments": { | ||
88 | + "driver": "$IMGFMT", | ||
89 | + "node-name": "disk0", | ||
90 | + "file": { | ||
91 | + "driver": "file", | ||
92 | + "filename": "$TEST_IMG" | ||
93 | + } | ||
94 | + } | ||
95 | +} | ||
96 | +{ "execute": "object-add", | ||
97 | + "arguments": { | ||
98 | + "qom-type": "throttle-group", | ||
99 | + "id": "group0", | ||
100 | + "props": { | ||
101 | + "limits" : { | ||
102 | + "iops-total": 1000 | ||
103 | + } | ||
104 | + } | ||
105 | + } | ||
106 | +} | ||
107 | +{ "execute": "blockdev-add", | ||
108 | + "arguments": { | ||
109 | + "driver": "throttle", | ||
110 | + "node-name": "throttle0", | ||
111 | + "throttle-group": "group0", | ||
112 | + "file": "disk0" | ||
113 | + } | ||
114 | +} | ||
115 | +{ "execute": "query-named-block-nodes" } | ||
116 | +{ "execute": "query-block" } | ||
117 | +{ "execute": "quit" } | ||
118 | +EOF | ||
119 | + | ||
120 | +echo | ||
121 | +echo "== property changes in ThrottleGroup ==" | ||
122 | + | ||
123 | +run_qemu <<EOF | ||
124 | +{ "execute": "qmp_capabilities" } | ||
125 | +{ "execute": "object-add", | ||
126 | + "arguments": { | ||
127 | + "qom-type": "throttle-group", | ||
128 | + "id": "group0", | ||
129 | + "props" : { | ||
130 | + "limits": { | ||
131 | + "iops-total": 1000 | ||
132 | + } | ||
133 | + } | ||
134 | + } | ||
135 | +} | ||
136 | +{ "execute" : "qom-get", | ||
137 | + "arguments" : { | ||
138 | + "path" : "group0", | ||
139 | + "property" : "limits" | ||
140 | + } | ||
141 | +} | ||
142 | +{ "execute" : "qom-set", | ||
143 | + "arguments" : { | ||
144 | + "path" : "group0", | ||
145 | + "property" : "limits", | ||
146 | + "value" : { | ||
147 | + "iops-total" : 0 | ||
148 | + } | ||
149 | + } | ||
150 | +} | ||
151 | +{ "execute" : "qom-get", | ||
152 | + "arguments" : { | ||
153 | + "path" : "group0", | ||
154 | + "property" : "limits" | ||
155 | + } | ||
156 | +} | ||
157 | +{ "execute": "quit" } | ||
158 | +EOF | ||
159 | + | ||
160 | +echo | ||
161 | +echo "== object creation/set errors ==" | ||
162 | + | ||
163 | +run_qemu <<EOF | ||
164 | +{ "execute": "qmp_capabilities" } | ||
165 | +{ "execute": "object-add", | ||
166 | + "arguments": { | ||
167 | + "qom-type": "throttle-group", | ||
168 | + "id": "group0", | ||
169 | + "props" : { | ||
170 | + "limits": { | ||
171 | + "iops-total": 1000 | ||
172 | + } | ||
173 | + } | ||
174 | + } | ||
175 | +} | ||
176 | +{ "execute" : "qom-set", | ||
177 | + "arguments" : { | ||
178 | + "path" : "group0", | ||
179 | + "property" : "x-iops-total", | ||
180 | + "value" : 0 | ||
181 | + } | ||
182 | +} | ||
183 | +{ "execute" : "qom-set", | ||
184 | + "arguments" : { | ||
185 | + "path" : "group0", | ||
186 | + "property" : "limits", | ||
187 | + "value" : { | ||
188 | + "iops-total" : 10, | ||
189 | + "iops-read" : 10 | ||
190 | + } | ||
191 | + } | ||
192 | +} | ||
193 | +{ "execute": "quit" } | ||
194 | +EOF | ||
195 | + | ||
196 | +echo | ||
197 | +echo "== don't specify group ==" | ||
198 | + | ||
199 | +run_qemu <<EOF | ||
200 | +{ "execute": "qmp_capabilities" } | ||
201 | +{ "execute": "blockdev-add", | ||
202 | + "arguments": { | ||
203 | + "driver": "$IMGFMT", | ||
204 | + "node-name": "disk0", | ||
205 | + "file": { | ||
206 | + "driver": "file", | ||
207 | + "filename": "$TEST_IMG" | ||
208 | + } | ||
209 | + } | ||
210 | +} | ||
211 | +{ "execute": "blockdev-add", | ||
212 | + "arguments": { | ||
213 | + "driver": "throttle", | ||
214 | + "node-name": "throttle0", | ||
215 | + "file": "disk0" | ||
216 | + } | ||
217 | +} | ||
218 | +{ "execute": "quit" } | ||
219 | +EOF | ||
220 | + | ||
221 | +echo | ||
222 | +# success, all done | ||
223 | +echo "*** done" | ||
224 | +rm -f $seq.full | ||
225 | +status=0 | ||
226 | diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out | ||
227 | new file mode 100644 | ||
228 | index XXXXXXX..XXXXXXX | ||
229 | --- /dev/null | ||
230 | +++ b/tests/qemu-iotests/184.out | ||
231 | @@ -XXX,XX +XXX,XX @@ | ||
232 | +QA output created by 184 | ||
233 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
234 | + | ||
235 | +== checking interface == | ||
236 | +Testing: | ||
237 | +{ | 47 | +{ |
238 | + QMP_VERSION | 48 | + TestBlockJob *s = container_of(job, TestBlockJob, common); |
239 | +} | 49 | + s->should_complete = true; |
240 | +{ | ||
241 | + "return": { | ||
242 | + } | ||
243 | +} | ||
244 | +{ | ||
245 | + "return": { | ||
246 | + } | ||
247 | +} | ||
248 | +{ | ||
249 | + "return": { | ||
250 | + } | ||
251 | +} | ||
252 | +{ | ||
253 | + "return": { | ||
254 | + } | ||
255 | +} | ||
256 | +{ | ||
257 | + "return": [ | ||
258 | + { | ||
259 | + "iops_rd": 0, | ||
260 | + "detect_zeroes": "off", | ||
261 | + "image": { | ||
262 | + "virtual-size": 67108864, | ||
263 | + "filename": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"qcow2\", \"file\": {\"driver\": \"file\", \"filename\": \"TEST_DIR/t.qcow2\"}}}", | ||
264 | + "cluster-size": 65536, | ||
265 | + "format": "throttle", | ||
266 | + "actual-size": 200704, | ||
267 | + "dirty-flag": false | ||
268 | + }, | ||
269 | + "iops_wr": 0, | ||
270 | + "ro": false, | ||
271 | + "node-name": "throttle0", | ||
272 | + "backing_file_depth": 0, | ||
273 | + "drv": "throttle", | ||
274 | + "iops": 0, | ||
275 | + "bps_wr": 0, | ||
276 | + "write_threshold": 0, | ||
277 | + "encrypted": false, | ||
278 | + "bps": 0, | ||
279 | + "bps_rd": 0, | ||
280 | + "cache": { | ||
281 | + "no-flush": false, | ||
282 | + "direct": false, | ||
283 | + "writeback": true | ||
284 | + }, | ||
285 | + "file": "json:{\"throttle-group\": \"group0\", \"driver\": \"throttle\", \"file\": {\"driver\": \"qcow2\", \"file\": {\"driver\": \"file\", \"filename\": \"TEST_DIR/t.qcow2\"}}}", | ||
286 | + "encryption_key_missing": false | ||
287 | + }, | ||
288 | + { | ||
289 | + "iops_rd": 0, | ||
290 | + "detect_zeroes": "off", | ||
291 | + "image": { | ||
292 | + "virtual-size": 67108864, | ||
293 | + "filename": "TEST_DIR/t.qcow2", | ||
294 | + "cluster-size": 65536, | ||
295 | + "format": "qcow2", | ||
296 | + "actual-size": 200704, | ||
297 | + "format-specific": { | ||
298 | + "type": "qcow2", | ||
299 | + "data": { | ||
300 | + "compat": "1.1", | ||
301 | + "lazy-refcounts": false, | ||
302 | + "refcount-bits": 16, | ||
303 | + "corrupt": false | ||
304 | + } | ||
305 | + }, | ||
306 | + "dirty-flag": false | ||
307 | + }, | ||
308 | + "iops_wr": 0, | ||
309 | + "ro": false, | ||
310 | + "node-name": "disk0", | ||
311 | + "backing_file_depth": 0, | ||
312 | + "drv": "qcow2", | ||
313 | + "iops": 0, | ||
314 | + "bps_wr": 0, | ||
315 | + "write_threshold": 0, | ||
316 | + "encrypted": false, | ||
317 | + "bps": 0, | ||
318 | + "bps_rd": 0, | ||
319 | + "cache": { | ||
320 | + "no-flush": false, | ||
321 | + "direct": false, | ||
322 | + "writeback": true | ||
323 | + }, | ||
324 | + "file": "TEST_DIR/t.qcow2", | ||
325 | + "encryption_key_missing": false | ||
326 | + }, | ||
327 | + { | ||
328 | + "iops_rd": 0, | ||
329 | + "detect_zeroes": "off", | ||
330 | + "image": { | ||
331 | + "virtual-size": 197120, | ||
332 | + "filename": "TEST_DIR/t.qcow2", | ||
333 | + "format": "file", | ||
334 | + "actual-size": 200704, | ||
335 | + "dirty-flag": false | ||
336 | + }, | ||
337 | + "iops_wr": 0, | ||
338 | + "ro": false, | ||
339 | + "node-name": "NODE_NAME", | ||
340 | + "backing_file_depth": 0, | ||
341 | + "drv": "file", | ||
342 | + "iops": 0, | ||
343 | + "bps_wr": 0, | ||
344 | + "write_threshold": 0, | ||
345 | + "encrypted": false, | ||
346 | + "bps": 0, | ||
347 | + "bps_rd": 0, | ||
348 | + "cache": { | ||
349 | + "no-flush": false, | ||
350 | + "direct": false, | ||
351 | + "writeback": true | ||
352 | + }, | ||
353 | + "file": "TEST_DIR/t.qcow2", | ||
354 | + "encryption_key_missing": false | ||
355 | + } | ||
356 | + ] | ||
357 | +} | ||
358 | +{ | ||
359 | + "return": [ | ||
360 | + ] | ||
361 | +} | ||
362 | +{ | ||
363 | + "return": { | ||
364 | + } | ||
365 | +} | ||
366 | +{ | ||
367 | + "timestamp": { | ||
368 | + "seconds": TIMESTAMP, | ||
369 | + "microseconds": TIMESTAMP | ||
370 | + }, | ||
371 | + "event": "SHUTDOWN", | ||
372 | + "data": { | ||
373 | + "guest": false | ||
374 | + } | ||
375 | +} | 50 | +} |
376 | + | 51 | + |
52 | +BlockJobDriver test_job_driver = { | ||
53 | + .instance_size = sizeof(TestBlockJob), | ||
54 | + .start = test_job_start, | ||
55 | + .complete = test_job_complete, | ||
56 | +}; | ||
377 | + | 57 | + |
378 | +== property changes in ThrottleGroup == | 58 | +static void test_blockjob_common(enum drain_type drain_type) |
379 | +Testing: | ||
380 | +{ | 59 | +{ |
381 | + QMP_VERSION | 60 | + BlockBackend *blk_src, *blk_target; |
382 | +} | 61 | + BlockDriverState *src, *target; |
383 | +{ | 62 | + BlockJob *job; |
384 | + "return": { | 63 | + int ret; |
64 | + | ||
65 | + src = bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR, | ||
66 | + &error_abort); | ||
67 | + blk_src = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
68 | + blk_insert_bs(blk_src, src, &error_abort); | ||
69 | + | ||
70 | + target = bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR, | ||
71 | + &error_abort); | ||
72 | + blk_target = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
73 | + blk_insert_bs(blk_target, target, &error_abort); | ||
74 | + | ||
75 | + job = block_job_create("job0", &test_job_driver, src, 0, BLK_PERM_ALL, 0, | ||
76 | + 0, NULL, NULL, &error_abort); | ||
77 | + block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abort); | ||
78 | + block_job_start(job); | ||
79 | + | ||
80 | + g_assert_cmpint(job->pause_count, ==, 0); | ||
81 | + g_assert_false(job->paused); | ||
82 | + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ | ||
83 | + | ||
84 | + do_drain_begin(drain_type, src); | ||
85 | + | ||
86 | + if (drain_type == BDRV_DRAIN_ALL) { | ||
87 | + /* bdrv_drain_all() drains both src and target, and involves an | ||
88 | + * additional block_job_pause_all() */ | ||
89 | + g_assert_cmpint(job->pause_count, ==, 3); | ||
90 | + } else { | ||
91 | + g_assert_cmpint(job->pause_count, ==, 1); | ||
385 | + } | 92 | + } |
386 | +} | 93 | + /* XXX We don't wait until the job is actually paused. Is this okay? */ |
387 | +{ | 94 | + /* g_assert_true(job->paused); */ |
388 | + "return": { | 95 | + g_assert_false(job->busy); /* The job is paused */ |
96 | + | ||
97 | + do_drain_end(drain_type, src); | ||
98 | + | ||
99 | + g_assert_cmpint(job->pause_count, ==, 0); | ||
100 | + g_assert_false(job->paused); | ||
101 | + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ | ||
102 | + | ||
103 | + do_drain_begin(drain_type, target); | ||
104 | + | ||
105 | + if (drain_type == BDRV_DRAIN_ALL) { | ||
106 | + /* bdrv_drain_all() drains both src and target, and involves an | ||
107 | + * additional block_job_pause_all() */ | ||
108 | + g_assert_cmpint(job->pause_count, ==, 3); | ||
109 | + } else { | ||
110 | + g_assert_cmpint(job->pause_count, ==, 1); | ||
389 | + } | 111 | + } |
390 | +} | 112 | + /* XXX We don't wait until the job is actually paused. Is this okay? */ |
391 | +{ | 113 | + /* g_assert_true(job->paused); */ |
392 | + "return": { | 114 | + g_assert_false(job->busy); /* The job is paused */ |
393 | + "bps-read-max-length": 1, | 115 | + |
394 | + "iops-read-max-length": 1, | 116 | + do_drain_end(drain_type, target); |
395 | + "bps-read-max": 0, | 117 | + |
396 | + "bps-total": 0, | 118 | + g_assert_cmpint(job->pause_count, ==, 0); |
397 | + "iops-total-max-length": 1, | 119 | + g_assert_false(job->paused); |
398 | + "iops-total": 1000, | 120 | + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ |
399 | + "iops-write-max": 0, | 121 | + |
400 | + "bps-write": 0, | 122 | + ret = block_job_complete_sync(job, &error_abort); |
401 | + "bps-total-max": 0, | 123 | + g_assert_cmpint(ret, ==, 0); |
402 | + "bps-write-max": 0, | 124 | + |
403 | + "iops-size": 0, | 125 | + blk_unref(blk_src); |
404 | + "iops-read": 0, | 126 | + blk_unref(blk_target); |
405 | + "iops-write-max-length": 1, | 127 | + bdrv_unref(src); |
406 | + "iops-write": 0, | 128 | + bdrv_unref(target); |
407 | + "bps-total-max-length": 1, | ||
408 | + "iops-read-max": 0, | ||
409 | + "bps-read": 0, | ||
410 | + "bps-write-max-length": 1, | ||
411 | + "iops-total-max": 0 | ||
412 | + } | ||
413 | +} | ||
414 | +{ | ||
415 | + "return": { | ||
416 | + } | ||
417 | +} | ||
418 | +{ | ||
419 | + "return": { | ||
420 | + "bps-read-max-length": 1, | ||
421 | + "iops-read-max-length": 1, | ||
422 | + "bps-read-max": 0, | ||
423 | + "bps-total": 0, | ||
424 | + "iops-total-max-length": 1, | ||
425 | + "iops-total": 0, | ||
426 | + "iops-write-max": 0, | ||
427 | + "bps-write": 0, | ||
428 | + "bps-total-max": 0, | ||
429 | + "bps-write-max": 0, | ||
430 | + "iops-size": 0, | ||
431 | + "iops-read": 0, | ||
432 | + "iops-write-max-length": 1, | ||
433 | + "iops-write": 0, | ||
434 | + "bps-total-max-length": 1, | ||
435 | + "iops-read-max": 0, | ||
436 | + "bps-read": 0, | ||
437 | + "bps-write-max-length": 1, | ||
438 | + "iops-total-max": 0 | ||
439 | + } | ||
440 | +} | ||
441 | +{ | ||
442 | + "return": { | ||
443 | + } | ||
444 | +} | ||
445 | +{ | ||
446 | + "timestamp": { | ||
447 | + "seconds": TIMESTAMP, | ||
448 | + "microseconds": TIMESTAMP | ||
449 | + }, | ||
450 | + "event": "SHUTDOWN", | ||
451 | + "data": { | ||
452 | + "guest": false | ||
453 | + } | ||
454 | +} | 129 | +} |
455 | + | 130 | + |
456 | + | 131 | +static void test_blockjob_drain_all(void) |
457 | +== object creation/set errors == | ||
458 | +Testing: | ||
459 | +{ | 132 | +{ |
460 | + QMP_VERSION | 133 | + test_blockjob_common(BDRV_DRAIN_ALL); |
461 | +} | ||
462 | +{ | ||
463 | + "return": { | ||
464 | + } | ||
465 | +} | ||
466 | +{ | ||
467 | + "return": { | ||
468 | + } | ||
469 | +} | ||
470 | +{ | ||
471 | + "error": { | ||
472 | + "class": "GenericError", | ||
473 | + "desc": "Property cannot be set after initialization" | ||
474 | + } | ||
475 | +} | ||
476 | +{ | ||
477 | + "error": { | ||
478 | + "class": "GenericError", | ||
479 | + "desc": "bps/iops/max total values and read/write values cannot be used at the same time" | ||
480 | + } | ||
481 | +} | ||
482 | +{ | ||
483 | + "return": { | ||
484 | + } | ||
485 | +} | ||
486 | +{ | ||
487 | + "timestamp": { | ||
488 | + "seconds": TIMESTAMP, | ||
489 | + "microseconds": TIMESTAMP | ||
490 | + }, | ||
491 | + "event": "SHUTDOWN", | ||
492 | + "data": { | ||
493 | + "guest": false | ||
494 | + } | ||
495 | +} | 134 | +} |
496 | + | 135 | + |
497 | + | 136 | +static void test_blockjob_drain(void) |
498 | +== don't specify group == | ||
499 | +Testing: | ||
500 | +{ | 137 | +{ |
501 | + QMP_VERSION | 138 | + test_blockjob_common(BDRV_DRAIN); |
502 | +} | ||
503 | +{ | ||
504 | + "return": { | ||
505 | + } | ||
506 | +} | ||
507 | +{ | ||
508 | + "return": { | ||
509 | + } | ||
510 | +} | ||
511 | +{ | ||
512 | + "error": { | ||
513 | + "class": "GenericError", | ||
514 | + "desc": "Parameter 'throttle-group' is missing" | ||
515 | + } | ||
516 | +} | ||
517 | +{ | ||
518 | + "return": { | ||
519 | + } | ||
520 | +} | ||
521 | +{ | ||
522 | + "timestamp": { | ||
523 | + "seconds": TIMESTAMP, | ||
524 | + "microseconds": TIMESTAMP | ||
525 | + }, | ||
526 | + "event": "SHUTDOWN", | ||
527 | + "data": { | ||
528 | + "guest": false | ||
529 | + } | ||
530 | +} | 139 | +} |
531 | + | 140 | + |
141 | int main(int argc, char **argv) | ||
142 | { | ||
143 | bdrv_init(); | ||
144 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
145 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); | ||
146 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); | ||
147 | |||
148 | + g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); | ||
149 | + g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | ||
532 | + | 150 | + |
533 | +*** done | 151 | return g_test_run(); |
534 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | 152 | } |
535 | index XXXXXXX..XXXXXXX 100644 | ||
536 | --- a/tests/qemu-iotests/group | ||
537 | +++ b/tests/qemu-iotests/group | ||
538 | @@ -XXX,XX +XXX,XX @@ | ||
539 | 181 rw auto migration | ||
540 | 182 rw auto quick | ||
541 | 183 rw auto migration | ||
542 | +184 rw auto quick | ||
543 | 185 rw auto | ||
544 | 186 rw auto | ||
545 | 187 rw auto | ||
546 | -- | 153 | -- |
547 | 2.13.5 | 154 | 2.13.6 |
548 | 155 | ||
549 | 156 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Block jobs are already paused using the BdrvChildRole drain callbacks, | ||
2 | so we don't need an additional block_job_pause_all() call. | ||
1 | 3 | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
5 | --- | ||
6 | block/io.c | 4 ---- | ||
7 | tests/test-bdrv-drain.c | 10 ++++------ | ||
8 | 2 files changed, 4 insertions(+), 10 deletions(-) | ||
9 | |||
10 | diff --git a/block/io.c b/block/io.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/block/io.c | ||
13 | +++ b/block/io.c | ||
14 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
15 | * context. */ | ||
16 | assert(qemu_get_current_aio_context() == qemu_get_aio_context()); | ||
17 | |||
18 | - block_job_pause_all(); | ||
19 | - | ||
20 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { | ||
21 | AioContext *aio_context = bdrv_get_aio_context(bs); | ||
22 | |||
23 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
24 | aio_enable_external(aio_context); | ||
25 | aio_context_release(aio_context); | ||
26 | } | ||
27 | - | ||
28 | - block_job_resume_all(); | ||
29 | } | ||
30 | |||
31 | void bdrv_drain_all(void) | ||
32 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/tests/test-bdrv-drain.c | ||
35 | +++ b/tests/test-bdrv-drain.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type) | ||
37 | do_drain_begin(drain_type, src); | ||
38 | |||
39 | if (drain_type == BDRV_DRAIN_ALL) { | ||
40 | - /* bdrv_drain_all() drains both src and target, and involves an | ||
41 | - * additional block_job_pause_all() */ | ||
42 | - g_assert_cmpint(job->pause_count, ==, 3); | ||
43 | + /* bdrv_drain_all() drains both src and target */ | ||
44 | + g_assert_cmpint(job->pause_count, ==, 2); | ||
45 | } else { | ||
46 | g_assert_cmpint(job->pause_count, ==, 1); | ||
47 | } | ||
48 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type) | ||
49 | do_drain_begin(drain_type, target); | ||
50 | |||
51 | if (drain_type == BDRV_DRAIN_ALL) { | ||
52 | - /* bdrv_drain_all() drains both src and target, and involves an | ||
53 | - * additional block_job_pause_all() */ | ||
54 | - g_assert_cmpint(job->pause_count, ==, 3); | ||
55 | + /* bdrv_drain_all() drains both src and target */ | ||
56 | + g_assert_cmpint(job->pause_count, ==, 2); | ||
57 | } else { | ||
58 | g_assert_cmpint(job->pause_count, ==, 1); | ||
59 | } | ||
60 | -- | ||
61 | 2.13.6 | ||
62 | |||
63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | bdrv_do_drained_begin() restricts the call of parent callbacks and | ||
2 | aio_disable_external() to the outermost drain section, but the block | ||
3 | driver callbacks are always called. bdrv_do_drained_end() must match | ||
4 | this behaviour, otherwise nodes stay drained even if begin/end calls | ||
5 | were balanced. | ||
1 | 6 | ||
7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | --- | ||
9 | block/io.c | 12 +++++++----- | ||
10 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
11 | |||
12 | diff --git a/block/io.c b/block/io.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/block/io.c | ||
15 | +++ b/block/io.c | ||
16 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) | ||
17 | |||
18 | void bdrv_drained_end(BlockDriverState *bs) | ||
19 | { | ||
20 | + int old_quiesce_counter; | ||
21 | + | ||
22 | if (qemu_in_coroutine()) { | ||
23 | bdrv_co_yield_to_drain(bs, false); | ||
24 | return; | ||
25 | } | ||
26 | assert(bs->quiesce_counter > 0); | ||
27 | - if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { | ||
28 | - return; | ||
29 | - } | ||
30 | + old_quiesce_counter = atomic_fetch_dec(&bs->quiesce_counter); | ||
31 | |||
32 | /* Re-enable things in child-to-parent order */ | ||
33 | bdrv_drain_invoke(bs, false, false); | ||
34 | - bdrv_parent_drained_end(bs); | ||
35 | - aio_enable_external(bdrv_get_aio_context(bs)); | ||
36 | + if (old_quiesce_counter == 1) { | ||
37 | + bdrv_parent_drained_end(bs); | ||
38 | + aio_enable_external(bdrv_get_aio_context(bs)); | ||
39 | + } | ||
40 | } | ||
41 | |||
42 | /* | ||
43 | -- | ||
44 | 2.13.6 | ||
45 | |||
46 | diff view generated by jsdifflib |
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | ||
---|---|---|---|
2 | |||
3 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
6 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
7 | --- | 2 | --- |
8 | include/block/block_int.h | 31 +++++++++++++++++++++++++++++++ | 3 | tests/test-bdrv-drain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | 1 file changed, 31 insertions(+) | 4 | 1 file changed, 57 insertions(+) |
10 | 5 | ||
11 | diff --git a/include/block/block_int.h b/include/block/block_int.h | 6 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
12 | index XXXXXXX..XXXXXXX 100644 | 7 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/include/block/block_int.h | 8 | --- a/tests/test-bdrv-drain.c |
14 | +++ b/include/block/block_int.h | 9 | +++ b/tests/test-bdrv-drain.c |
15 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | 10 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
16 | 11 | enum drain_type { | |
17 | int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, | 12 | BDRV_DRAIN_ALL, |
18 | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); | 13 | BDRV_DRAIN, |
14 | + DRAIN_TYPE_MAX, | ||
15 | }; | ||
16 | |||
17 | static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs) | ||
18 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void) | ||
19 | test_quiesce_common(BDRV_DRAIN, false); | ||
20 | } | ||
21 | |||
22 | +static void test_nested(void) | ||
23 | +{ | ||
24 | + BlockBackend *blk; | ||
25 | + BlockDriverState *bs, *backing; | ||
26 | + BDRVTestState *s, *backing_s; | ||
27 | + enum drain_type outer, inner; | ||
19 | + | 28 | + |
20 | + /** | 29 | + blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
21 | + * @offset: position in bytes to read at | 30 | + bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, |
22 | + * @bytes: number of bytes to read | 31 | + &error_abort); |
23 | + * @qiov: the buffers to fill with read data | 32 | + s = bs->opaque; |
24 | + * @flags: currently unused, always 0 | 33 | + blk_insert_bs(blk, bs, &error_abort); |
25 | + * | 34 | + |
26 | + * @offset and @bytes will be a multiple of 'request_alignment', | 35 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); |
27 | + * but the length of individual @qiov elements does not have to | 36 | + backing_s = backing->opaque; |
28 | + * be a multiple. | 37 | + bdrv_set_backing_hd(bs, backing, &error_abort); |
29 | + * | 38 | + |
30 | + * @bytes will always equal the total size of @qiov, and will be | 39 | + for (outer = 0; outer < DRAIN_TYPE_MAX; outer++) { |
31 | + * no larger than 'max_transfer'. | 40 | + for (inner = 0; inner < DRAIN_TYPE_MAX; inner++) { |
32 | + * | 41 | + /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ |
33 | + * The buffer in @qiov may point directly to guest memory. | 42 | + int bs_quiesce = (outer != BDRV_DRAIN_ALL) + |
34 | + */ | 43 | + (inner != BDRV_DRAIN_ALL); |
35 | int coroutine_fn (*bdrv_co_preadv)(BlockDriverState *bs, | 44 | + int backing_quiesce = 0; |
36 | uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags); | 45 | + int backing_cb_cnt = (outer != BDRV_DRAIN) + |
37 | int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, | 46 | + (inner != BDRV_DRAIN); |
38 | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); | 47 | + |
39 | int coroutine_fn (*bdrv_co_writev_flags)(BlockDriverState *bs, | 48 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); |
40 | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int flags); | 49 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); |
41 | + /** | 50 | + g_assert_cmpint(s->drain_count, ==, 0); |
42 | + * @offset: position in bytes to write at | 51 | + g_assert_cmpint(backing_s->drain_count, ==, 0); |
43 | + * @bytes: number of bytes to write | 52 | + |
44 | + * @qiov: the buffers containing data to write | 53 | + do_drain_begin(outer, bs); |
45 | + * @flags: zero or more bits allowed by 'supported_write_flags' | 54 | + do_drain_begin(inner, bs); |
46 | + * | 55 | + |
47 | + * @offset and @bytes will be a multiple of 'request_alignment', | 56 | + g_assert_cmpint(bs->quiesce_counter, ==, bs_quiesce); |
48 | + * but the length of individual @qiov elements does not have to | 57 | + g_assert_cmpint(backing->quiesce_counter, ==, backing_quiesce); |
49 | + * be a multiple. | 58 | + g_assert_cmpint(s->drain_count, ==, 2); |
50 | + * | 59 | + g_assert_cmpint(backing_s->drain_count, ==, backing_cb_cnt); |
51 | + * @bytes will always equal the total size of @qiov, and will be | 60 | + |
52 | + * no larger than 'max_transfer'. | 61 | + do_drain_end(inner, bs); |
53 | + * | 62 | + do_drain_end(outer, bs); |
54 | + * The buffer in @qiov may point directly to guest memory. | 63 | + |
55 | + */ | 64 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); |
56 | int coroutine_fn (*bdrv_co_pwritev)(BlockDriverState *bs, | 65 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); |
57 | uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags); | 66 | + g_assert_cmpint(s->drain_count, ==, 0); |
67 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + bdrv_unref(backing); | ||
72 | + bdrv_unref(bs); | ||
73 | + blk_unref(blk); | ||
74 | +} | ||
75 | + | ||
76 | |||
77 | typedef struct TestBlockJob { | ||
78 | BlockJob common; | ||
79 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
80 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); | ||
81 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); | ||
82 | |||
83 | + g_test_add_func("/bdrv-drain/nested", test_nested); | ||
84 | + | ||
85 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); | ||
86 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | ||
58 | 87 | ||
59 | -- | 88 | -- |
60 | 2.13.5 | 89 | 2.13.6 |
61 | 90 | ||
62 | 91 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | This is in preparation for subtree drains, i.e. drained sections that | |
2 | affect not only a single node, but recursively all child nodes, too. | ||
3 | |||
4 | Calling the parent callbacks for drain is pointless when we just came | ||
5 | from that parent node recursively and leads to multiple increases of | ||
6 | bs->quiesce_counter in a single drain call. Don't do it. | ||
7 | |||
8 | In order for this to work correctly, the parent callback must be called | ||
9 | for every bdrv_drain_begin/end() call, not only for the outermost one: | ||
10 | |||
11 | If we have a node N with two parents A and B, recursive draining of A | ||
12 | should cause the quiesce_counter of B to increase because its child N is | ||
13 | drained independently of B. If now B is recursively drained, too, A must | ||
14 | increase its quiesce_counter because N is drained independently of A | ||
15 | only now, even if N is going from quiesce_counter 1 to 2. | ||
16 | |||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | --- | ||
19 | include/block/block.h | 4 ++-- | ||
20 | block.c | 13 +++++++++---- | ||
21 | block/io.c | 47 ++++++++++++++++++++++++++++++++++------------- | ||
22 | 3 files changed, 45 insertions(+), 19 deletions(-) | ||
23 | |||
24 | diff --git a/include/block/block.h b/include/block/block.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/block/block.h | ||
27 | +++ b/include/block/block.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void bdrv_io_unplug(BlockDriverState *bs); | ||
29 | * Begin a quiesced section of all users of @bs. This is part of | ||
30 | * bdrv_drained_begin. | ||
31 | */ | ||
32 | -void bdrv_parent_drained_begin(BlockDriverState *bs); | ||
33 | +void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore); | ||
34 | |||
35 | /** | ||
36 | * bdrv_parent_drained_end: | ||
37 | @@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin(BlockDriverState *bs); | ||
38 | * End a quiesced section of all users of @bs. This is part of | ||
39 | * bdrv_drained_end. | ||
40 | */ | ||
41 | -void bdrv_parent_drained_end(BlockDriverState *bs); | ||
42 | +void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore); | ||
43 | |||
44 | /** | ||
45 | * bdrv_drained_begin: | ||
46 | diff --git a/block.c b/block.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/block.c | ||
49 | +++ b/block.c | ||
50 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
51 | BlockDriverState *new_bs) | ||
52 | { | ||
53 | BlockDriverState *old_bs = child->bs; | ||
54 | + int i; | ||
55 | |||
56 | if (old_bs && new_bs) { | ||
57 | assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs)); | ||
58 | } | ||
59 | if (old_bs) { | ||
60 | if (old_bs->quiesce_counter && child->role->drained_end) { | ||
61 | - child->role->drained_end(child); | ||
62 | + for (i = 0; i < old_bs->quiesce_counter; i++) { | ||
63 | + child->role->drained_end(child); | ||
64 | + } | ||
65 | } | ||
66 | if (child->role->detach) { | ||
67 | child->role->detach(child); | ||
68 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
69 | if (new_bs) { | ||
70 | QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); | ||
71 | if (new_bs->quiesce_counter && child->role->drained_begin) { | ||
72 | - child->role->drained_begin(child); | ||
73 | + for (i = 0; i < new_bs->quiesce_counter; i++) { | ||
74 | + child->role->drained_begin(child); | ||
75 | + } | ||
76 | } | ||
77 | |||
78 | if (child->role->attach) { | ||
79 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) | ||
80 | AioContext *ctx = bdrv_get_aio_context(bs); | ||
81 | |||
82 | aio_disable_external(ctx); | ||
83 | - bdrv_parent_drained_begin(bs); | ||
84 | + bdrv_parent_drained_begin(bs, NULL); | ||
85 | bdrv_drain(bs); /* ensure there are no in-flight requests */ | ||
86 | |||
87 | while (aio_poll(ctx, false)) { | ||
88 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) | ||
89 | */ | ||
90 | aio_context_acquire(new_context); | ||
91 | bdrv_attach_aio_context(bs, new_context); | ||
92 | - bdrv_parent_drained_end(bs); | ||
93 | + bdrv_parent_drained_end(bs, NULL); | ||
94 | aio_enable_external(ctx); | ||
95 | aio_context_release(new_context); | ||
96 | } | ||
97 | diff --git a/block/io.c b/block/io.c | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/block/io.c | ||
100 | +++ b/block/io.c | ||
101 | @@ -XXX,XX +XXX,XX @@ | ||
102 | static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, | ||
103 | int64_t offset, int bytes, BdrvRequestFlags flags); | ||
104 | |||
105 | -void bdrv_parent_drained_begin(BlockDriverState *bs) | ||
106 | +void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore) | ||
107 | { | ||
108 | BdrvChild *c, *next; | ||
109 | |||
110 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { | ||
111 | + if (c == ignore) { | ||
112 | + continue; | ||
113 | + } | ||
114 | if (c->role->drained_begin) { | ||
115 | c->role->drained_begin(c); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | -void bdrv_parent_drained_end(BlockDriverState *bs) | ||
121 | +void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore) | ||
122 | { | ||
123 | BdrvChild *c, *next; | ||
124 | |||
125 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { | ||
126 | + if (c == ignore) { | ||
127 | + continue; | ||
128 | + } | ||
129 | if (c->role->drained_end) { | ||
130 | c->role->drained_end(c); | ||
131 | } | ||
132 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
133 | BlockDriverState *bs; | ||
134 | bool done; | ||
135 | bool begin; | ||
136 | + BdrvChild *parent; | ||
137 | } BdrvCoDrainData; | ||
138 | |||
139 | static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) | ||
140 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs) | ||
141 | return waited; | ||
142 | } | ||
143 | |||
144 | +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); | ||
145 | +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); | ||
146 | + | ||
147 | static void bdrv_co_drain_bh_cb(void *opaque) | ||
148 | { | ||
149 | BdrvCoDrainData *data = opaque; | ||
150 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) | ||
151 | |||
152 | bdrv_dec_in_flight(bs); | ||
153 | if (data->begin) { | ||
154 | - bdrv_drained_begin(bs); | ||
155 | + bdrv_do_drained_begin(bs, data->parent); | ||
156 | } else { | ||
157 | - bdrv_drained_end(bs); | ||
158 | + bdrv_do_drained_end(bs, data->parent); | ||
159 | } | ||
160 | |||
161 | data->done = true; | ||
162 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) | ||
163 | } | ||
164 | |||
165 | static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
166 | - bool begin) | ||
167 | + bool begin, BdrvChild *parent) | ||
168 | { | ||
169 | BdrvCoDrainData data; | ||
170 | |||
171 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
172 | .bs = bs, | ||
173 | .done = false, | ||
174 | .begin = begin, | ||
175 | + .parent = parent, | ||
176 | }; | ||
177 | bdrv_inc_in_flight(bs); | ||
178 | aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), | ||
179 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
180 | assert(data.done); | ||
181 | } | ||
182 | |||
183 | -void bdrv_drained_begin(BlockDriverState *bs) | ||
184 | +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) | ||
185 | { | ||
186 | if (qemu_in_coroutine()) { | ||
187 | - bdrv_co_yield_to_drain(bs, true); | ||
188 | + bdrv_co_yield_to_drain(bs, true, parent); | ||
189 | return; | ||
190 | } | ||
191 | |||
192 | /* Stop things in parent-to-child order */ | ||
193 | if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { | ||
194 | aio_disable_external(bdrv_get_aio_context(bs)); | ||
195 | - bdrv_parent_drained_begin(bs); | ||
196 | } | ||
197 | |||
198 | + bdrv_parent_drained_begin(bs, parent); | ||
199 | bdrv_drain_invoke(bs, true, false); | ||
200 | bdrv_drain_recurse(bs); | ||
201 | } | ||
202 | |||
203 | -void bdrv_drained_end(BlockDriverState *bs) | ||
204 | +void bdrv_drained_begin(BlockDriverState *bs) | ||
205 | +{ | ||
206 | + bdrv_do_drained_begin(bs, NULL); | ||
207 | +} | ||
208 | + | ||
209 | +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) | ||
210 | { | ||
211 | int old_quiesce_counter; | ||
212 | |||
213 | if (qemu_in_coroutine()) { | ||
214 | - bdrv_co_yield_to_drain(bs, false); | ||
215 | + bdrv_co_yield_to_drain(bs, false, parent); | ||
216 | return; | ||
217 | } | ||
218 | assert(bs->quiesce_counter > 0); | ||
219 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) | ||
220 | |||
221 | /* Re-enable things in child-to-parent order */ | ||
222 | bdrv_drain_invoke(bs, false, false); | ||
223 | + bdrv_parent_drained_end(bs, parent); | ||
224 | if (old_quiesce_counter == 1) { | ||
225 | - bdrv_parent_drained_end(bs); | ||
226 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | +void bdrv_drained_end(BlockDriverState *bs) | ||
231 | +{ | ||
232 | + bdrv_do_drained_end(bs, NULL); | ||
233 | +} | ||
234 | + | ||
235 | /* | ||
236 | * Wait for pending requests to complete on a single BlockDriverState subtree, | ||
237 | * and suspend block driver's internal I/O until next request arrives. | ||
238 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | ||
239 | /* Stop things in parent-to-child order */ | ||
240 | aio_context_acquire(aio_context); | ||
241 | aio_disable_external(aio_context); | ||
242 | - bdrv_parent_drained_begin(bs); | ||
243 | + bdrv_parent_drained_begin(bs, NULL); | ||
244 | bdrv_drain_invoke(bs, true, true); | ||
245 | aio_context_release(aio_context); | ||
246 | |||
247 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) | ||
248 | /* Re-enable things in child-to-parent order */ | ||
249 | aio_context_acquire(aio_context); | ||
250 | bdrv_drain_invoke(bs, false, true); | ||
251 | - bdrv_parent_drained_end(bs); | ||
252 | + bdrv_parent_drained_end(bs, NULL); | ||
253 | aio_enable_external(aio_context); | ||
254 | aio_context_release(aio_context); | ||
255 | } | ||
256 | -- | ||
257 | 2.13.6 | ||
258 | |||
259 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | bdrv_drained_begin() waits for the completion of requests in the whole |
---|---|---|---|
2 | subtree, but it only actually keeps its immediate bs parameter quiesced | ||
3 | until bdrv_drained_end(). | ||
2 | 4 | ||
3 | timer_cb() needs to know about the current Aio context of the throttle | 5 | Add a version that keeps the whole subtree drained. As of this commit, |
4 | request that is woken up. In order to make ThrottleGroupMember backend | 6 | graph changes cannot be allowed during a subtree drained section, but |
5 | agnostic, this information is stored in an aio_context field instead of | 7 | this will be fixed soon. |
6 | accessing it from BlockBackend. | ||
7 | 8 | ||
8 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | --- | 10 | --- |
13 | include/block/throttle-groups.h | 7 ++++- | 11 | include/block/block.h | 13 +++++++++++++ |
14 | block/block-backend.c | 15 ++++------ | 12 | block/io.c | 54 ++++++++++++++++++++++++++++++++++++++++----------- |
15 | block/throttle-groups.c | 38 ++++++++++++++++--------- | 13 | 2 files changed, 56 insertions(+), 11 deletions(-) |
16 | tests/test-throttle.c | 63 +++++++++++++++++++++-------------------- | ||
17 | 4 files changed, 69 insertions(+), 54 deletions(-) | ||
18 | 14 | ||
19 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | 15 | diff --git a/include/block/block.h b/include/block/block.h |
20 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/block/throttle-groups.h | 17 | --- a/include/block/block.h |
22 | +++ b/include/block/throttle-groups.h | 18 | +++ b/include/block/block.h |
23 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore); |
20 | void bdrv_drained_begin(BlockDriverState *bs); | ||
21 | |||
22 | /** | ||
23 | + * Like bdrv_drained_begin, but recursively begins a quiesced section for | ||
24 | + * exclusive access to all child nodes as well. | ||
25 | + * | ||
26 | + * Graph changes are not allowed during a subtree drain section. | ||
27 | + */ | ||
28 | +void bdrv_subtree_drained_begin(BlockDriverState *bs); | ||
29 | + | ||
30 | +/** | ||
31 | * bdrv_drained_end: | ||
32 | * | ||
33 | * End a quiescent section started by bdrv_drained_begin(). | ||
24 | */ | 34 | */ |
25 | 35 | void bdrv_drained_end(BlockDriverState *bs); | |
26 | typedef struct ThrottleGroupMember { | 36 | |
27 | + AioContext *aio_context; | 37 | +/** |
28 | /* throttled_reqs_lock protects the CoQueues for throttled requests. */ | 38 | + * End a quiescent section started by bdrv_subtree_drained_begin(). |
29 | CoMutex throttled_reqs_lock; | 39 | + */ |
30 | CoQueue throttled_reqs[2]; | 40 | +void bdrv_subtree_drained_end(BlockDriverState *bs); |
31 | @@ -XXX,XX +XXX,XX @@ void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg); | 41 | + |
32 | void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg); | 42 | void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child, |
33 | 43 | Error **errp); | |
34 | void throttle_group_register_tgm(ThrottleGroupMember *tgm, | 44 | void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp); |
35 | - const char *groupname); | 45 | diff --git a/block/io.c b/block/io.c |
36 | + const char *groupname, | ||
37 | + AioContext *ctx); | ||
38 | void throttle_group_unregister_tgm(ThrottleGroupMember *tgm); | ||
39 | void throttle_group_restart_tgm(ThrottleGroupMember *tgm); | ||
40 | |||
41 | void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm, | ||
42 | unsigned int bytes, | ||
43 | bool is_write); | ||
44 | +void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, | ||
45 | + AioContext *new_context); | ||
46 | +void throttle_group_detach_aio_context(ThrottleGroupMember *tgm); | ||
47 | |||
48 | #endif | ||
49 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/block/block-backend.c | 47 | --- a/block/io.c |
52 | +++ b/block/block-backend.c | 48 | +++ b/block/io.c |
53 | @@ -XXX,XX +XXX,XX @@ static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb) | 49 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
54 | void blk_set_aio_context(BlockBackend *blk, AioContext *new_context) | 50 | BlockDriverState *bs; |
51 | bool done; | ||
52 | bool begin; | ||
53 | + bool recursive; | ||
54 | BdrvChild *parent; | ||
55 | } BdrvCoDrainData; | ||
56 | |||
57 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs) | ||
58 | return waited; | ||
59 | } | ||
60 | |||
61 | -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); | ||
62 | -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); | ||
63 | +static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, | ||
64 | + BdrvChild *parent); | ||
65 | +static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, | ||
66 | + BdrvChild *parent); | ||
67 | |||
68 | static void bdrv_co_drain_bh_cb(void *opaque) | ||
55 | { | 69 | { |
56 | BlockDriverState *bs = blk_bs(blk); | 70 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) |
57 | - ThrottleTimers *tt; | 71 | |
58 | + ThrottleGroupMember *tgm = &blk->public.throttle_group_member; | 72 | bdrv_dec_in_flight(bs); |
59 | 73 | if (data->begin) { | |
60 | if (bs) { | 74 | - bdrv_do_drained_begin(bs, data->parent); |
61 | - if (blk->public.throttle_group_member.throttle_state) { | 75 | + bdrv_do_drained_begin(bs, data->recursive, data->parent); |
62 | - tt = &blk->public.throttle_group_member.throttle_timers; | 76 | } else { |
63 | - throttle_timers_detach_aio_context(tt); | 77 | - bdrv_do_drained_end(bs, data->parent); |
64 | + if (tgm->throttle_state) { | 78 | + bdrv_do_drained_end(bs, data->recursive, data->parent); |
65 | + throttle_group_detach_aio_context(tgm); | ||
66 | + throttle_group_attach_aio_context(tgm, new_context); | ||
67 | } | ||
68 | bdrv_set_aio_context(bs, new_context); | ||
69 | - if (blk->public.throttle_group_member.throttle_state) { | ||
70 | - tt = &blk->public.throttle_group_member.throttle_timers; | ||
71 | - throttle_timers_attach_aio_context(tt, new_context); | ||
72 | - } | ||
73 | } | 79 | } |
80 | |||
81 | data->done = true; | ||
82 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) | ||
74 | } | 83 | } |
75 | 84 | ||
76 | @@ -XXX,XX +XXX,XX @@ void blk_io_limits_disable(BlockBackend *blk) | 85 | static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
77 | void blk_io_limits_enable(BlockBackend *blk, const char *group) | 86 | - bool begin, BdrvChild *parent) |
87 | + bool begin, bool recursive, | ||
88 | + BdrvChild *parent) | ||
78 | { | 89 | { |
79 | assert(!blk->public.throttle_group_member.throttle_state); | 90 | BdrvCoDrainData data; |
80 | - throttle_group_register_tgm(&blk->public.throttle_group_member, group); | 91 | |
81 | + throttle_group_register_tgm(&blk->public.throttle_group_member, | 92 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
82 | + group, blk_get_aio_context(blk)); | 93 | .bs = bs, |
94 | .done = false, | ||
95 | .begin = begin, | ||
96 | + .recursive = recursive, | ||
97 | .parent = parent, | ||
98 | }; | ||
99 | bdrv_inc_in_flight(bs); | ||
100 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
101 | assert(data.done); | ||
83 | } | 102 | } |
84 | 103 | ||
85 | void blk_io_limits_update_group(BlockBackend *blk, const char *group) | 104 | -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) |
86 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | 105 | +static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, |
87 | index XXXXXXX..XXXXXXX 100644 | 106 | + BdrvChild *parent) |
88 | --- a/block/throttle-groups.c | ||
89 | +++ b/block/throttle-groups.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) | ||
91 | |||
92 | static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write) | ||
93 | { | 107 | { |
94 | - BlockBackendPublic *blkp = container_of(tgm, BlockBackendPublic, | 108 | + BdrvChild *child, *next; |
95 | - throttle_group_member); | 109 | + |
96 | - BlockBackend *blk = blk_by_public(blkp); | 110 | if (qemu_in_coroutine()) { |
97 | Coroutine *co; | 111 | - bdrv_co_yield_to_drain(bs, true, parent); |
98 | RestartData rd = { | 112 | + bdrv_co_yield_to_drain(bs, true, recursive, parent); |
99 | .tgm = tgm, | 113 | return; |
100 | @@ -XXX,XX +XXX,XX @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write | 114 | } |
101 | }; | 115 | |
102 | 116 | @@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) | |
103 | co = qemu_coroutine_create(throttle_group_restart_queue_entry, &rd); | 117 | bdrv_parent_drained_begin(bs, parent); |
104 | - aio_co_enter(blk_get_aio_context(blk), co); | 118 | bdrv_drain_invoke(bs, true, false); |
105 | + aio_co_enter(tgm->aio_context, co); | 119 | bdrv_drain_recurse(bs); |
120 | + | ||
121 | + if (recursive) { | ||
122 | + QLIST_FOREACH_SAFE(child, &bs->children, next, next) { | ||
123 | + bdrv_do_drained_begin(child->bs, true, child); | ||
124 | + } | ||
125 | + } | ||
106 | } | 126 | } |
107 | 127 | ||
108 | void throttle_group_restart_tgm(ThrottleGroupMember *tgm) | 128 | void bdrv_drained_begin(BlockDriverState *bs) |
109 | @@ -XXX,XX +XXX,XX @@ void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) | ||
110 | /* ThrottleTimers callback. This wakes up a request that was waiting | ||
111 | * because it had been throttled. | ||
112 | * | ||
113 | - * @blk: the BlockBackend whose request had been throttled | ||
114 | + * @tgm: the ThrottleGroupMember whose request had been throttled | ||
115 | * @is_write: the type of operation (read/write) | ||
116 | */ | ||
117 | -static void timer_cb(BlockBackend *blk, bool is_write) | ||
118 | +static void timer_cb(ThrottleGroupMember *tgm, bool is_write) | ||
119 | { | 129 | { |
120 | - BlockBackendPublic *blkp = blk_get_public(blk); | 130 | - bdrv_do_drained_begin(bs, NULL); |
121 | - ThrottleGroupMember *tgm = &blkp->throttle_group_member; | 131 | + bdrv_do_drained_begin(bs, false, NULL); |
122 | ThrottleState *ts = tgm->throttle_state; | ||
123 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
124 | |||
125 | @@ -XXX,XX +XXX,XX @@ static void write_timer_cb(void *opaque) | ||
126 | * | ||
127 | * @tgm: the ThrottleGroupMember to insert | ||
128 | * @groupname: the name of the group | ||
129 | + * @ctx: the AioContext to use | ||
130 | */ | ||
131 | void throttle_group_register_tgm(ThrottleGroupMember *tgm, | ||
132 | - const char *groupname) | ||
133 | + const char *groupname, | ||
134 | + AioContext *ctx) | ||
135 | { | ||
136 | int i; | ||
137 | - BlockBackendPublic *blkp = container_of(tgm, BlockBackendPublic, | ||
138 | - throttle_group_member); | ||
139 | - BlockBackend *blk = blk_by_public(blkp); | ||
140 | ThrottleState *ts = throttle_group_incref(groupname); | ||
141 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
142 | |||
143 | tgm->throttle_state = ts; | ||
144 | + tgm->aio_context = ctx; | ||
145 | |||
146 | qemu_mutex_lock(&tg->lock); | ||
147 | /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */ | ||
148 | @@ -XXX,XX +XXX,XX @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm, | ||
149 | QLIST_INSERT_HEAD(&tg->head, tgm, round_robin); | ||
150 | |||
151 | throttle_timers_init(&tgm->throttle_timers, | ||
152 | - blk_get_aio_context(blk), | ||
153 | + tgm->aio_context, | ||
154 | tg->clock_type, | ||
155 | read_timer_cb, | ||
156 | write_timer_cb, | ||
157 | - blk); | ||
158 | + tgm); | ||
159 | |||
160 | qemu_mutex_unlock(&tg->lock); | ||
161 | } | ||
162 | @@ -XXX,XX +XXX,XX @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) | ||
163 | tgm->throttle_state = NULL; | ||
164 | } | ||
165 | |||
166 | +void throttle_group_attach_aio_context(ThrottleGroupMember *tgm, | ||
167 | + AioContext *new_context) | ||
168 | +{ | ||
169 | + ThrottleTimers *tt = &tgm->throttle_timers; | ||
170 | + throttle_timers_attach_aio_context(tt, new_context); | ||
171 | + tgm->aio_context = new_context; | ||
172 | +} | 132 | +} |
173 | + | 133 | + |
174 | +void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) | 134 | +void bdrv_subtree_drained_begin(BlockDriverState *bs) |
175 | +{ | 135 | +{ |
176 | + ThrottleTimers *tt = &tgm->throttle_timers; | 136 | + bdrv_do_drained_begin(bs, true, NULL); |
177 | + throttle_timers_detach_aio_context(tt); | 137 | } |
178 | + tgm->aio_context = NULL; | 138 | |
139 | -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) | ||
140 | +static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, | ||
141 | + BdrvChild *parent) | ||
142 | { | ||
143 | + BdrvChild *child, *next; | ||
144 | int old_quiesce_counter; | ||
145 | |||
146 | if (qemu_in_coroutine()) { | ||
147 | - bdrv_co_yield_to_drain(bs, false, parent); | ||
148 | + bdrv_co_yield_to_drain(bs, false, recursive, parent); | ||
149 | return; | ||
150 | } | ||
151 | assert(bs->quiesce_counter > 0); | ||
152 | @@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) | ||
153 | if (old_quiesce_counter == 1) { | ||
154 | aio_enable_external(bdrv_get_aio_context(bs)); | ||
155 | } | ||
156 | + | ||
157 | + if (recursive) { | ||
158 | + QLIST_FOREACH_SAFE(child, &bs->children, next, next) { | ||
159 | + bdrv_do_drained_end(child->bs, true, child); | ||
160 | + } | ||
161 | + } | ||
162 | } | ||
163 | |||
164 | void bdrv_drained_end(BlockDriverState *bs) | ||
165 | { | ||
166 | - bdrv_do_drained_end(bs, NULL); | ||
167 | + bdrv_do_drained_end(bs, false, NULL); | ||
179 | +} | 168 | +} |
180 | + | 169 | + |
181 | static void throttle_groups_init(void) | 170 | +void bdrv_subtree_drained_end(BlockDriverState *bs) |
182 | { | 171 | +{ |
183 | qemu_mutex_init(&throttle_groups_lock); | 172 | + bdrv_do_drained_end(bs, true, NULL); |
184 | diff --git a/tests/test-throttle.c b/tests/test-throttle.c | ||
185 | index XXXXXXX..XXXXXXX 100644 | ||
186 | --- a/tests/test-throttle.c | ||
187 | +++ b/tests/test-throttle.c | ||
188 | @@ -XXX,XX +XXX,XX @@ | ||
189 | static AioContext *ctx; | ||
190 | static LeakyBucket bkt; | ||
191 | static ThrottleConfig cfg; | ||
192 | +static ThrottleGroupMember tgm; | ||
193 | static ThrottleState ts; | ||
194 | -static ThrottleTimers tt; | ||
195 | +static ThrottleTimers *tt; | ||
196 | |||
197 | /* useful function */ | ||
198 | static bool double_cmp(double x, double y) | ||
199 | @@ -XXX,XX +XXX,XX @@ static void test_init(void) | ||
200 | { | ||
201 | int i; | ||
202 | |||
203 | + tt = &tgm.throttle_timers; | ||
204 | + | ||
205 | /* fill the structures with crap */ | ||
206 | memset(&ts, 1, sizeof(ts)); | ||
207 | - memset(&tt, 1, sizeof(tt)); | ||
208 | + memset(tt, 1, sizeof(*tt)); | ||
209 | |||
210 | /* init structures */ | ||
211 | throttle_init(&ts); | ||
212 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
213 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
214 | read_timer_cb, write_timer_cb, &ts); | ||
215 | |||
216 | /* check initialized fields */ | ||
217 | - g_assert(tt.clock_type == QEMU_CLOCK_VIRTUAL); | ||
218 | - g_assert(tt.timers[0]); | ||
219 | - g_assert(tt.timers[1]); | ||
220 | + g_assert(tt->clock_type == QEMU_CLOCK_VIRTUAL); | ||
221 | + g_assert(tt->timers[0]); | ||
222 | + g_assert(tt->timers[1]); | ||
223 | |||
224 | /* check other fields where cleared */ | ||
225 | g_assert(!ts.previous_leak); | ||
226 | @@ -XXX,XX +XXX,XX @@ static void test_init(void) | ||
227 | g_assert(!ts.cfg.buckets[i].level); | ||
228 | } | ||
229 | |||
230 | - throttle_timers_destroy(&tt); | ||
231 | + throttle_timers_destroy(tt); | ||
232 | } | 173 | } |
233 | 174 | ||
234 | static void test_destroy(void) | 175 | /* |
235 | { | ||
236 | int i; | ||
237 | throttle_init(&ts); | ||
238 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
239 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
240 | read_timer_cb, write_timer_cb, &ts); | ||
241 | - throttle_timers_destroy(&tt); | ||
242 | + throttle_timers_destroy(tt); | ||
243 | for (i = 0; i < 2; i++) { | ||
244 | - g_assert(!tt.timers[i]); | ||
245 | + g_assert(!tt->timers[i]); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | @@ -XXX,XX +XXX,XX @@ static void test_config_functions(void) | ||
250 | orig_cfg.op_size = 1; | ||
251 | |||
252 | throttle_init(&ts); | ||
253 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
254 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
255 | read_timer_cb, write_timer_cb, &ts); | ||
256 | /* structure reset by throttle_init previous_leak should be null */ | ||
257 | g_assert(!ts.previous_leak); | ||
258 | @@ -XXX,XX +XXX,XX @@ static void test_config_functions(void) | ||
259 | /* get back the fixed configuration */ | ||
260 | throttle_get_config(&ts, &final_cfg); | ||
261 | |||
262 | - throttle_timers_destroy(&tt); | ||
263 | + throttle_timers_destroy(tt); | ||
264 | |||
265 | g_assert(final_cfg.buckets[THROTTLE_BPS_TOTAL].avg == 153); | ||
266 | g_assert(final_cfg.buckets[THROTTLE_BPS_READ].avg == 56); | ||
267 | @@ -XXX,XX +XXX,XX @@ static void test_have_timer(void) | ||
268 | { | ||
269 | /* zero structures */ | ||
270 | memset(&ts, 0, sizeof(ts)); | ||
271 | - memset(&tt, 0, sizeof(tt)); | ||
272 | + memset(tt, 0, sizeof(*tt)); | ||
273 | |||
274 | /* no timer set should return false */ | ||
275 | - g_assert(!throttle_timers_are_initialized(&tt)); | ||
276 | + g_assert(!throttle_timers_are_initialized(tt)); | ||
277 | |||
278 | /* init structures */ | ||
279 | throttle_init(&ts); | ||
280 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
281 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
282 | read_timer_cb, write_timer_cb, &ts); | ||
283 | |||
284 | /* timer set by init should return true */ | ||
285 | - g_assert(throttle_timers_are_initialized(&tt)); | ||
286 | + g_assert(throttle_timers_are_initialized(tt)); | ||
287 | |||
288 | - throttle_timers_destroy(&tt); | ||
289 | + throttle_timers_destroy(tt); | ||
290 | } | ||
291 | |||
292 | static void test_detach_attach(void) | ||
293 | { | ||
294 | /* zero structures */ | ||
295 | memset(&ts, 0, sizeof(ts)); | ||
296 | - memset(&tt, 0, sizeof(tt)); | ||
297 | + memset(tt, 0, sizeof(*tt)); | ||
298 | |||
299 | /* init the structure */ | ||
300 | throttle_init(&ts); | ||
301 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
302 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
303 | read_timer_cb, write_timer_cb, &ts); | ||
304 | |||
305 | /* timer set by init should return true */ | ||
306 | - g_assert(throttle_timers_are_initialized(&tt)); | ||
307 | + g_assert(throttle_timers_are_initialized(tt)); | ||
308 | |||
309 | /* timer should no longer exist after detaching */ | ||
310 | - throttle_timers_detach_aio_context(&tt); | ||
311 | - g_assert(!throttle_timers_are_initialized(&tt)); | ||
312 | + throttle_timers_detach_aio_context(tt); | ||
313 | + g_assert(!throttle_timers_are_initialized(tt)); | ||
314 | |||
315 | /* timer should exist again after attaching */ | ||
316 | - throttle_timers_attach_aio_context(&tt, ctx); | ||
317 | - g_assert(throttle_timers_are_initialized(&tt)); | ||
318 | + throttle_timers_attach_aio_context(tt, ctx); | ||
319 | + g_assert(throttle_timers_are_initialized(tt)); | ||
320 | |||
321 | - throttle_timers_destroy(&tt); | ||
322 | + throttle_timers_destroy(tt); | ||
323 | } | ||
324 | |||
325 | static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */ | ||
326 | @@ -XXX,XX +XXX,XX @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */ | ||
327 | cfg.op_size = op_size; | ||
328 | |||
329 | throttle_init(&ts); | ||
330 | - throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
331 | + throttle_timers_init(tt, ctx, QEMU_CLOCK_VIRTUAL, | ||
332 | read_timer_cb, write_timer_cb, &ts); | ||
333 | throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg); | ||
334 | |||
335 | @@ -XXX,XX +XXX,XX @@ static bool do_test_accounting(bool is_ops, /* are we testing bps or ops */ | ||
336 | return false; | ||
337 | } | ||
338 | |||
339 | - throttle_timers_destroy(&tt); | ||
340 | + throttle_timers_destroy(tt); | ||
341 | |||
342 | return true; | ||
343 | } | ||
344 | @@ -XXX,XX +XXX,XX @@ static void test_groups(void) | ||
345 | g_assert(tgm2->throttle_state == NULL); | ||
346 | g_assert(tgm3->throttle_state == NULL); | ||
347 | |||
348 | - throttle_group_register_tgm(tgm1, "bar"); | ||
349 | - throttle_group_register_tgm(tgm2, "foo"); | ||
350 | - throttle_group_register_tgm(tgm3, "bar"); | ||
351 | + throttle_group_register_tgm(tgm1, "bar", blk_get_aio_context(blk1)); | ||
352 | + throttle_group_register_tgm(tgm2, "foo", blk_get_aio_context(blk2)); | ||
353 | + throttle_group_register_tgm(tgm3, "bar", blk_get_aio_context(blk3)); | ||
354 | |||
355 | g_assert(tgm1->throttle_state != NULL); | ||
356 | g_assert(tgm2->throttle_state != NULL); | ||
357 | -- | 176 | -- |
358 | 2.13.5 | 177 | 2.13.6 |
359 | 178 | ||
360 | 179 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | Add a subtree drain version to the existing test cases. |
---|---|---|---|
2 | 2 | ||
3 | This commit eliminates the 1:1 relationship between BlockBackend and | ||
4 | throttle group state. Users will be able to create multiple throttle | ||
5 | nodes, each with its own throttle group state, in the future. The | ||
6 | throttle group state cannot be per-BlockBackend anymore, it must be | ||
7 | per-throttle node. This is done by gathering ThrottleGroup membership | ||
8 | details from BlockBackendPublic into ThrottleGroupMember and refactoring | ||
9 | existing code to use the structure. | ||
10 | |||
11 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
15 | --- | 4 | --- |
16 | include/block/throttle-groups.h | 39 +++++- | 5 | tests/test-bdrv-drain.c | 27 ++++++++++++++++++++++++++- |
17 | include/sysemu/block-backend.h | 20 +-- | 6 | 1 file changed, 26 insertions(+), 1 deletion(-) |
18 | block/block-backend.c | 66 +++++---- | ||
19 | block/qapi.c | 8 +- | ||
20 | block/throttle-groups.c | 288 ++++++++++++++++++++-------------------- | ||
21 | blockdev.c | 4 +- | ||
22 | tests/test-throttle.c | 53 ++++---- | ||
23 | 7 files changed, 252 insertions(+), 226 deletions(-) | ||
24 | 7 | ||
25 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | 8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
26 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/block/throttle-groups.h | 10 | --- a/tests/test-bdrv-drain.c |
28 | +++ b/include/block/throttle-groups.h | 11 | +++ b/tests/test-bdrv-drain.c |
29 | @@ -XXX,XX +XXX,XX @@ | 12 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
30 | #include "qemu/throttle.h" | 13 | enum drain_type { |
31 | #include "block/block_int.h" | 14 | BDRV_DRAIN_ALL, |
32 | 15 | BDRV_DRAIN, | |
33 | -const char *throttle_group_get_name(BlockBackend *blk); | 16 | + BDRV_SUBTREE_DRAIN, |
34 | +/* The ThrottleGroupMember structure indicates membership in a ThrottleGroup | 17 | DRAIN_TYPE_MAX, |
35 | + * and holds related data. | 18 | }; |
36 | + */ | 19 | |
37 | + | 20 | @@ -XXX,XX +XXX,XX @@ static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs) |
38 | +typedef struct ThrottleGroupMember { | 21 | switch (drain_type) { |
39 | + /* throttled_reqs_lock protects the CoQueues for throttled requests. */ | 22 | case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; |
40 | + CoMutex throttled_reqs_lock; | 23 | case BDRV_DRAIN: bdrv_drained_begin(bs); break; |
41 | + CoQueue throttled_reqs[2]; | 24 | + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_begin(bs); break; |
42 | + | 25 | default: g_assert_not_reached(); |
43 | + /* Nonzero if the I/O limits are currently being ignored; generally | ||
44 | + * it is zero. Accessed with atomic operations. | ||
45 | + */ | ||
46 | + unsigned int io_limits_disabled; | ||
47 | + | ||
48 | + /* The following fields are protected by the ThrottleGroup lock. | ||
49 | + * See the ThrottleGroup documentation for details. | ||
50 | + * throttle_state tells us if I/O limits are configured. */ | ||
51 | + ThrottleState *throttle_state; | ||
52 | + ThrottleTimers throttle_timers; | ||
53 | + unsigned pending_reqs[2]; | ||
54 | + QLIST_ENTRY(ThrottleGroupMember) round_robin; | ||
55 | + | ||
56 | +} ThrottleGroupMember; | ||
57 | + | ||
58 | +const char *throttle_group_get_name(ThrottleGroupMember *tgm); | ||
59 | |||
60 | ThrottleState *throttle_group_incref(const char *name); | ||
61 | void throttle_group_unref(ThrottleState *ts); | ||
62 | |||
63 | -void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg); | ||
64 | -void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg); | ||
65 | +void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg); | ||
66 | +void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg); | ||
67 | |||
68 | -void throttle_group_register_blk(BlockBackend *blk, const char *groupname); | ||
69 | -void throttle_group_unregister_blk(BlockBackend *blk); | ||
70 | -void throttle_group_restart_blk(BlockBackend *blk); | ||
71 | +void throttle_group_register_tgm(ThrottleGroupMember *tgm, | ||
72 | + const char *groupname); | ||
73 | +void throttle_group_unregister_tgm(ThrottleGroupMember *tgm); | ||
74 | +void throttle_group_restart_tgm(ThrottleGroupMember *tgm); | ||
75 | |||
76 | -void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, | ||
77 | +void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm, | ||
78 | unsigned int bytes, | ||
79 | bool is_write); | ||
80 | |||
81 | diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/include/sysemu/block-backend.h | ||
84 | +++ b/include/sysemu/block-backend.h | ||
85 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockDevOps { | ||
86 | |||
87 | /* This struct is embedded in (the private) BlockBackend struct and contains | ||
88 | * fields that must be public. This is in particular for QLIST_ENTRY() and | ||
89 | - * friends so that BlockBackends can be kept in lists outside block-backend.c */ | ||
90 | + * friends so that BlockBackends can be kept in lists outside block-backend.c | ||
91 | + * */ | ||
92 | typedef struct BlockBackendPublic { | ||
93 | - /* throttled_reqs_lock protects the CoQueues for throttled requests. */ | ||
94 | - CoMutex throttled_reqs_lock; | ||
95 | - CoQueue throttled_reqs[2]; | ||
96 | - | ||
97 | - /* Nonzero if the I/O limits are currently being ignored; generally | ||
98 | - * it is zero. Accessed with atomic operations. | ||
99 | - */ | ||
100 | - unsigned int io_limits_disabled; | ||
101 | - | ||
102 | - /* The following fields are protected by the ThrottleGroup lock. | ||
103 | - * See the ThrottleGroup documentation for details. | ||
104 | - * throttle_state tells us if I/O limits are configured. */ | ||
105 | - ThrottleState *throttle_state; | ||
106 | - ThrottleTimers throttle_timers; | ||
107 | - unsigned pending_reqs[2]; | ||
108 | - QLIST_ENTRY(BlockBackendPublic) round_robin; | ||
109 | + ThrottleGroupMember throttle_group_member; | ||
110 | } BlockBackendPublic; | ||
111 | |||
112 | BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm); | ||
113 | diff --git a/block/block-backend.c b/block/block-backend.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/block/block-backend.c | ||
116 | +++ b/block/block-backend.c | ||
117 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) | ||
118 | blk->shared_perm = shared_perm; | ||
119 | blk_set_enable_write_cache(blk, true); | ||
120 | |||
121 | - qemu_co_mutex_init(&blk->public.throttled_reqs_lock); | ||
122 | - qemu_co_queue_init(&blk->public.throttled_reqs[0]); | ||
123 | - qemu_co_queue_init(&blk->public.throttled_reqs[1]); | ||
124 | + qemu_co_mutex_init(&blk->public.throttle_group_member.throttled_reqs_lock); | ||
125 | + qemu_co_queue_init(&blk->public.throttle_group_member.throttled_reqs[0]); | ||
126 | + qemu_co_queue_init(&blk->public.throttle_group_member.throttled_reqs[1]); | ||
127 | block_acct_init(&blk->stats); | ||
128 | |||
129 | notifier_list_init(&blk->remove_bs_notifiers); | ||
130 | @@ -XXX,XX +XXX,XX @@ static void blk_delete(BlockBackend *blk) | ||
131 | assert(!blk->refcnt); | ||
132 | assert(!blk->name); | ||
133 | assert(!blk->dev); | ||
134 | - if (blk->public.throttle_state) { | ||
135 | + if (blk->public.throttle_group_member.throttle_state) { | ||
136 | blk_io_limits_disable(blk); | ||
137 | } | ||
138 | if (blk->root) { | ||
139 | @@ -XXX,XX +XXX,XX @@ BlockBackend *blk_by_public(BlockBackendPublic *public) | ||
140 | */ | ||
141 | void blk_remove_bs(BlockBackend *blk) | ||
142 | { | ||
143 | + ThrottleTimers *tt; | ||
144 | + | ||
145 | notifier_list_notify(&blk->remove_bs_notifiers, blk); | ||
146 | - if (blk->public.throttle_state) { | ||
147 | - throttle_timers_detach_aio_context(&blk->public.throttle_timers); | ||
148 | + if (blk->public.throttle_group_member.throttle_state) { | ||
149 | + tt = &blk->public.throttle_group_member.throttle_timers; | ||
150 | + throttle_timers_detach_aio_context(tt); | ||
151 | } | ||
152 | |||
153 | blk_update_root_state(blk); | ||
154 | @@ -XXX,XX +XXX,XX @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) | ||
155 | bdrv_ref(bs); | ||
156 | |||
157 | notifier_list_notify(&blk->insert_bs_notifiers, blk); | ||
158 | - if (blk->public.throttle_state) { | ||
159 | + if (blk->public.throttle_group_member.throttle_state) { | ||
160 | throttle_timers_attach_aio_context( | ||
161 | - &blk->public.throttle_timers, bdrv_get_aio_context(bs)); | ||
162 | + &blk->public.throttle_group_member.throttle_timers, | ||
163 | + bdrv_get_aio_context(bs)); | ||
164 | } | ||
165 | |||
166 | return 0; | ||
167 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, | ||
168 | bdrv_inc_in_flight(bs); | ||
169 | |||
170 | /* throttling disk I/O */ | ||
171 | - if (blk->public.throttle_state) { | ||
172 | - throttle_group_co_io_limits_intercept(blk, bytes, false); | ||
173 | + if (blk->public.throttle_group_member.throttle_state) { | ||
174 | + throttle_group_co_io_limits_intercept(&blk->public.throttle_group_member, | ||
175 | + bytes, false); | ||
176 | } | ||
177 | |||
178 | ret = bdrv_co_preadv(blk->root, offset, bytes, qiov, flags); | ||
179 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, | ||
180 | } | ||
181 | |||
182 | bdrv_inc_in_flight(bs); | ||
183 | - | ||
184 | /* throttling disk I/O */ | ||
185 | - if (blk->public.throttle_state) { | ||
186 | - throttle_group_co_io_limits_intercept(blk, bytes, true); | ||
187 | + if (blk->public.throttle_group_member.throttle_state) { | ||
188 | + throttle_group_co_io_limits_intercept(&blk->public.throttle_group_member, | ||
189 | + bytes, true); | ||
190 | } | ||
191 | |||
192 | if (!blk->enable_write_cache) { | ||
193 | @@ -XXX,XX +XXX,XX @@ static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb) | ||
194 | void blk_set_aio_context(BlockBackend *blk, AioContext *new_context) | ||
195 | { | ||
196 | BlockDriverState *bs = blk_bs(blk); | ||
197 | + ThrottleTimers *tt; | ||
198 | |||
199 | if (bs) { | ||
200 | - if (blk->public.throttle_state) { | ||
201 | - throttle_timers_detach_aio_context(&blk->public.throttle_timers); | ||
202 | + if (blk->public.throttle_group_member.throttle_state) { | ||
203 | + tt = &blk->public.throttle_group_member.throttle_timers; | ||
204 | + throttle_timers_detach_aio_context(tt); | ||
205 | } | ||
206 | bdrv_set_aio_context(bs, new_context); | ||
207 | - if (blk->public.throttle_state) { | ||
208 | - throttle_timers_attach_aio_context(&blk->public.throttle_timers, | ||
209 | - new_context); | ||
210 | + if (blk->public.throttle_group_member.throttle_state) { | ||
211 | + tt = &blk->public.throttle_group_member.throttle_timers; | ||
212 | + throttle_timers_attach_aio_context(tt, new_context); | ||
213 | } | ||
214 | } | 26 | } |
215 | } | 27 | } |
216 | @@ -XXX,XX +XXX,XX @@ int blk_commit_all(void) | 28 | @@ -XXX,XX +XXX,XX @@ static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs) |
217 | /* throttling disk I/O limits */ | 29 | switch (drain_type) { |
218 | void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg) | 30 | case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; |
219 | { | 31 | case BDRV_DRAIN: bdrv_drained_end(bs); break; |
220 | - throttle_group_config(blk, cfg); | 32 | + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_end(bs); break; |
221 | + throttle_group_config(&blk->public.throttle_group_member, cfg); | 33 | default: g_assert_not_reached(); |
222 | } | ||
223 | |||
224 | void blk_io_limits_disable(BlockBackend *blk) | ||
225 | { | ||
226 | - assert(blk->public.throttle_state); | ||
227 | + assert(blk->public.throttle_group_member.throttle_state); | ||
228 | bdrv_drained_begin(blk_bs(blk)); | ||
229 | - throttle_group_unregister_blk(blk); | ||
230 | + throttle_group_unregister_tgm(&blk->public.throttle_group_member); | ||
231 | bdrv_drained_end(blk_bs(blk)); | ||
232 | } | ||
233 | |||
234 | /* should be called before blk_set_io_limits if a limit is set */ | ||
235 | void blk_io_limits_enable(BlockBackend *blk, const char *group) | ||
236 | { | ||
237 | - assert(!blk->public.throttle_state); | ||
238 | - throttle_group_register_blk(blk, group); | ||
239 | + assert(!blk->public.throttle_group_member.throttle_state); | ||
240 | + throttle_group_register_tgm(&blk->public.throttle_group_member, group); | ||
241 | } | ||
242 | |||
243 | void blk_io_limits_update_group(BlockBackend *blk, const char *group) | ||
244 | { | ||
245 | /* this BB is not part of any group */ | ||
246 | - if (!blk->public.throttle_state) { | ||
247 | + if (!blk->public.throttle_group_member.throttle_state) { | ||
248 | return; | ||
249 | } | ||
250 | |||
251 | /* this BB is a part of the same group than the one we want */ | ||
252 | - if (!g_strcmp0(throttle_group_get_name(blk), group)) { | ||
253 | + if (!g_strcmp0(throttle_group_get_name(&blk->public.throttle_group_member), | ||
254 | + group)) { | ||
255 | return; | ||
256 | } | ||
257 | |||
258 | @@ -XXX,XX +XXX,XX @@ static void blk_root_drained_begin(BdrvChild *child) | ||
259 | /* Note that blk->root may not be accessible here yet if we are just | ||
260 | * attaching to a BlockDriverState that is drained. Use child instead. */ | ||
261 | |||
262 | - if (atomic_fetch_inc(&blk->public.io_limits_disabled) == 0) { | ||
263 | - throttle_group_restart_blk(blk); | ||
264 | + if (atomic_fetch_inc(&blk->public.throttle_group_member.io_limits_disabled) == 0) { | ||
265 | + throttle_group_restart_tgm(&blk->public.throttle_group_member); | ||
266 | } | 34 | } |
267 | } | 35 | } |
268 | 36 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void) | |
269 | @@ -XXX,XX +XXX,XX @@ static void blk_root_drained_end(BdrvChild *child) | 37 | test_drv_cb_common(BDRV_DRAIN, false); |
270 | BlockBackend *blk = child->opaque; | ||
271 | assert(blk->quiesce_counter); | ||
272 | |||
273 | - assert(blk->public.io_limits_disabled); | ||
274 | - atomic_dec(&blk->public.io_limits_disabled); | ||
275 | + assert(blk->public.throttle_group_member.io_limits_disabled); | ||
276 | + atomic_dec(&blk->public.throttle_group_member.io_limits_disabled); | ||
277 | |||
278 | if (--blk->quiesce_counter == 0) { | ||
279 | if (blk->dev_ops && blk->dev_ops->drained_end) { | ||
280 | diff --git a/block/qapi.c b/block/qapi.c | ||
281 | index XXXXXXX..XXXXXXX 100644 | ||
282 | --- a/block/qapi.c | ||
283 | +++ b/block/qapi.c | ||
284 | @@ -XXX,XX +XXX,XX @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, | ||
285 | |||
286 | info->detect_zeroes = bs->detect_zeroes; | ||
287 | |||
288 | - if (blk && blk_get_public(blk)->throttle_state) { | ||
289 | + if (blk && blk_get_public(blk)->throttle_group_member.throttle_state) { | ||
290 | ThrottleConfig cfg; | ||
291 | + BlockBackendPublic *blkp = blk_get_public(blk); | ||
292 | |||
293 | - throttle_group_get_config(blk, &cfg); | ||
294 | + throttle_group_get_config(&blkp->throttle_group_member, &cfg); | ||
295 | |||
296 | info->bps = cfg.buckets[THROTTLE_BPS_TOTAL].avg; | ||
297 | info->bps_rd = cfg.buckets[THROTTLE_BPS_READ].avg; | ||
298 | @@ -XXX,XX +XXX,XX @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, | ||
299 | info->iops_size = cfg.op_size; | ||
300 | |||
301 | info->has_group = true; | ||
302 | - info->group = g_strdup(throttle_group_get_name(blk)); | ||
303 | + info->group = | ||
304 | + g_strdup(throttle_group_get_name(&blkp->throttle_group_member)); | ||
305 | } | ||
306 | |||
307 | info->write_threshold = bdrv_write_threshold_get(bs); | ||
308 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | ||
309 | index XXXXXXX..XXXXXXX 100644 | ||
310 | --- a/block/throttle-groups.c | ||
311 | +++ b/block/throttle-groups.c | ||
312 | @@ -XXX,XX +XXX,XX @@ | ||
313 | #include "sysemu/qtest.h" | ||
314 | |||
315 | /* The ThrottleGroup structure (with its ThrottleState) is shared | ||
316 | - * among different BlockBackends and it's independent from | ||
317 | + * among different ThrottleGroupMembers and it's independent from | ||
318 | * AioContext, so in order to use it from different threads it needs | ||
319 | * its own locking. | ||
320 | * | ||
321 | @@ -XXX,XX +XXX,XX @@ | ||
322 | * The whole ThrottleGroup structure is private and invisible to | ||
323 | * outside users, that only use it through its ThrottleState. | ||
324 | * | ||
325 | - * In addition to the ThrottleGroup structure, BlockBackendPublic has | ||
326 | + * In addition to the ThrottleGroup structure, ThrottleGroupMember has | ||
327 | * fields that need to be accessed by other members of the group and | ||
328 | * therefore also need to be protected by this lock. Once a | ||
329 | - * BlockBackend is registered in a group those fields can be accessed | ||
330 | + * ThrottleGroupMember is registered in a group those fields can be accessed | ||
331 | * by other threads any time. | ||
332 | * | ||
333 | * Again, all this is handled internally and is mostly transparent to | ||
334 | * the outside. The 'throttle_timers' field however has an additional | ||
335 | * constraint because it may be temporarily invalid (see for example | ||
336 | * blk_set_aio_context()). Therefore in this file a thread will | ||
337 | - * access some other BlockBackend's timers only after verifying that | ||
338 | - * that BlockBackend has throttled requests in the queue. | ||
339 | + * access some other ThrottleGroupMember's timers only after verifying that | ||
340 | + * that ThrottleGroupMember has throttled requests in the queue. | ||
341 | */ | ||
342 | typedef struct ThrottleGroup { | ||
343 | char *name; /* This is constant during the lifetime of the group */ | ||
344 | |||
345 | QemuMutex lock; /* This lock protects the following four fields */ | ||
346 | ThrottleState ts; | ||
347 | - QLIST_HEAD(, BlockBackendPublic) head; | ||
348 | - BlockBackend *tokens[2]; | ||
349 | + QLIST_HEAD(, ThrottleGroupMember) head; | ||
350 | + ThrottleGroupMember *tokens[2]; | ||
351 | bool any_timer_armed[2]; | ||
352 | QEMUClockType clock_type; | ||
353 | |||
354 | @@ -XXX,XX +XXX,XX @@ void throttle_group_unref(ThrottleState *ts) | ||
355 | qemu_mutex_unlock(&throttle_groups_lock); | ||
356 | } | 38 | } |
357 | 39 | ||
358 | -/* Get the name from a BlockBackend's ThrottleGroup. The name (and the pointer) | 40 | +static void test_drv_cb_drain_subtree(void) |
359 | +/* Get the name from a ThrottleGroupMember's group. The name (and the pointer) | 41 | +{ |
360 | * is guaranteed to remain constant during the lifetime of the group. | 42 | + test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); |
361 | * | 43 | +} |
362 | - * @blk: a BlockBackend that is member of a throttling group | 44 | + |
363 | + * @tgm: a ThrottleGroupMember | 45 | static void test_quiesce_common(enum drain_type drain_type, bool recursive) |
364 | * @ret: the name of the group. | ||
365 | */ | ||
366 | -const char *throttle_group_get_name(BlockBackend *blk) | ||
367 | +const char *throttle_group_get_name(ThrottleGroupMember *tgm) | ||
368 | { | 46 | { |
369 | - BlockBackendPublic *blkp = blk_get_public(blk); | 47 | BlockBackend *blk; |
370 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | 48 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void) |
371 | + ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts); | 49 | test_quiesce_common(BDRV_DRAIN, false); |
372 | return tg->name; | ||
373 | } | 50 | } |
374 | 51 | ||
375 | -/* Return the next BlockBackend in the round-robin sequence, simulating a | 52 | +static void test_quiesce_drain_subtree(void) |
376 | - * circular list. | 53 | +{ |
377 | +/* Return the next ThrottleGroupMember in the round-robin sequence, simulating | 54 | + test_quiesce_common(BDRV_SUBTREE_DRAIN, true); |
378 | + * a circular list. | 55 | +} |
379 | * | 56 | + |
380 | * This assumes that tg->lock is held. | 57 | static void test_nested(void) |
381 | * | ||
382 | - * @blk: the current BlockBackend | ||
383 | - * @ret: the next BlockBackend in the sequence | ||
384 | + * @tgm: the current ThrottleGroupMember | ||
385 | + * @ret: the next ThrottleGroupMember in the sequence | ||
386 | */ | ||
387 | -static BlockBackend *throttle_group_next_blk(BlockBackend *blk) | ||
388 | +static ThrottleGroupMember *throttle_group_next_tgm(ThrottleGroupMember *tgm) | ||
389 | { | 58 | { |
390 | - BlockBackendPublic *blkp = blk_get_public(blk); | 59 | BlockBackend *blk; |
391 | - ThrottleState *ts = blkp->throttle_state; | 60 | @@ -XXX,XX +XXX,XX @@ static void test_nested(void) |
392 | + ThrottleState *ts = tgm->throttle_state; | 61 | /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ |
393 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | 62 | int bs_quiesce = (outer != BDRV_DRAIN_ALL) + |
394 | - BlockBackendPublic *next = QLIST_NEXT(blkp, round_robin); | 63 | (inner != BDRV_DRAIN_ALL); |
395 | + ThrottleGroupMember *next = QLIST_NEXT(tgm, round_robin); | 64 | - int backing_quiesce = 0; |
396 | 65 | + int backing_quiesce = (outer == BDRV_SUBTREE_DRAIN) + | |
397 | if (!next) { | 66 | + (inner == BDRV_SUBTREE_DRAIN); |
398 | next = QLIST_FIRST(&tg->head); | 67 | int backing_cb_cnt = (outer != BDRV_DRAIN) + |
399 | } | 68 | (inner != BDRV_DRAIN); |
400 | 69 | ||
401 | - return blk_by_public(next); | 70 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_drain(void) |
402 | + return next; | 71 | test_blockjob_common(BDRV_DRAIN); |
403 | } | 72 | } |
404 | 73 | ||
405 | /* | 74 | +static void test_blockjob_drain_subtree(void) |
406 | - * Return whether a BlockBackend has pending requests. | 75 | +{ |
407 | + * Return whether a ThrottleGroupMember has pending requests. | 76 | + test_blockjob_common(BDRV_SUBTREE_DRAIN); |
408 | * | 77 | +} |
409 | * This assumes that tg->lock is held. | 78 | + |
410 | * | 79 | int main(int argc, char **argv) |
411 | - * @blk: the BlockBackend | ||
412 | - * @is_write: the type of operation (read/write) | ||
413 | - * @ret: whether the BlockBackend has pending requests. | ||
414 | + * @tgm: the ThrottleGroupMember | ||
415 | + * @is_write: the type of operation (read/write) | ||
416 | + * @ret: whether the ThrottleGroupMember has pending requests. | ||
417 | */ | ||
418 | -static inline bool blk_has_pending_reqs(BlockBackend *blk, | ||
419 | +static inline bool tgm_has_pending_reqs(ThrottleGroupMember *tgm, | ||
420 | bool is_write) | ||
421 | { | 80 | { |
422 | - const BlockBackendPublic *blkp = blk_get_public(blk); | 81 | bdrv_init(); |
423 | - return blkp->pending_reqs[is_write]; | 82 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
424 | + return tgm->pending_reqs[is_write]; | 83 | |
84 | g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all); | ||
85 | g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); | ||
86 | + g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", | ||
87 | + test_drv_cb_drain_subtree); | ||
88 | |||
89 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); | ||
90 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); | ||
91 | + g_test_add_func("/bdrv-drain/quiesce/drain_subtree", | ||
92 | + test_quiesce_drain_subtree); | ||
93 | |||
94 | g_test_add_func("/bdrv-drain/nested", test_nested); | ||
95 | |||
96 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); | ||
97 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | ||
98 | + g_test_add_func("/bdrv-drain/blockjob/drain_subtree", | ||
99 | + test_blockjob_drain_subtree); | ||
100 | |||
101 | return g_test_run(); | ||
425 | } | 102 | } |
426 | |||
427 | -/* Return the next BlockBackend in the round-robin sequence with pending I/O | ||
428 | - * requests. | ||
429 | +/* Return the next ThrottleGroupMember in the round-robin sequence with pending | ||
430 | + * I/O requests. | ||
431 | * | ||
432 | * This assumes that tg->lock is held. | ||
433 | * | ||
434 | - * @blk: the current BlockBackend | ||
435 | + * @tgm: the current ThrottleGroupMember | ||
436 | * @is_write: the type of operation (read/write) | ||
437 | - * @ret: the next BlockBackend with pending requests, or blk if there is | ||
438 | - * none. | ||
439 | + * @ret: the next ThrottleGroupMember with pending requests, or tgm if | ||
440 | + * there is none. | ||
441 | */ | ||
442 | -static BlockBackend *next_throttle_token(BlockBackend *blk, bool is_write) | ||
443 | +static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm, | ||
444 | + bool is_write) | ||
445 | { | ||
446 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
447 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | ||
448 | - BlockBackend *token, *start; | ||
449 | + ThrottleState *ts = tgm->throttle_state; | ||
450 | + ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
451 | + ThrottleGroupMember *token, *start; | ||
452 | |||
453 | start = token = tg->tokens[is_write]; | ||
454 | |||
455 | /* get next bs round in round robin style */ | ||
456 | - token = throttle_group_next_blk(token); | ||
457 | - while (token != start && !blk_has_pending_reqs(token, is_write)) { | ||
458 | - token = throttle_group_next_blk(token); | ||
459 | + token = throttle_group_next_tgm(token); | ||
460 | + while (token != start && !tgm_has_pending_reqs(token, is_write)) { | ||
461 | + token = throttle_group_next_tgm(token); | ||
462 | } | ||
463 | |||
464 | /* If no IO are queued for scheduling on the next round robin token | ||
465 | - * then decide the token is the current bs because chances are | ||
466 | - * the current bs get the current request queued. | ||
467 | + * then decide the token is the current tgm because chances are | ||
468 | + * the current tgm got the current request queued. | ||
469 | */ | ||
470 | - if (token == start && !blk_has_pending_reqs(token, is_write)) { | ||
471 | - token = blk; | ||
472 | + if (token == start && !tgm_has_pending_reqs(token, is_write)) { | ||
473 | + token = tgm; | ||
474 | } | ||
475 | |||
476 | - /* Either we return the original BB, or one with pending requests */ | ||
477 | - assert(token == blk || blk_has_pending_reqs(token, is_write)); | ||
478 | + /* Either we return the original TGM, or one with pending requests */ | ||
479 | + assert(token == tgm || tgm_has_pending_reqs(token, is_write)); | ||
480 | |||
481 | return token; | ||
482 | } | ||
483 | |||
484 | -/* Check if the next I/O request for a BlockBackend needs to be throttled or | ||
485 | - * not. If there's no timer set in this group, set one and update the token | ||
486 | - * accordingly. | ||
487 | +/* Check if the next I/O request for a ThrottleGroupMember needs to be | ||
488 | + * throttled or not. If there's no timer set in this group, set one and update | ||
489 | + * the token accordingly. | ||
490 | * | ||
491 | * This assumes that tg->lock is held. | ||
492 | * | ||
493 | - * @blk: the current BlockBackend | ||
494 | + * @tgm: the current ThrottleGroupMember | ||
495 | * @is_write: the type of operation (read/write) | ||
496 | * @ret: whether the I/O request needs to be throttled or not | ||
497 | */ | ||
498 | -static bool throttle_group_schedule_timer(BlockBackend *blk, bool is_write) | ||
499 | +static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm, | ||
500 | + bool is_write) | ||
501 | { | ||
502 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
503 | - ThrottleState *ts = blkp->throttle_state; | ||
504 | - ThrottleTimers *tt = &blkp->throttle_timers; | ||
505 | + ThrottleState *ts = tgm->throttle_state; | ||
506 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
507 | + ThrottleTimers *tt = &tgm->throttle_timers; | ||
508 | bool must_wait; | ||
509 | |||
510 | - if (atomic_read(&blkp->io_limits_disabled)) { | ||
511 | + if (atomic_read(&tgm->io_limits_disabled)) { | ||
512 | return false; | ||
513 | } | ||
514 | |||
515 | @@ -XXX,XX +XXX,XX @@ static bool throttle_group_schedule_timer(BlockBackend *blk, bool is_write) | ||
516 | |||
517 | must_wait = throttle_schedule_timer(ts, tt, is_write); | ||
518 | |||
519 | - /* If a timer just got armed, set blk as the current token */ | ||
520 | + /* If a timer just got armed, set tgm as the current token */ | ||
521 | if (must_wait) { | ||
522 | - tg->tokens[is_write] = blk; | ||
523 | + tg->tokens[is_write] = tgm; | ||
524 | tg->any_timer_armed[is_write] = true; | ||
525 | } | ||
526 | |||
527 | return must_wait; | ||
528 | } | ||
529 | |||
530 | -/* Start the next pending I/O request for a BlockBackend. Return whether | ||
531 | +/* Start the next pending I/O request for a ThrottleGroupMember. Return whether | ||
532 | * any request was actually pending. | ||
533 | * | ||
534 | - * @blk: the current BlockBackend | ||
535 | + * @tgm: the current ThrottleGroupMember | ||
536 | * @is_write: the type of operation (read/write) | ||
537 | */ | ||
538 | -static bool coroutine_fn throttle_group_co_restart_queue(BlockBackend *blk, | ||
539 | +static bool coroutine_fn throttle_group_co_restart_queue(ThrottleGroupMember *tgm, | ||
540 | bool is_write) | ||
541 | { | ||
542 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
543 | bool ret; | ||
544 | |||
545 | - qemu_co_mutex_lock(&blkp->throttled_reqs_lock); | ||
546 | - ret = qemu_co_queue_next(&blkp->throttled_reqs[is_write]); | ||
547 | - qemu_co_mutex_unlock(&blkp->throttled_reqs_lock); | ||
548 | + qemu_co_mutex_lock(&tgm->throttled_reqs_lock); | ||
549 | + ret = qemu_co_queue_next(&tgm->throttled_reqs[is_write]); | ||
550 | + qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); | ||
551 | |||
552 | return ret; | ||
553 | } | ||
554 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn throttle_group_co_restart_queue(BlockBackend *blk, | ||
555 | * | ||
556 | * This assumes that tg->lock is held. | ||
557 | * | ||
558 | - * @blk: the current BlockBackend | ||
559 | + * @tgm: the current ThrottleGroupMember | ||
560 | * @is_write: the type of operation (read/write) | ||
561 | */ | ||
562 | -static void schedule_next_request(BlockBackend *blk, bool is_write) | ||
563 | +static void schedule_next_request(ThrottleGroupMember *tgm, bool is_write) | ||
564 | { | ||
565 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
566 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | ||
567 | + ThrottleState *ts = tgm->throttle_state; | ||
568 | + ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
569 | bool must_wait; | ||
570 | - BlockBackend *token; | ||
571 | + ThrottleGroupMember *token; | ||
572 | |||
573 | /* Check if there's any pending request to schedule next */ | ||
574 | - token = next_throttle_token(blk, is_write); | ||
575 | - if (!blk_has_pending_reqs(token, is_write)) { | ||
576 | + token = next_throttle_token(tgm, is_write); | ||
577 | + if (!tgm_has_pending_reqs(token, is_write)) { | ||
578 | return; | ||
579 | } | ||
580 | |||
581 | @@ -XXX,XX +XXX,XX @@ static void schedule_next_request(BlockBackend *blk, bool is_write) | ||
582 | |||
583 | /* If it doesn't have to wait, queue it for immediate execution */ | ||
584 | if (!must_wait) { | ||
585 | - /* Give preference to requests from the current blk */ | ||
586 | + /* Give preference to requests from the current tgm */ | ||
587 | if (qemu_in_coroutine() && | ||
588 | - throttle_group_co_restart_queue(blk, is_write)) { | ||
589 | - token = blk; | ||
590 | + throttle_group_co_restart_queue(tgm, is_write)) { | ||
591 | + token = tgm; | ||
592 | } else { | ||
593 | - ThrottleTimers *tt = &blk_get_public(token)->throttle_timers; | ||
594 | + ThrottleTimers *tt = &token->throttle_timers; | ||
595 | int64_t now = qemu_clock_get_ns(tg->clock_type); | ||
596 | timer_mod(tt->timers[is_write], now); | ||
597 | tg->any_timer_armed[is_write] = true; | ||
598 | @@ -XXX,XX +XXX,XX @@ static void schedule_next_request(BlockBackend *blk, bool is_write) | ||
599 | * if necessary, and schedule the next request using a round robin | ||
600 | * algorithm. | ||
601 | * | ||
602 | - * @blk: the current BlockBackend | ||
603 | + * @tgm: the current ThrottleGroupMember | ||
604 | * @bytes: the number of bytes for this I/O | ||
605 | * @is_write: the type of operation (read/write) | ||
606 | */ | ||
607 | -void coroutine_fn throttle_group_co_io_limits_intercept(BlockBackend *blk, | ||
608 | +void coroutine_fn throttle_group_co_io_limits_intercept(ThrottleGroupMember *tgm, | ||
609 | unsigned int bytes, | ||
610 | bool is_write) | ||
611 | { | ||
612 | bool must_wait; | ||
613 | - BlockBackend *token; | ||
614 | - | ||
615 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
616 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | ||
617 | + ThrottleGroupMember *token; | ||
618 | + ThrottleGroup *tg = container_of(tgm->throttle_state, ThrottleGroup, ts); | ||
619 | qemu_mutex_lock(&tg->lock); | ||
620 | |||
621 | /* First we check if this I/O has to be throttled. */ | ||
622 | - token = next_throttle_token(blk, is_write); | ||
623 | + token = next_throttle_token(tgm, is_write); | ||
624 | must_wait = throttle_group_schedule_timer(token, is_write); | ||
625 | |||
626 | /* Wait if there's a timer set or queued requests of this type */ | ||
627 | - if (must_wait || blkp->pending_reqs[is_write]) { | ||
628 | - blkp->pending_reqs[is_write]++; | ||
629 | + if (must_wait || tgm->pending_reqs[is_write]) { | ||
630 | + tgm->pending_reqs[is_write]++; | ||
631 | qemu_mutex_unlock(&tg->lock); | ||
632 | - qemu_co_mutex_lock(&blkp->throttled_reqs_lock); | ||
633 | - qemu_co_queue_wait(&blkp->throttled_reqs[is_write], | ||
634 | - &blkp->throttled_reqs_lock); | ||
635 | - qemu_co_mutex_unlock(&blkp->throttled_reqs_lock); | ||
636 | + qemu_co_mutex_lock(&tgm->throttled_reqs_lock); | ||
637 | + qemu_co_queue_wait(&tgm->throttled_reqs[is_write], | ||
638 | + &tgm->throttled_reqs_lock); | ||
639 | + qemu_co_mutex_unlock(&tgm->throttled_reqs_lock); | ||
640 | qemu_mutex_lock(&tg->lock); | ||
641 | - blkp->pending_reqs[is_write]--; | ||
642 | + tgm->pending_reqs[is_write]--; | ||
643 | } | ||
644 | |||
645 | /* The I/O will be executed, so do the accounting */ | ||
646 | - throttle_account(blkp->throttle_state, is_write, bytes); | ||
647 | + throttle_account(tgm->throttle_state, is_write, bytes); | ||
648 | |||
649 | /* Schedule the next request */ | ||
650 | - schedule_next_request(blk, is_write); | ||
651 | + schedule_next_request(tgm, is_write); | ||
652 | |||
653 | qemu_mutex_unlock(&tg->lock); | ||
654 | } | ||
655 | |||
656 | typedef struct { | ||
657 | - BlockBackend *blk; | ||
658 | + ThrottleGroupMember *tgm; | ||
659 | bool is_write; | ||
660 | } RestartData; | ||
661 | |||
662 | static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) | ||
663 | { | ||
664 | RestartData *data = opaque; | ||
665 | - BlockBackend *blk = data->blk; | ||
666 | + ThrottleGroupMember *tgm = data->tgm; | ||
667 | + ThrottleState *ts = tgm->throttle_state; | ||
668 | + ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
669 | bool is_write = data->is_write; | ||
670 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
671 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | ||
672 | bool empty_queue; | ||
673 | |||
674 | - empty_queue = !throttle_group_co_restart_queue(blk, is_write); | ||
675 | + empty_queue = !throttle_group_co_restart_queue(tgm, is_write); | ||
676 | |||
677 | /* If the request queue was empty then we have to take care of | ||
678 | * scheduling the next one */ | ||
679 | if (empty_queue) { | ||
680 | qemu_mutex_lock(&tg->lock); | ||
681 | - schedule_next_request(blk, is_write); | ||
682 | + schedule_next_request(tgm, is_write); | ||
683 | qemu_mutex_unlock(&tg->lock); | ||
684 | } | ||
685 | } | ||
686 | |||
687 | -static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) | ||
688 | +static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write) | ||
689 | { | ||
690 | + BlockBackendPublic *blkp = container_of(tgm, BlockBackendPublic, | ||
691 | + throttle_group_member); | ||
692 | + BlockBackend *blk = blk_by_public(blkp); | ||
693 | Coroutine *co; | ||
694 | RestartData rd = { | ||
695 | - .blk = blk, | ||
696 | + .tgm = tgm, | ||
697 | .is_write = is_write | ||
698 | }; | ||
699 | |||
700 | @@ -XXX,XX +XXX,XX @@ static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) | ||
701 | aio_co_enter(blk_get_aio_context(blk), co); | ||
702 | } | ||
703 | |||
704 | -void throttle_group_restart_blk(BlockBackend *blk) | ||
705 | +void throttle_group_restart_tgm(ThrottleGroupMember *tgm) | ||
706 | { | ||
707 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
708 | - | ||
709 | - if (blkp->throttle_state) { | ||
710 | - throttle_group_restart_queue(blk, 0); | ||
711 | - throttle_group_restart_queue(blk, 1); | ||
712 | + if (tgm->throttle_state) { | ||
713 | + throttle_group_restart_queue(tgm, 0); | ||
714 | + throttle_group_restart_queue(tgm, 1); | ||
715 | } | ||
716 | } | ||
717 | |||
718 | @@ -XXX,XX +XXX,XX @@ void throttle_group_restart_blk(BlockBackend *blk) | ||
719 | * to throttle_config(), but guarantees atomicity within the | ||
720 | * throttling group. | ||
721 | * | ||
722 | - * @blk: a BlockBackend that is a member of the group | ||
723 | + * @tgm: a ThrottleGroupMember that is a member of the group | ||
724 | * @cfg: the configuration to set | ||
725 | */ | ||
726 | -void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg) | ||
727 | +void throttle_group_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) | ||
728 | { | ||
729 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
730 | - ThrottleState *ts = blkp->throttle_state; | ||
731 | + ThrottleState *ts = tgm->throttle_state; | ||
732 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
733 | qemu_mutex_lock(&tg->lock); | ||
734 | throttle_config(ts, tg->clock_type, cfg); | ||
735 | qemu_mutex_unlock(&tg->lock); | ||
736 | |||
737 | - throttle_group_restart_blk(blk); | ||
738 | + throttle_group_restart_tgm(tgm); | ||
739 | } | ||
740 | |||
741 | /* Get the throttle configuration from a particular group. Similar to | ||
742 | * throttle_get_config(), but guarantees atomicity within the | ||
743 | * throttling group. | ||
744 | * | ||
745 | - * @blk: a BlockBackend that is a member of the group | ||
746 | + * @tgm: a ThrottleGroupMember that is a member of the group | ||
747 | * @cfg: the configuration will be written here | ||
748 | */ | ||
749 | -void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg) | ||
750 | +void throttle_group_get_config(ThrottleGroupMember *tgm, ThrottleConfig *cfg) | ||
751 | { | ||
752 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
753 | - ThrottleState *ts = blkp->throttle_state; | ||
754 | + ThrottleState *ts = tgm->throttle_state; | ||
755 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
756 | qemu_mutex_lock(&tg->lock); | ||
757 | throttle_get_config(ts, cfg); | ||
758 | @@ -XXX,XX +XXX,XX @@ void throttle_group_get_config(BlockBackend *blk, ThrottleConfig *cfg) | ||
759 | static void timer_cb(BlockBackend *blk, bool is_write) | ||
760 | { | ||
761 | BlockBackendPublic *blkp = blk_get_public(blk); | ||
762 | - ThrottleState *ts = blkp->throttle_state; | ||
763 | + ThrottleGroupMember *tgm = &blkp->throttle_group_member; | ||
764 | + ThrottleState *ts = tgm->throttle_state; | ||
765 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
766 | |||
767 | /* The timer has just been fired, so we can update the flag */ | ||
768 | @@ -XXX,XX +XXX,XX @@ static void timer_cb(BlockBackend *blk, bool is_write) | ||
769 | qemu_mutex_unlock(&tg->lock); | ||
770 | |||
771 | /* Run the request that was waiting for this timer */ | ||
772 | - throttle_group_restart_queue(blk, is_write); | ||
773 | + throttle_group_restart_queue(tgm, is_write); | ||
774 | } | ||
775 | |||
776 | static void read_timer_cb(void *opaque) | ||
777 | @@ -XXX,XX +XXX,XX @@ static void write_timer_cb(void *opaque) | ||
778 | timer_cb(opaque, true); | ||
779 | } | ||
780 | |||
781 | -/* Register a BlockBackend in the throttling group, also initializing its | ||
782 | - * timers and updating its throttle_state pointer to point to it. If a | ||
783 | +/* Register a ThrottleGroupMember from the throttling group, also initializing | ||
784 | + * its timers and updating its throttle_state pointer to point to it. If a | ||
785 | * throttling group with that name does not exist yet, it will be created. | ||
786 | * | ||
787 | - * @blk: the BlockBackend to insert | ||
788 | + * @tgm: the ThrottleGroupMember to insert | ||
789 | * @groupname: the name of the group | ||
790 | */ | ||
791 | -void throttle_group_register_blk(BlockBackend *blk, const char *groupname) | ||
792 | +void throttle_group_register_tgm(ThrottleGroupMember *tgm, | ||
793 | + const char *groupname) | ||
794 | { | ||
795 | int i; | ||
796 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
797 | + BlockBackendPublic *blkp = container_of(tgm, BlockBackendPublic, | ||
798 | + throttle_group_member); | ||
799 | + BlockBackend *blk = blk_by_public(blkp); | ||
800 | ThrottleState *ts = throttle_group_incref(groupname); | ||
801 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
802 | - blkp->throttle_state = ts; | ||
803 | + | ||
804 | + tgm->throttle_state = ts; | ||
805 | |||
806 | qemu_mutex_lock(&tg->lock); | ||
807 | - /* If the ThrottleGroup is new set this BlockBackend as the token */ | ||
808 | + /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */ | ||
809 | for (i = 0; i < 2; i++) { | ||
810 | if (!tg->tokens[i]) { | ||
811 | - tg->tokens[i] = blk; | ||
812 | + tg->tokens[i] = tgm; | ||
813 | } | ||
814 | } | ||
815 | |||
816 | - QLIST_INSERT_HEAD(&tg->head, blkp, round_robin); | ||
817 | + QLIST_INSERT_HEAD(&tg->head, tgm, round_robin); | ||
818 | |||
819 | - throttle_timers_init(&blkp->throttle_timers, | ||
820 | + throttle_timers_init(&tgm->throttle_timers, | ||
821 | blk_get_aio_context(blk), | ||
822 | tg->clock_type, | ||
823 | read_timer_cb, | ||
824 | @@ -XXX,XX +XXX,XX @@ void throttle_group_register_blk(BlockBackend *blk, const char *groupname) | ||
825 | qemu_mutex_unlock(&tg->lock); | ||
826 | } | ||
827 | |||
828 | -/* Unregister a BlockBackend from its group, removing it from the list, | ||
829 | +/* Unregister a ThrottleGroupMember from its group, removing it from the list, | ||
830 | * destroying the timers and setting the throttle_state pointer to NULL. | ||
831 | * | ||
832 | - * The BlockBackend must not have pending throttled requests, so the caller has | ||
833 | - * to drain them first. | ||
834 | + * The ThrottleGroupMember must not have pending throttled requests, so the | ||
835 | + * caller has to drain them first. | ||
836 | * | ||
837 | * The group will be destroyed if it's empty after this operation. | ||
838 | * | ||
839 | - * @blk: the BlockBackend to remove | ||
840 | + * @tgm the ThrottleGroupMember to remove | ||
841 | */ | ||
842 | -void throttle_group_unregister_blk(BlockBackend *blk) | ||
843 | +void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) | ||
844 | { | ||
845 | - BlockBackendPublic *blkp = blk_get_public(blk); | ||
846 | - ThrottleGroup *tg = container_of(blkp->throttle_state, ThrottleGroup, ts); | ||
847 | + ThrottleState *ts = tgm->throttle_state; | ||
848 | + ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
849 | + ThrottleGroupMember *token; | ||
850 | int i; | ||
851 | |||
852 | - assert(blkp->pending_reqs[0] == 0 && blkp->pending_reqs[1] == 0); | ||
853 | - assert(qemu_co_queue_empty(&blkp->throttled_reqs[0])); | ||
854 | - assert(qemu_co_queue_empty(&blkp->throttled_reqs[1])); | ||
855 | + assert(tgm->pending_reqs[0] == 0 && tgm->pending_reqs[1] == 0); | ||
856 | + assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); | ||
857 | + assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); | ||
858 | |||
859 | qemu_mutex_lock(&tg->lock); | ||
860 | for (i = 0; i < 2; i++) { | ||
861 | - if (tg->tokens[i] == blk) { | ||
862 | - BlockBackend *token = throttle_group_next_blk(blk); | ||
863 | - /* Take care of the case where this is the last blk in the group */ | ||
864 | - if (token == blk) { | ||
865 | + if (tg->tokens[i] == tgm) { | ||
866 | + token = throttle_group_next_tgm(tgm); | ||
867 | + /* Take care of the case where this is the last tgm in the group */ | ||
868 | + if (token == tgm) { | ||
869 | token = NULL; | ||
870 | } | ||
871 | tg->tokens[i] = token; | ||
872 | } | ||
873 | } | ||
874 | |||
875 | - /* remove the current blk from the list */ | ||
876 | - QLIST_REMOVE(blkp, round_robin); | ||
877 | - throttle_timers_destroy(&blkp->throttle_timers); | ||
878 | + /* remove the current tgm from the list */ | ||
879 | + QLIST_REMOVE(tgm, round_robin); | ||
880 | + throttle_timers_destroy(&tgm->throttle_timers); | ||
881 | qemu_mutex_unlock(&tg->lock); | ||
882 | |||
883 | throttle_group_unref(&tg->ts); | ||
884 | - blkp->throttle_state = NULL; | ||
885 | + tgm->throttle_state = NULL; | ||
886 | } | ||
887 | |||
888 | static void throttle_groups_init(void) | ||
889 | diff --git a/blockdev.c b/blockdev.c | ||
890 | index XXXXXXX..XXXXXXX 100644 | ||
891 | --- a/blockdev.c | ||
892 | +++ b/blockdev.c | ||
893 | @@ -XXX,XX +XXX,XX @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) | ||
894 | if (throttle_enabled(&cfg)) { | ||
895 | /* Enable I/O limits if they're not enabled yet, otherwise | ||
896 | * just update the throttling group. */ | ||
897 | - if (!blk_get_public(blk)->throttle_state) { | ||
898 | + if (!blk_get_public(blk)->throttle_group_member.throttle_state) { | ||
899 | blk_io_limits_enable(blk, | ||
900 | arg->has_group ? arg->group : | ||
901 | arg->has_device ? arg->device : | ||
902 | @@ -XXX,XX +XXX,XX @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp) | ||
903 | } | ||
904 | /* Set the new throttling configuration */ | ||
905 | blk_set_io_limits(blk, &cfg); | ||
906 | - } else if (blk_get_public(blk)->throttle_state) { | ||
907 | + } else if (blk_get_public(blk)->throttle_group_member.throttle_state) { | ||
908 | /* If all throttling settings are set to 0, disable I/O limits */ | ||
909 | blk_io_limits_disable(blk); | ||
910 | } | ||
911 | diff --git a/tests/test-throttle.c b/tests/test-throttle.c | ||
912 | index XXXXXXX..XXXXXXX 100644 | ||
913 | --- a/tests/test-throttle.c | ||
914 | +++ b/tests/test-throttle.c | ||
915 | @@ -XXX,XX +XXX,XX @@ static void test_groups(void) | ||
916 | ThrottleConfig cfg1, cfg2; | ||
917 | BlockBackend *blk1, *blk2, *blk3; | ||
918 | BlockBackendPublic *blkp1, *blkp2, *blkp3; | ||
919 | + ThrottleGroupMember *tgm1, *tgm2, *tgm3; | ||
920 | |||
921 | /* No actual I/O is performed on these devices */ | ||
922 | blk1 = blk_new(0, BLK_PERM_ALL); | ||
923 | @@ -XXX,XX +XXX,XX @@ static void test_groups(void) | ||
924 | blkp2 = blk_get_public(blk2); | ||
925 | blkp3 = blk_get_public(blk3); | ||
926 | |||
927 | - g_assert(blkp1->throttle_state == NULL); | ||
928 | - g_assert(blkp2->throttle_state == NULL); | ||
929 | - g_assert(blkp3->throttle_state == NULL); | ||
930 | + tgm1 = &blkp1->throttle_group_member; | ||
931 | + tgm2 = &blkp2->throttle_group_member; | ||
932 | + tgm3 = &blkp3->throttle_group_member; | ||
933 | |||
934 | - throttle_group_register_blk(blk1, "bar"); | ||
935 | - throttle_group_register_blk(blk2, "foo"); | ||
936 | - throttle_group_register_blk(blk3, "bar"); | ||
937 | + g_assert(tgm1->throttle_state == NULL); | ||
938 | + g_assert(tgm2->throttle_state == NULL); | ||
939 | + g_assert(tgm3->throttle_state == NULL); | ||
940 | |||
941 | - g_assert(blkp1->throttle_state != NULL); | ||
942 | - g_assert(blkp2->throttle_state != NULL); | ||
943 | - g_assert(blkp3->throttle_state != NULL); | ||
944 | + throttle_group_register_tgm(tgm1, "bar"); | ||
945 | + throttle_group_register_tgm(tgm2, "foo"); | ||
946 | + throttle_group_register_tgm(tgm3, "bar"); | ||
947 | |||
948 | - g_assert(!strcmp(throttle_group_get_name(blk1), "bar")); | ||
949 | - g_assert(!strcmp(throttle_group_get_name(blk2), "foo")); | ||
950 | - g_assert(blkp1->throttle_state == blkp3->throttle_state); | ||
951 | + g_assert(tgm1->throttle_state != NULL); | ||
952 | + g_assert(tgm2->throttle_state != NULL); | ||
953 | + g_assert(tgm3->throttle_state != NULL); | ||
954 | + | ||
955 | + g_assert(!strcmp(throttle_group_get_name(tgm1), "bar")); | ||
956 | + g_assert(!strcmp(throttle_group_get_name(tgm2), "foo")); | ||
957 | + g_assert(tgm1->throttle_state == tgm3->throttle_state); | ||
958 | |||
959 | /* Setting the config of a group member affects the whole group */ | ||
960 | throttle_config_init(&cfg1); | ||
961 | @@ -XXX,XX +XXX,XX @@ static void test_groups(void) | ||
962 | cfg1.buckets[THROTTLE_BPS_WRITE].avg = 285000; | ||
963 | cfg1.buckets[THROTTLE_OPS_READ].avg = 20000; | ||
964 | cfg1.buckets[THROTTLE_OPS_WRITE].avg = 12000; | ||
965 | - throttle_group_config(blk1, &cfg1); | ||
966 | + throttle_group_config(tgm1, &cfg1); | ||
967 | |||
968 | - throttle_group_get_config(blk1, &cfg1); | ||
969 | - throttle_group_get_config(blk3, &cfg2); | ||
970 | + throttle_group_get_config(tgm1, &cfg1); | ||
971 | + throttle_group_get_config(tgm3, &cfg2); | ||
972 | g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); | ||
973 | |||
974 | cfg2.buckets[THROTTLE_BPS_READ].avg = 4547; | ||
975 | cfg2.buckets[THROTTLE_BPS_WRITE].avg = 1349; | ||
976 | cfg2.buckets[THROTTLE_OPS_READ].avg = 123; | ||
977 | cfg2.buckets[THROTTLE_OPS_WRITE].avg = 86; | ||
978 | - throttle_group_config(blk3, &cfg1); | ||
979 | + throttle_group_config(tgm3, &cfg1); | ||
980 | |||
981 | - throttle_group_get_config(blk1, &cfg1); | ||
982 | - throttle_group_get_config(blk3, &cfg2); | ||
983 | + throttle_group_get_config(tgm1, &cfg1); | ||
984 | + throttle_group_get_config(tgm3, &cfg2); | ||
985 | g_assert(!memcmp(&cfg1, &cfg2, sizeof(cfg1))); | ||
986 | |||
987 | - throttle_group_unregister_blk(blk1); | ||
988 | - throttle_group_unregister_blk(blk2); | ||
989 | - throttle_group_unregister_blk(blk3); | ||
990 | + throttle_group_unregister_tgm(tgm1); | ||
991 | + throttle_group_unregister_tgm(tgm2); | ||
992 | + throttle_group_unregister_tgm(tgm3); | ||
993 | |||
994 | - g_assert(blkp1->throttle_state == NULL); | ||
995 | - g_assert(blkp2->throttle_state == NULL); | ||
996 | - g_assert(blkp3->throttle_state == NULL); | ||
997 | + g_assert(tgm1->throttle_state == NULL); | ||
998 | + g_assert(tgm2->throttle_state == NULL); | ||
999 | + g_assert(tgm3->throttle_state == NULL); | ||
1000 | } | ||
1001 | |||
1002 | int main(int argc, char **argv) | ||
1003 | -- | 103 | -- |
1004 | 2.13.5 | 104 | 2.13.6 |
1005 | 105 | ||
1006 | 106 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | If bdrv_do_drained_begin/end() are called in coroutine context, they |
---|---|---|---|
2 | first use a BH to get out of the coroutine context. Call some existing | ||
3 | tests again from a coroutine to cover this code path. | ||
2 | 4 | ||
3 | ThrottleGroup is converted to an object. This will allow the future | ||
4 | throttle block filter drive easy creation and configuration of throttle | ||
5 | groups in QMP and cli. | ||
6 | |||
7 | A new QAPI struct, ThrottleLimits, is introduced to provide a shared | ||
8 | struct for all throttle configuration needs in QMP. | ||
9 | |||
10 | ThrottleGroups can be created via CLI as | ||
11 | -object throttle-group,id=foo,x-iops-total=100,x-.. | ||
12 | where x-* are individual limit properties. Since we can't add non-scalar | ||
13 | properties in -object this interface must be used instead. However, | ||
14 | setting these properties must be disabled after initialization because | ||
15 | certain combinations of limits are forbidden and thus configuration | ||
16 | changes should be done in one transaction. The individual properties | ||
17 | will go away when support for non-scalar values in CLI is implemented | ||
18 | and thus are marked as experimental. | ||
19 | |||
20 | ThrottleGroup also has a `limits` property that uses the ThrottleLimits | ||
21 | struct. It can be used to create ThrottleGroups or set the | ||
22 | configuration in existing groups as follows: | ||
23 | |||
24 | { "execute": "object-add", | ||
25 | "arguments": { | ||
26 | "qom-type": "throttle-group", | ||
27 | "id": "foo", | ||
28 | "props" : { | ||
29 | "limits": { | ||
30 | "iops-total": 100 | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | { "execute" : "qom-set", | ||
36 | "arguments" : { | ||
37 | "path" : "foo", | ||
38 | "property" : "limits", | ||
39 | "value" : { | ||
40 | "iops-total" : 99 | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
45 | This also means a group's configuration can be fetched with qom-get. | ||
46 | |||
47 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
48 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
49 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
50 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
51 | --- | 6 | --- |
52 | qapi/block-core.json | 48 +++++ | 7 | tests/test-bdrv-drain.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ |
53 | include/block/throttle-groups.h | 3 + | 8 | 1 file changed, 59 insertions(+) |
54 | include/qemu/throttle-options.h | 59 ++++-- | ||
55 | include/qemu/throttle.h | 3 + | ||
56 | block/throttle-groups.c | 424 ++++++++++++++++++++++++++++++++++++---- | ||
57 | tests/test-throttle.c | 1 + | ||
58 | util/throttle.c | 151 ++++++++++++++ | ||
59 | 7 files changed, 628 insertions(+), 61 deletions(-) | ||
60 | 9 | ||
61 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 10 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
62 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
63 | --- a/qapi/block-core.json | 12 | --- a/tests/test-bdrv-drain.c |
64 | +++ b/qapi/block-core.json | 13 | +++ b/tests/test-bdrv-drain.c |
65 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
66 | '*iops_size': 'int', '*group': 'str' } } | 15 | *aio_ret = ret; |
67 | 16 | } | |
68 | ## | 17 | |
69 | +# @ThrottleLimits: | 18 | +typedef struct CallInCoroutineData { |
70 | +# | 19 | + void (*entry)(void); |
71 | +# Limit parameters for throttling. | 20 | + bool done; |
72 | +# Since some limit combinations are illegal, limits should always be set in one | 21 | +} CallInCoroutineData; |
73 | +# transaction. All fields are optional. When setting limits, if a field is | ||
74 | +# missing the current value is not changed. | ||
75 | +# | ||
76 | +# @iops-total: limit total I/O operations per second | ||
77 | +# @iops-total-max: I/O operations burst | ||
78 | +# @iops-total-max-length: length of the iops-total-max burst period, in seconds | ||
79 | +# It must only be set if @iops-total-max is set as well. | ||
80 | +# @iops-read: limit read operations per second | ||
81 | +# @iops-read-max: I/O operations read burst | ||
82 | +# @iops-read-max-length: length of the iops-read-max burst period, in seconds | ||
83 | +# It must only be set if @iops-read-max is set as well. | ||
84 | +# @iops-write: limit write operations per second | ||
85 | +# @iops-write-max: I/O operations write burst | ||
86 | +# @iops-write-max-length: length of the iops-write-max burst period, in seconds | ||
87 | +# It must only be set if @iops-write-max is set as well. | ||
88 | +# @bps-total: limit total bytes per second | ||
89 | +# @bps-total-max: total bytes burst | ||
90 | +# @bps-total-max-length: length of the bps-total-max burst period, in seconds. | ||
91 | +# It must only be set if @bps-total-max is set as well. | ||
92 | +# @bps-read: limit read bytes per second | ||
93 | +# @bps-read-max: total bytes read burst | ||
94 | +# @bps-read-max-length: length of the bps-read-max burst period, in seconds | ||
95 | +# It must only be set if @bps-read-max is set as well. | ||
96 | +# @bps-write: limit write bytes per second | ||
97 | +# @bps-write-max: total bytes write burst | ||
98 | +# @bps-write-max-length: length of the bps-write-max burst period, in seconds | ||
99 | +# It must only be set if @bps-write-max is set as well. | ||
100 | +# @iops-size: when limiting by iops max size of an I/O in bytes | ||
101 | +# | ||
102 | +# Since: 2.11 | ||
103 | +## | ||
104 | +{ 'struct': 'ThrottleLimits', | ||
105 | + 'data': { '*iops-total' : 'int', '*iops-total-max' : 'int', | ||
106 | + '*iops-total-max-length' : 'int', '*iops-read' : 'int', | ||
107 | + '*iops-read-max' : 'int', '*iops-read-max-length' : 'int', | ||
108 | + '*iops-write' : 'int', '*iops-write-max' : 'int', | ||
109 | + '*iops-write-max-length' : 'int', '*bps-total' : 'int', | ||
110 | + '*bps-total-max' : 'int', '*bps-total-max-length' : 'int', | ||
111 | + '*bps-read' : 'int', '*bps-read-max' : 'int', | ||
112 | + '*bps-read-max-length' : 'int', '*bps-write' : 'int', | ||
113 | + '*bps-write-max' : 'int', '*bps-write-max-length' : 'int', | ||
114 | + '*iops-size' : 'int' } } | ||
115 | + | 22 | + |
116 | +## | 23 | +static coroutine_fn void call_in_coroutine_entry(void *opaque) |
117 | # @block-stream: | 24 | +{ |
118 | # | 25 | + CallInCoroutineData *data = opaque; |
119 | # Copy data from a backing file into a block device. | ||
120 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/include/block/throttle-groups.h | ||
123 | +++ b/include/block/throttle-groups.h | ||
124 | @@ -XXX,XX +XXX,XX @@ typedef struct ThrottleGroupMember { | ||
125 | |||
126 | } ThrottleGroupMember; | ||
127 | |||
128 | +#define TYPE_THROTTLE_GROUP "throttle-group" | ||
129 | +#define THROTTLE_GROUP(obj) OBJECT_CHECK(ThrottleGroup, (obj), TYPE_THROTTLE_GROUP) | ||
130 | + | 26 | + |
131 | const char *throttle_group_get_name(ThrottleGroupMember *tgm); | 27 | + data->entry(); |
132 | 28 | + data->done = true; | |
133 | ThrottleState *throttle_group_incref(const char *name); | ||
134 | diff --git a/include/qemu/throttle-options.h b/include/qemu/throttle-options.h | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/include/qemu/throttle-options.h | ||
137 | +++ b/include/qemu/throttle-options.h | ||
138 | @@ -XXX,XX +XXX,XX @@ | ||
139 | #ifndef THROTTLE_OPTIONS_H | ||
140 | #define THROTTLE_OPTIONS_H | ||
141 | |||
142 | +#define QEMU_OPT_IOPS_TOTAL "iops-total" | ||
143 | +#define QEMU_OPT_IOPS_TOTAL_MAX "iops-total-max" | ||
144 | +#define QEMU_OPT_IOPS_TOTAL_MAX_LENGTH "iops-total-max-length" | ||
145 | +#define QEMU_OPT_IOPS_READ "iops-read" | ||
146 | +#define QEMU_OPT_IOPS_READ_MAX "iops-read-max" | ||
147 | +#define QEMU_OPT_IOPS_READ_MAX_LENGTH "iops-read-max-length" | ||
148 | +#define QEMU_OPT_IOPS_WRITE "iops-write" | ||
149 | +#define QEMU_OPT_IOPS_WRITE_MAX "iops-write-max" | ||
150 | +#define QEMU_OPT_IOPS_WRITE_MAX_LENGTH "iops-write-max-length" | ||
151 | +#define QEMU_OPT_BPS_TOTAL "bps-total" | ||
152 | +#define QEMU_OPT_BPS_TOTAL_MAX "bps-total-max" | ||
153 | +#define QEMU_OPT_BPS_TOTAL_MAX_LENGTH "bps-total-max-length" | ||
154 | +#define QEMU_OPT_BPS_READ "bps-read" | ||
155 | +#define QEMU_OPT_BPS_READ_MAX "bps-read-max" | ||
156 | +#define QEMU_OPT_BPS_READ_MAX_LENGTH "bps-read-max-length" | ||
157 | +#define QEMU_OPT_BPS_WRITE "bps-write" | ||
158 | +#define QEMU_OPT_BPS_WRITE_MAX "bps-write-max" | ||
159 | +#define QEMU_OPT_BPS_WRITE_MAX_LENGTH "bps-write-max-length" | ||
160 | +#define QEMU_OPT_IOPS_SIZE "iops-size" | ||
161 | + | ||
162 | +#define THROTTLE_OPT_PREFIX "throttling." | ||
163 | #define THROTTLE_OPTS \ | ||
164 | { \ | ||
165 | - .name = "throttling.iops-total",\ | ||
166 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL,\ | ||
167 | .type = QEMU_OPT_NUMBER,\ | ||
168 | .help = "limit total I/O operations per second",\ | ||
169 | },{ \ | ||
170 | - .name = "throttling.iops-read",\ | ||
171 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ,\ | ||
172 | .type = QEMU_OPT_NUMBER,\ | ||
173 | .help = "limit read operations per second",\ | ||
174 | },{ \ | ||
175 | - .name = "throttling.iops-write",\ | ||
176 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE,\ | ||
177 | .type = QEMU_OPT_NUMBER,\ | ||
178 | .help = "limit write operations per second",\ | ||
179 | },{ \ | ||
180 | - .name = "throttling.bps-total",\ | ||
181 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL,\ | ||
182 | .type = QEMU_OPT_NUMBER,\ | ||
183 | .help = "limit total bytes per second",\ | ||
184 | },{ \ | ||
185 | - .name = "throttling.bps-read",\ | ||
186 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ,\ | ||
187 | .type = QEMU_OPT_NUMBER,\ | ||
188 | .help = "limit read bytes per second",\ | ||
189 | },{ \ | ||
190 | - .name = "throttling.bps-write",\ | ||
191 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE,\ | ||
192 | .type = QEMU_OPT_NUMBER,\ | ||
193 | .help = "limit write bytes per second",\ | ||
194 | },{ \ | ||
195 | - .name = "throttling.iops-total-max",\ | ||
196 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX,\ | ||
197 | .type = QEMU_OPT_NUMBER,\ | ||
198 | .help = "I/O operations burst",\ | ||
199 | },{ \ | ||
200 | - .name = "throttling.iops-read-max",\ | ||
201 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX,\ | ||
202 | .type = QEMU_OPT_NUMBER,\ | ||
203 | .help = "I/O operations read burst",\ | ||
204 | },{ \ | ||
205 | - .name = "throttling.iops-write-max",\ | ||
206 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX,\ | ||
207 | .type = QEMU_OPT_NUMBER,\ | ||
208 | .help = "I/O operations write burst",\ | ||
209 | },{ \ | ||
210 | - .name = "throttling.bps-total-max",\ | ||
211 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX,\ | ||
212 | .type = QEMU_OPT_NUMBER,\ | ||
213 | .help = "total bytes burst",\ | ||
214 | },{ \ | ||
215 | - .name = "throttling.bps-read-max",\ | ||
216 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX,\ | ||
217 | .type = QEMU_OPT_NUMBER,\ | ||
218 | .help = "total bytes read burst",\ | ||
219 | },{ \ | ||
220 | - .name = "throttling.bps-write-max",\ | ||
221 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX,\ | ||
222 | .type = QEMU_OPT_NUMBER,\ | ||
223 | .help = "total bytes write burst",\ | ||
224 | },{ \ | ||
225 | - .name = "throttling.iops-total-max-length",\ | ||
226 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX_LENGTH,\ | ||
227 | .type = QEMU_OPT_NUMBER,\ | ||
228 | .help = "length of the iops-total-max burst period, in seconds",\ | ||
229 | },{ \ | ||
230 | - .name = "throttling.iops-read-max-length",\ | ||
231 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX_LENGTH,\ | ||
232 | .type = QEMU_OPT_NUMBER,\ | ||
233 | .help = "length of the iops-read-max burst period, in seconds",\ | ||
234 | },{ \ | ||
235 | - .name = "throttling.iops-write-max-length",\ | ||
236 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX_LENGTH,\ | ||
237 | .type = QEMU_OPT_NUMBER,\ | ||
238 | .help = "length of the iops-write-max burst period, in seconds",\ | ||
239 | },{ \ | ||
240 | - .name = "throttling.bps-total-max-length",\ | ||
241 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX_LENGTH,\ | ||
242 | .type = QEMU_OPT_NUMBER,\ | ||
243 | .help = "length of the bps-total-max burst period, in seconds",\ | ||
244 | },{ \ | ||
245 | - .name = "throttling.bps-read-max-length",\ | ||
246 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX_LENGTH,\ | ||
247 | .type = QEMU_OPT_NUMBER,\ | ||
248 | .help = "length of the bps-read-max burst period, in seconds",\ | ||
249 | },{ \ | ||
250 | - .name = "throttling.bps-write-max-length",\ | ||
251 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX_LENGTH,\ | ||
252 | .type = QEMU_OPT_NUMBER,\ | ||
253 | .help = "length of the bps-write-max burst period, in seconds",\ | ||
254 | },{ \ | ||
255 | - .name = "throttling.iops-size",\ | ||
256 | + .name = THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE,\ | ||
257 | .type = QEMU_OPT_NUMBER,\ | ||
258 | .help = "when limiting by iops max size of an I/O in bytes",\ | ||
259 | } | ||
260 | diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h | ||
261 | index XXXXXXX..XXXXXXX 100644 | ||
262 | --- a/include/qemu/throttle.h | ||
263 | +++ b/include/qemu/throttle.h | ||
264 | @@ -XXX,XX +XXX,XX @@ bool throttle_schedule_timer(ThrottleState *ts, | ||
265 | bool is_write); | ||
266 | |||
267 | void throttle_account(ThrottleState *ts, bool is_write, uint64_t size); | ||
268 | +void throttle_limits_to_config(ThrottleLimits *arg, ThrottleConfig *cfg, | ||
269 | + Error **errp); | ||
270 | +void throttle_config_to_limits(ThrottleConfig *cfg, ThrottleLimits *var); | ||
271 | |||
272 | #endif | ||
273 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | ||
274 | index XXXXXXX..XXXXXXX 100644 | ||
275 | --- a/block/throttle-groups.c | ||
276 | +++ b/block/throttle-groups.c | ||
277 | @@ -XXX,XX +XXX,XX @@ | ||
278 | #include "qemu/osdep.h" | ||
279 | #include "sysemu/block-backend.h" | ||
280 | #include "block/throttle-groups.h" | ||
281 | +#include "qemu/throttle-options.h" | ||
282 | #include "qemu/queue.h" | ||
283 | #include "qemu/thread.h" | ||
284 | #include "sysemu/qtest.h" | ||
285 | +#include "qapi/error.h" | ||
286 | +#include "qapi-visit.h" | ||
287 | +#include "qom/object.h" | ||
288 | +#include "qom/object_interfaces.h" | ||
289 | + | ||
290 | +static void throttle_group_obj_init(Object *obj); | ||
291 | +static void throttle_group_obj_complete(UserCreatable *obj, Error **errp); | ||
292 | |||
293 | /* The ThrottleGroup structure (with its ThrottleState) is shared | ||
294 | * among different ThrottleGroupMembers and it's independent from | ||
295 | @@ -XXX,XX +XXX,XX @@ | ||
296 | * that ThrottleGroupMember has throttled requests in the queue. | ||
297 | */ | ||
298 | typedef struct ThrottleGroup { | ||
299 | + Object parent_obj; | ||
300 | + | ||
301 | + /* refuse individual property change if initialization is complete */ | ||
302 | + bool is_initialized; | ||
303 | char *name; /* This is constant during the lifetime of the group */ | ||
304 | |||
305 | QemuMutex lock; /* This lock protects the following four fields */ | ||
306 | @@ -XXX,XX +XXX,XX @@ typedef struct ThrottleGroup { | ||
307 | bool any_timer_armed[2]; | ||
308 | QEMUClockType clock_type; | ||
309 | |||
310 | - /* These two are protected by the global throttle_groups_lock */ | ||
311 | - unsigned refcount; | ||
312 | + /* This field is protected by the global QEMU mutex */ | ||
313 | QTAILQ_ENTRY(ThrottleGroup) list; | ||
314 | } ThrottleGroup; | ||
315 | |||
316 | -static QemuMutex throttle_groups_lock; | ||
317 | +/* This is protected by the global QEMU mutex */ | ||
318 | static QTAILQ_HEAD(, ThrottleGroup) throttle_groups = | ||
319 | QTAILQ_HEAD_INITIALIZER(throttle_groups); | ||
320 | |||
321 | + | ||
322 | +/* This function reads throttle_groups and must be called under the global | ||
323 | + * mutex. | ||
324 | + */ | ||
325 | +static ThrottleGroup *throttle_group_by_name(const char *name) | ||
326 | +{ | ||
327 | + ThrottleGroup *iter; | ||
328 | + | ||
329 | + /* Look for an existing group with that name */ | ||
330 | + QTAILQ_FOREACH(iter, &throttle_groups, list) { | ||
331 | + if (!g_strcmp0(name, iter->name)) { | ||
332 | + return iter; | ||
333 | + } | ||
334 | + } | ||
335 | + | ||
336 | + return NULL; | ||
337 | +} | 29 | +} |
338 | + | 30 | + |
339 | /* Increments the reference count of a ThrottleGroup given its name. | 31 | +static void call_in_coroutine(void (*entry)(void)) |
340 | * | 32 | +{ |
341 | * If no ThrottleGroup is found with the given name a new one is | 33 | + Coroutine *co; |
342 | * created. | 34 | + CallInCoroutineData data = { |
343 | * | 35 | + .entry = entry, |
344 | + * This function edits throttle_groups and must be called under the global | 36 | + .done = false, |
345 | + * mutex. | 37 | + }; |
346 | + * | ||
347 | * @name: the name of the ThrottleGroup | ||
348 | * @ret: the ThrottleState member of the ThrottleGroup | ||
349 | */ | ||
350 | ThrottleState *throttle_group_incref(const char *name) | ||
351 | { | ||
352 | ThrottleGroup *tg = NULL; | ||
353 | - ThrottleGroup *iter; | ||
354 | - | ||
355 | - qemu_mutex_lock(&throttle_groups_lock); | ||
356 | |||
357 | /* Look for an existing group with that name */ | ||
358 | - QTAILQ_FOREACH(iter, &throttle_groups, list) { | ||
359 | - if (!strcmp(name, iter->name)) { | ||
360 | - tg = iter; | ||
361 | - break; | ||
362 | - } | ||
363 | - } | ||
364 | - | ||
365 | - /* Create a new one if not found */ | ||
366 | - if (!tg) { | ||
367 | - tg = g_new0(ThrottleGroup, 1); | ||
368 | + tg = throttle_group_by_name(name); | ||
369 | + | 38 | + |
370 | + if (tg) { | 39 | + co = qemu_coroutine_create(call_in_coroutine_entry, &data); |
371 | + object_ref(OBJECT(tg)); | 40 | + qemu_coroutine_enter(co); |
372 | + } else { | 41 | + while (!data.done) { |
373 | + /* Create a new one if not found */ | 42 | + aio_poll(qemu_get_aio_context(), true); |
374 | + /* new ThrottleGroup obj will have a refcnt = 1 */ | ||
375 | + tg = THROTTLE_GROUP(object_new(TYPE_THROTTLE_GROUP)); | ||
376 | tg->name = g_strdup(name); | ||
377 | - tg->clock_type = QEMU_CLOCK_REALTIME; | ||
378 | - | ||
379 | - if (qtest_enabled()) { | ||
380 | - /* For testing block IO throttling only */ | ||
381 | - tg->clock_type = QEMU_CLOCK_VIRTUAL; | ||
382 | - } | ||
383 | - qemu_mutex_init(&tg->lock); | ||
384 | - throttle_init(&tg->ts); | ||
385 | - QLIST_INIT(&tg->head); | ||
386 | - | ||
387 | - QTAILQ_INSERT_TAIL(&throttle_groups, tg, list); | ||
388 | + throttle_group_obj_complete(USER_CREATABLE(tg), &error_abort); | ||
389 | } | ||
390 | |||
391 | - tg->refcount++; | ||
392 | - | ||
393 | - qemu_mutex_unlock(&throttle_groups_lock); | ||
394 | - | ||
395 | return &tg->ts; | ||
396 | } | ||
397 | |||
398 | @@ -XXX,XX +XXX,XX @@ ThrottleState *throttle_group_incref(const char *name) | ||
399 | * When the reference count reaches zero the ThrottleGroup is | ||
400 | * destroyed. | ||
401 | * | ||
402 | + * This function edits throttle_groups and must be called under the global | ||
403 | + * mutex. | ||
404 | + * | ||
405 | * @ts: The ThrottleGroup to unref, given by its ThrottleState member | ||
406 | */ | ||
407 | void throttle_group_unref(ThrottleState *ts) | ||
408 | { | ||
409 | ThrottleGroup *tg = container_of(ts, ThrottleGroup, ts); | ||
410 | - | ||
411 | - qemu_mutex_lock(&throttle_groups_lock); | ||
412 | - if (--tg->refcount == 0) { | ||
413 | - QTAILQ_REMOVE(&throttle_groups, tg, list); | ||
414 | - qemu_mutex_destroy(&tg->lock); | ||
415 | - g_free(tg->name); | ||
416 | - g_free(tg); | ||
417 | - } | ||
418 | - qemu_mutex_unlock(&throttle_groups_lock); | ||
419 | + object_unref(OBJECT(tg)); | ||
420 | } | ||
421 | |||
422 | /* Get the name from a ThrottleGroupMember's group. The name (and the pointer) | ||
423 | @@ -XXX,XX +XXX,XX @@ static void write_timer_cb(void *opaque) | ||
424 | * its timers and updating its throttle_state pointer to point to it. If a | ||
425 | * throttling group with that name does not exist yet, it will be created. | ||
426 | * | ||
427 | + * This function edits throttle_groups and must be called under the global | ||
428 | + * mutex. | ||
429 | + * | ||
430 | * @tgm: the ThrottleGroupMember to insert | ||
431 | * @groupname: the name of the group | ||
432 | * @ctx: the AioContext to use | ||
433 | @@ -XXX,XX +XXX,XX @@ void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) | ||
434 | tgm->aio_context = NULL; | ||
435 | } | ||
436 | |||
437 | +#undef THROTTLE_OPT_PREFIX | ||
438 | +#define THROTTLE_OPT_PREFIX "x-" | ||
439 | + | ||
440 | +/* Helper struct and array for QOM property setter/getter */ | ||
441 | +typedef struct { | ||
442 | + const char *name; | ||
443 | + BucketType type; | ||
444 | + enum { | ||
445 | + AVG, | ||
446 | + MAX, | ||
447 | + BURST_LENGTH, | ||
448 | + IOPS_SIZE, | ||
449 | + } category; | ||
450 | +} ThrottleParamInfo; | ||
451 | + | ||
452 | +static ThrottleParamInfo properties[] = { | ||
453 | + { | ||
454 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL, | ||
455 | + THROTTLE_OPS_TOTAL, AVG, | ||
456 | + }, | ||
457 | + { | ||
458 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX, | ||
459 | + THROTTLE_OPS_TOTAL, MAX, | ||
460 | + }, | ||
461 | + { | ||
462 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_TOTAL_MAX_LENGTH, | ||
463 | + THROTTLE_OPS_TOTAL, BURST_LENGTH, | ||
464 | + }, | ||
465 | + { | ||
466 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ, | ||
467 | + THROTTLE_OPS_READ, AVG, | ||
468 | + }, | ||
469 | + { | ||
470 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX, | ||
471 | + THROTTLE_OPS_READ, MAX, | ||
472 | + }, | ||
473 | + { | ||
474 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_READ_MAX_LENGTH, | ||
475 | + THROTTLE_OPS_READ, BURST_LENGTH, | ||
476 | + }, | ||
477 | + { | ||
478 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE, | ||
479 | + THROTTLE_OPS_WRITE, AVG, | ||
480 | + }, | ||
481 | + { | ||
482 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX, | ||
483 | + THROTTLE_OPS_WRITE, MAX, | ||
484 | + }, | ||
485 | + { | ||
486 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_WRITE_MAX_LENGTH, | ||
487 | + THROTTLE_OPS_WRITE, BURST_LENGTH, | ||
488 | + }, | ||
489 | + { | ||
490 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL, | ||
491 | + THROTTLE_BPS_TOTAL, AVG, | ||
492 | + }, | ||
493 | + { | ||
494 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX, | ||
495 | + THROTTLE_BPS_TOTAL, MAX, | ||
496 | + }, | ||
497 | + { | ||
498 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_TOTAL_MAX_LENGTH, | ||
499 | + THROTTLE_BPS_TOTAL, BURST_LENGTH, | ||
500 | + }, | ||
501 | + { | ||
502 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ, | ||
503 | + THROTTLE_BPS_READ, AVG, | ||
504 | + }, | ||
505 | + { | ||
506 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX, | ||
507 | + THROTTLE_BPS_READ, MAX, | ||
508 | + }, | ||
509 | + { | ||
510 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_READ_MAX_LENGTH, | ||
511 | + THROTTLE_BPS_READ, BURST_LENGTH, | ||
512 | + }, | ||
513 | + { | ||
514 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE, | ||
515 | + THROTTLE_BPS_WRITE, AVG, | ||
516 | + }, | ||
517 | + { | ||
518 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX, | ||
519 | + THROTTLE_BPS_WRITE, MAX, | ||
520 | + }, | ||
521 | + { | ||
522 | + THROTTLE_OPT_PREFIX QEMU_OPT_BPS_WRITE_MAX_LENGTH, | ||
523 | + THROTTLE_BPS_WRITE, BURST_LENGTH, | ||
524 | + }, | ||
525 | + { | ||
526 | + THROTTLE_OPT_PREFIX QEMU_OPT_IOPS_SIZE, | ||
527 | + 0, IOPS_SIZE, | ||
528 | + } | 43 | + } |
529 | +}; | ||
530 | + | ||
531 | +/* This function edits throttle_groups and must be called under the global | ||
532 | + * mutex */ | ||
533 | +static void throttle_group_obj_init(Object *obj) | ||
534 | +{ | ||
535 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | ||
536 | + | ||
537 | + tg->clock_type = QEMU_CLOCK_REALTIME; | ||
538 | + if (qtest_enabled()) { | ||
539 | + /* For testing block IO throttling only */ | ||
540 | + tg->clock_type = QEMU_CLOCK_VIRTUAL; | ||
541 | + } | ||
542 | + tg->is_initialized = false; | ||
543 | + qemu_mutex_init(&tg->lock); | ||
544 | + throttle_init(&tg->ts); | ||
545 | + QLIST_INIT(&tg->head); | ||
546 | +} | 44 | +} |
547 | + | 45 | + |
548 | +/* This function edits throttle_groups and must be called under the global | 46 | enum drain_type { |
549 | + * mutex */ | 47 | BDRV_DRAIN_ALL, |
550 | +static void throttle_group_obj_complete(UserCreatable *obj, Error **errp) | 48 | BDRV_DRAIN, |
49 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_subtree(void) | ||
50 | test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); | ||
51 | } | ||
52 | |||
53 | +static void test_drv_cb_co_drain(void) | ||
551 | +{ | 54 | +{ |
552 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | 55 | + call_in_coroutine(test_drv_cb_drain); |
553 | + ThrottleConfig cfg; | ||
554 | + | ||
555 | + /* set group name to object id if it exists */ | ||
556 | + if (!tg->name && tg->parent_obj.parent) { | ||
557 | + tg->name = object_get_canonical_path_component(OBJECT(obj)); | ||
558 | + } | ||
559 | + /* We must have a group name at this point */ | ||
560 | + assert(tg->name); | ||
561 | + | ||
562 | + /* error if name is duplicate */ | ||
563 | + if (throttle_group_by_name(tg->name) != NULL) { | ||
564 | + error_setg(errp, "A group with this name already exists"); | ||
565 | + return; | ||
566 | + } | ||
567 | + | ||
568 | + /* check validity */ | ||
569 | + throttle_get_config(&tg->ts, &cfg); | ||
570 | + if (!throttle_is_valid(&cfg, errp)) { | ||
571 | + return; | ||
572 | + } | ||
573 | + throttle_config(&tg->ts, tg->clock_type, &cfg); | ||
574 | + QTAILQ_INSERT_TAIL(&throttle_groups, tg, list); | ||
575 | + tg->is_initialized = true; | ||
576 | +} | 56 | +} |
577 | + | 57 | + |
578 | +/* This function edits throttle_groups and must be called under the global | 58 | +static void test_drv_cb_co_drain_subtree(void) |
579 | + * mutex */ | ||
580 | +static void throttle_group_obj_finalize(Object *obj) | ||
581 | +{ | 59 | +{ |
582 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | 60 | + call_in_coroutine(test_drv_cb_drain_subtree); |
583 | + if (tg->is_initialized) { | ||
584 | + QTAILQ_REMOVE(&throttle_groups, tg, list); | ||
585 | + } | ||
586 | + qemu_mutex_destroy(&tg->lock); | ||
587 | + g_free(tg->name); | ||
588 | +} | 61 | +} |
589 | + | 62 | + |
590 | +static void throttle_group_set(Object *obj, Visitor *v, const char * name, | 63 | static void test_quiesce_common(enum drain_type drain_type, bool recursive) |
591 | + void *opaque, Error **errp) | 64 | { |
592 | + | 65 | BlockBackend *blk; |
66 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain_subtree(void) | ||
67 | test_quiesce_common(BDRV_SUBTREE_DRAIN, true); | ||
68 | } | ||
69 | |||
70 | +static void test_quiesce_co_drain(void) | ||
593 | +{ | 71 | +{ |
594 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | 72 | + call_in_coroutine(test_quiesce_drain); |
595 | + ThrottleConfig *cfg; | ||
596 | + ThrottleParamInfo *info = opaque; | ||
597 | + Error *local_err = NULL; | ||
598 | + int64_t value; | ||
599 | + | ||
600 | + /* If we have finished initialization, don't accept individual property | ||
601 | + * changes through QOM. Throttle configuration limits must be set in one | ||
602 | + * transaction, as certain combinations are invalid. | ||
603 | + */ | ||
604 | + if (tg->is_initialized) { | ||
605 | + error_setg(&local_err, "Property cannot be set after initialization"); | ||
606 | + goto ret; | ||
607 | + } | ||
608 | + | ||
609 | + visit_type_int64(v, name, &value, &local_err); | ||
610 | + if (local_err) { | ||
611 | + goto ret; | ||
612 | + } | ||
613 | + if (value < 0) { | ||
614 | + error_setg(&local_err, "Property values cannot be negative"); | ||
615 | + goto ret; | ||
616 | + } | ||
617 | + | ||
618 | + cfg = &tg->ts.cfg; | ||
619 | + switch (info->category) { | ||
620 | + case AVG: | ||
621 | + cfg->buckets[info->type].avg = value; | ||
622 | + break; | ||
623 | + case MAX: | ||
624 | + cfg->buckets[info->type].max = value; | ||
625 | + break; | ||
626 | + case BURST_LENGTH: | ||
627 | + if (value > UINT_MAX) { | ||
628 | + error_setg(&local_err, "%s value must be in the" | ||
629 | + "range [0, %u]", info->name, UINT_MAX); | ||
630 | + goto ret; | ||
631 | + } | ||
632 | + cfg->buckets[info->type].burst_length = value; | ||
633 | + break; | ||
634 | + case IOPS_SIZE: | ||
635 | + cfg->op_size = value; | ||
636 | + break; | ||
637 | + } | ||
638 | + | ||
639 | +ret: | ||
640 | + error_propagate(errp, local_err); | ||
641 | + return; | ||
642 | + | ||
643 | +} | 73 | +} |
644 | + | 74 | + |
645 | +static void throttle_group_get(Object *obj, Visitor *v, const char *name, | 75 | +static void test_quiesce_co_drain_subtree(void) |
646 | + void *opaque, Error **errp) | ||
647 | +{ | 76 | +{ |
648 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | 77 | + call_in_coroutine(test_quiesce_drain_subtree); |
649 | + ThrottleConfig cfg; | ||
650 | + ThrottleParamInfo *info = opaque; | ||
651 | + int64_t value; | ||
652 | + | ||
653 | + throttle_get_config(&tg->ts, &cfg); | ||
654 | + switch (info->category) { | ||
655 | + case AVG: | ||
656 | + value = cfg.buckets[info->type].avg; | ||
657 | + break; | ||
658 | + case MAX: | ||
659 | + value = cfg.buckets[info->type].max; | ||
660 | + break; | ||
661 | + case BURST_LENGTH: | ||
662 | + value = cfg.buckets[info->type].burst_length; | ||
663 | + break; | ||
664 | + case IOPS_SIZE: | ||
665 | + value = cfg.op_size; | ||
666 | + break; | ||
667 | + } | ||
668 | + | ||
669 | + visit_type_int64(v, name, &value, errp); | ||
670 | +} | 78 | +} |
671 | + | 79 | + |
672 | +static void throttle_group_set_limits(Object *obj, Visitor *v, | 80 | static void test_nested(void) |
673 | + const char *name, void *opaque, | 81 | { |
674 | + Error **errp) | 82 | BlockBackend *blk; |
83 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
84 | g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", | ||
85 | test_drv_cb_drain_subtree); | ||
86 | |||
87 | + // XXX bdrv_drain_all() doesn't work in coroutine context | ||
88 | + g_test_add_func("/bdrv-drain/driver-cb/co/drain", test_drv_cb_co_drain); | ||
89 | + g_test_add_func("/bdrv-drain/driver-cb/co/drain_subtree", | ||
90 | + test_drv_cb_co_drain_subtree); | ||
675 | + | 91 | + |
676 | +{ | ||
677 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | ||
678 | + ThrottleConfig cfg; | ||
679 | + ThrottleLimits arg = { 0 }; | ||
680 | + ThrottleLimits *argp = &arg; | ||
681 | + Error *local_err = NULL; | ||
682 | + | 92 | + |
683 | + visit_type_ThrottleLimits(v, name, &argp, &local_err); | 93 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); |
684 | + if (local_err) { | 94 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); |
685 | + goto ret; | 95 | g_test_add_func("/bdrv-drain/quiesce/drain_subtree", |
686 | + } | 96 | test_quiesce_drain_subtree); |
687 | + qemu_mutex_lock(&tg->lock); | 97 | |
688 | + throttle_get_config(&tg->ts, &cfg); | 98 | + // XXX bdrv_drain_all() doesn't work in coroutine context |
689 | + throttle_limits_to_config(argp, &cfg, &local_err); | 99 | + g_test_add_func("/bdrv-drain/quiesce/co/drain", test_quiesce_co_drain); |
690 | + if (local_err) { | 100 | + g_test_add_func("/bdrv-drain/quiesce/co/drain_subtree", |
691 | + goto unlock; | 101 | + test_quiesce_co_drain_subtree); |
692 | + } | ||
693 | + throttle_config(&tg->ts, tg->clock_type, &cfg); | ||
694 | + | 102 | + |
695 | +unlock: | 103 | g_test_add_func("/bdrv-drain/nested", test_nested); |
696 | + qemu_mutex_unlock(&tg->lock); | 104 | |
697 | +ret: | 105 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); |
698 | + error_propagate(errp, local_err); | ||
699 | + return; | ||
700 | +} | ||
701 | + | ||
702 | +static void throttle_group_get_limits(Object *obj, Visitor *v, | ||
703 | + const char *name, void *opaque, | ||
704 | + Error **errp) | ||
705 | +{ | ||
706 | + ThrottleGroup *tg = THROTTLE_GROUP(obj); | ||
707 | + ThrottleConfig cfg; | ||
708 | + ThrottleLimits arg = { 0 }; | ||
709 | + ThrottleLimits *argp = &arg; | ||
710 | + | ||
711 | + qemu_mutex_lock(&tg->lock); | ||
712 | + throttle_get_config(&tg->ts, &cfg); | ||
713 | + qemu_mutex_unlock(&tg->lock); | ||
714 | + | ||
715 | + throttle_config_to_limits(&cfg, argp); | ||
716 | + | ||
717 | + visit_type_ThrottleLimits(v, name, &argp, errp); | ||
718 | +} | ||
719 | + | ||
720 | +static bool throttle_group_can_be_deleted(UserCreatable *uc) | ||
721 | +{ | ||
722 | + return OBJECT(uc)->ref == 1; | ||
723 | +} | ||
724 | + | ||
725 | +static void throttle_group_obj_class_init(ObjectClass *klass, void *class_data) | ||
726 | +{ | ||
727 | + size_t i = 0; | ||
728 | + UserCreatableClass *ucc = USER_CREATABLE_CLASS(klass); | ||
729 | + | ||
730 | + ucc->complete = throttle_group_obj_complete; | ||
731 | + ucc->can_be_deleted = throttle_group_can_be_deleted; | ||
732 | + | ||
733 | + /* individual properties */ | ||
734 | + for (i = 0; i < sizeof(properties) / sizeof(ThrottleParamInfo); i++) { | ||
735 | + object_class_property_add(klass, | ||
736 | + properties[i].name, | ||
737 | + "int", | ||
738 | + throttle_group_get, | ||
739 | + throttle_group_set, | ||
740 | + NULL, &properties[i], | ||
741 | + &error_abort); | ||
742 | + } | ||
743 | + | ||
744 | + /* ThrottleLimits */ | ||
745 | + object_class_property_add(klass, | ||
746 | + "limits", "ThrottleLimits", | ||
747 | + throttle_group_get_limits, | ||
748 | + throttle_group_set_limits, | ||
749 | + NULL, NULL, | ||
750 | + &error_abort); | ||
751 | +} | ||
752 | + | ||
753 | +static const TypeInfo throttle_group_info = { | ||
754 | + .name = TYPE_THROTTLE_GROUP, | ||
755 | + .parent = TYPE_OBJECT, | ||
756 | + .class_init = throttle_group_obj_class_init, | ||
757 | + .instance_size = sizeof(ThrottleGroup), | ||
758 | + .instance_init = throttle_group_obj_init, | ||
759 | + .instance_finalize = throttle_group_obj_finalize, | ||
760 | + .interfaces = (InterfaceInfo[]) { | ||
761 | + { TYPE_USER_CREATABLE }, | ||
762 | + { } | ||
763 | + }, | ||
764 | +}; | ||
765 | + | ||
766 | static void throttle_groups_init(void) | ||
767 | { | ||
768 | - qemu_mutex_init(&throttle_groups_lock); | ||
769 | + type_register_static(&throttle_group_info); | ||
770 | } | ||
771 | |||
772 | -block_init(throttle_groups_init); | ||
773 | +type_init(throttle_groups_init); | ||
774 | diff --git a/tests/test-throttle.c b/tests/test-throttle.c | ||
775 | index XXXXXXX..XXXXXXX 100644 | ||
776 | --- a/tests/test-throttle.c | ||
777 | +++ b/tests/test-throttle.c | ||
778 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
779 | qemu_init_main_loop(&error_fatal); | ||
780 | ctx = qemu_get_aio_context(); | ||
781 | bdrv_init(); | ||
782 | + module_call_init(MODULE_INIT_QOM); | ||
783 | |||
784 | do {} while (g_main_context_iteration(NULL, false)); | ||
785 | |||
786 | diff --git a/util/throttle.c b/util/throttle.c | ||
787 | index XXXXXXX..XXXXXXX 100644 | ||
788 | --- a/util/throttle.c | ||
789 | +++ b/util/throttle.c | ||
790 | @@ -XXX,XX +XXX,XX @@ void throttle_account(ThrottleState *ts, bool is_write, uint64_t size) | ||
791 | } | ||
792 | } | ||
793 | |||
794 | +/* return a ThrottleConfig based on the options in a ThrottleLimits | ||
795 | + * | ||
796 | + * @arg: the ThrottleLimits object to read from | ||
797 | + * @cfg: the ThrottleConfig to edit | ||
798 | + * @errp: error object | ||
799 | + */ | ||
800 | +void throttle_limits_to_config(ThrottleLimits *arg, ThrottleConfig *cfg, | ||
801 | + Error **errp) | ||
802 | +{ | ||
803 | + if (arg->has_bps_total) { | ||
804 | + cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps_total; | ||
805 | + } | ||
806 | + if (arg->has_bps_read) { | ||
807 | + cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_read; | ||
808 | + } | ||
809 | + if (arg->has_bps_write) { | ||
810 | + cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_write; | ||
811 | + } | ||
812 | + | ||
813 | + if (arg->has_iops_total) { | ||
814 | + cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops_total; | ||
815 | + } | ||
816 | + if (arg->has_iops_read) { | ||
817 | + cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_read; | ||
818 | + } | ||
819 | + if (arg->has_iops_write) { | ||
820 | + cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_write; | ||
821 | + } | ||
822 | + | ||
823 | + if (arg->has_bps_total_max) { | ||
824 | + cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_total_max; | ||
825 | + } | ||
826 | + if (arg->has_bps_read_max) { | ||
827 | + cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_read_max; | ||
828 | + } | ||
829 | + if (arg->has_bps_write_max) { | ||
830 | + cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_write_max; | ||
831 | + } | ||
832 | + if (arg->has_iops_total_max) { | ||
833 | + cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_total_max; | ||
834 | + } | ||
835 | + if (arg->has_iops_read_max) { | ||
836 | + cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_read_max; | ||
837 | + } | ||
838 | + if (arg->has_iops_write_max) { | ||
839 | + cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_write_max; | ||
840 | + } | ||
841 | + | ||
842 | + if (arg->has_bps_total_max_length) { | ||
843 | + if (arg->bps_total_max_length > UINT_MAX) { | ||
844 | + error_setg(errp, "bps-total-max-length value must be in" | ||
845 | + " the range [0, %u]", UINT_MAX); | ||
846 | + return; | ||
847 | + } | ||
848 | + cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_total_max_length; | ||
849 | + } | ||
850 | + if (arg->has_bps_read_max_length) { | ||
851 | + if (arg->bps_read_max_length > UINT_MAX) { | ||
852 | + error_setg(errp, "bps-read-max-length value must be in" | ||
853 | + " the range [0, %u]", UINT_MAX); | ||
854 | + return; | ||
855 | + } | ||
856 | + cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_read_max_length; | ||
857 | + } | ||
858 | + if (arg->has_bps_write_max_length) { | ||
859 | + if (arg->bps_write_max_length > UINT_MAX) { | ||
860 | + error_setg(errp, "bps-write-max-length value must be in" | ||
861 | + " the range [0, %u]", UINT_MAX); | ||
862 | + return; | ||
863 | + } | ||
864 | + cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_write_max_length; | ||
865 | + } | ||
866 | + if (arg->has_iops_total_max_length) { | ||
867 | + if (arg->iops_total_max_length > UINT_MAX) { | ||
868 | + error_setg(errp, "iops-total-max-length value must be in" | ||
869 | + " the range [0, %u]", UINT_MAX); | ||
870 | + return; | ||
871 | + } | ||
872 | + cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_total_max_length; | ||
873 | + } | ||
874 | + if (arg->has_iops_read_max_length) { | ||
875 | + if (arg->iops_read_max_length > UINT_MAX) { | ||
876 | + error_setg(errp, "iops-read-max-length value must be in" | ||
877 | + " the range [0, %u]", UINT_MAX); | ||
878 | + return; | ||
879 | + } | ||
880 | + cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_read_max_length; | ||
881 | + } | ||
882 | + if (arg->has_iops_write_max_length) { | ||
883 | + if (arg->iops_write_max_length > UINT_MAX) { | ||
884 | + error_setg(errp, "iops-write-max-length value must be in" | ||
885 | + " the range [0, %u]", UINT_MAX); | ||
886 | + return; | ||
887 | + } | ||
888 | + cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_write_max_length; | ||
889 | + } | ||
890 | + | ||
891 | + if (arg->has_iops_size) { | ||
892 | + cfg->op_size = arg->iops_size; | ||
893 | + } | ||
894 | + | ||
895 | + throttle_is_valid(cfg, errp); | ||
896 | +} | ||
897 | + | ||
898 | +/* write the options of a ThrottleConfig to a ThrottleLimits | ||
899 | + * | ||
900 | + * @cfg: the ThrottleConfig to read from | ||
901 | + * @var: the ThrottleLimits to write to | ||
902 | + */ | ||
903 | +void throttle_config_to_limits(ThrottleConfig *cfg, ThrottleLimits *var) | ||
904 | +{ | ||
905 | + var->bps_total = cfg->buckets[THROTTLE_BPS_TOTAL].avg; | ||
906 | + var->bps_read = cfg->buckets[THROTTLE_BPS_READ].avg; | ||
907 | + var->bps_write = cfg->buckets[THROTTLE_BPS_WRITE].avg; | ||
908 | + var->iops_total = cfg->buckets[THROTTLE_OPS_TOTAL].avg; | ||
909 | + var->iops_read = cfg->buckets[THROTTLE_OPS_READ].avg; | ||
910 | + var->iops_write = cfg->buckets[THROTTLE_OPS_WRITE].avg; | ||
911 | + var->bps_total_max = cfg->buckets[THROTTLE_BPS_TOTAL].max; | ||
912 | + var->bps_read_max = cfg->buckets[THROTTLE_BPS_READ].max; | ||
913 | + var->bps_write_max = cfg->buckets[THROTTLE_BPS_WRITE].max; | ||
914 | + var->iops_total_max = cfg->buckets[THROTTLE_OPS_TOTAL].max; | ||
915 | + var->iops_read_max = cfg->buckets[THROTTLE_OPS_READ].max; | ||
916 | + var->iops_write_max = cfg->buckets[THROTTLE_OPS_WRITE].max; | ||
917 | + var->bps_total_max_length = cfg->buckets[THROTTLE_BPS_TOTAL].burst_length; | ||
918 | + var->bps_read_max_length = cfg->buckets[THROTTLE_BPS_READ].burst_length; | ||
919 | + var->bps_write_max_length = cfg->buckets[THROTTLE_BPS_WRITE].burst_length; | ||
920 | + var->iops_total_max_length = cfg->buckets[THROTTLE_OPS_TOTAL].burst_length; | ||
921 | + var->iops_read_max_length = cfg->buckets[THROTTLE_OPS_READ].burst_length; | ||
922 | + var->iops_write_max_length = cfg->buckets[THROTTLE_OPS_WRITE].burst_length; | ||
923 | + var->iops_size = cfg->op_size; | ||
924 | + | ||
925 | + var->has_bps_total = true; | ||
926 | + var->has_bps_read = true; | ||
927 | + var->has_bps_write = true; | ||
928 | + var->has_iops_total = true; | ||
929 | + var->has_iops_read = true; | ||
930 | + var->has_iops_write = true; | ||
931 | + var->has_bps_total_max = true; | ||
932 | + var->has_bps_read_max = true; | ||
933 | + var->has_bps_write_max = true; | ||
934 | + var->has_iops_total_max = true; | ||
935 | + var->has_iops_read_max = true; | ||
936 | + var->has_iops_write_max = true; | ||
937 | + var->has_bps_read_max_length = true; | ||
938 | + var->has_bps_total_max_length = true; | ||
939 | + var->has_bps_write_max_length = true; | ||
940 | + var->has_iops_total_max_length = true; | ||
941 | + var->has_iops_read_max_length = true; | ||
942 | + var->has_iops_write_max_length = true; | ||
943 | + var->has_iops_size = true; | ||
944 | +} | ||
945 | -- | 106 | -- |
946 | 2.13.5 | 107 | 2.13.6 |
947 | 108 | ||
948 | 109 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Test that drain sections are correctly propagated through the graph. | ||
1 | 2 | ||
3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
4 | --- | ||
5 | tests/test-bdrv-drain.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ | ||
6 | 1 file changed, 74 insertions(+) | ||
7 | |||
8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/tests/test-bdrv-drain.c | ||
11 | +++ b/tests/test-bdrv-drain.c | ||
12 | @@ -XXX,XX +XXX,XX @@ static void test_nested(void) | ||
13 | blk_unref(blk); | ||
14 | } | ||
15 | |||
16 | +static void test_multiparent(void) | ||
17 | +{ | ||
18 | + BlockBackend *blk_a, *blk_b; | ||
19 | + BlockDriverState *bs_a, *bs_b, *backing; | ||
20 | + BDRVTestState *a_s, *b_s, *backing_s; | ||
21 | + | ||
22 | + blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
23 | + bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, | ||
24 | + &error_abort); | ||
25 | + a_s = bs_a->opaque; | ||
26 | + blk_insert_bs(blk_a, bs_a, &error_abort); | ||
27 | + | ||
28 | + blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
29 | + bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, | ||
30 | + &error_abort); | ||
31 | + b_s = bs_b->opaque; | ||
32 | + blk_insert_bs(blk_b, bs_b, &error_abort); | ||
33 | + | ||
34 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); | ||
35 | + backing_s = backing->opaque; | ||
36 | + bdrv_set_backing_hd(bs_a, backing, &error_abort); | ||
37 | + bdrv_set_backing_hd(bs_b, backing, &error_abort); | ||
38 | + | ||
39 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 0); | ||
40 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 0); | ||
41 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | ||
42 | + g_assert_cmpint(a_s->drain_count, ==, 0); | ||
43 | + g_assert_cmpint(b_s->drain_count, ==, 0); | ||
44 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
45 | + | ||
46 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); | ||
47 | + | ||
48 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 1); | ||
49 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 1); | ||
50 | + g_assert_cmpint(backing->quiesce_counter, ==, 1); | ||
51 | + g_assert_cmpint(a_s->drain_count, ==, 1); | ||
52 | + g_assert_cmpint(b_s->drain_count, ==, 1); | ||
53 | + g_assert_cmpint(backing_s->drain_count, ==, 1); | ||
54 | + | ||
55 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); | ||
56 | + | ||
57 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 2); | ||
58 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 2); | ||
59 | + g_assert_cmpint(backing->quiesce_counter, ==, 2); | ||
60 | + g_assert_cmpint(a_s->drain_count, ==, 2); | ||
61 | + g_assert_cmpint(b_s->drain_count, ==, 2); | ||
62 | + g_assert_cmpint(backing_s->drain_count, ==, 2); | ||
63 | + | ||
64 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); | ||
65 | + | ||
66 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 1); | ||
67 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 1); | ||
68 | + g_assert_cmpint(backing->quiesce_counter, ==, 1); | ||
69 | + g_assert_cmpint(a_s->drain_count, ==, 1); | ||
70 | + g_assert_cmpint(b_s->drain_count, ==, 1); | ||
71 | + g_assert_cmpint(backing_s->drain_count, ==, 1); | ||
72 | + | ||
73 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); | ||
74 | + | ||
75 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 0); | ||
76 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 0); | ||
77 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | ||
78 | + g_assert_cmpint(a_s->drain_count, ==, 0); | ||
79 | + g_assert_cmpint(b_s->drain_count, ==, 0); | ||
80 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
81 | + | ||
82 | + bdrv_unref(backing); | ||
83 | + bdrv_unref(bs_a); | ||
84 | + bdrv_unref(bs_b); | ||
85 | + blk_unref(blk_a); | ||
86 | + blk_unref(blk_b); | ||
87 | +} | ||
88 | + | ||
89 | |||
90 | typedef struct TestBlockJob { | ||
91 | BlockJob common; | ||
92 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
93 | test_quiesce_co_drain_subtree); | ||
94 | |||
95 | g_test_add_func("/bdrv-drain/nested", test_nested); | ||
96 | + g_test_add_func("/bdrv-drain/multiparent", test_multiparent); | ||
97 | |||
98 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); | ||
99 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | ||
100 | -- | ||
101 | 2.13.6 | ||
102 | |||
103 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | 1 | We need to remember how many of the drain sections in which a node is |
---|---|---|---|
2 | 2 | were recursive (i.e. subtree drain rather than node drain), so that they | |
3 | This function is not used anywhere, so remove it. | 3 | can be correctly applied when children are added or removed during the |
4 | 4 | drained section. | |
5 | Markus Armbruster adds: | 5 | |
6 | The i82078 floppy device model used to call bdrv_media_changed() to | 6 | With this change, it is safe to modify the graph even inside a |
7 | implement its media change bit when backed by a host floppy. This | 7 | bdrv_subtree_drained_begin/end() section. |
8 | went away in 21fcf36 "fdc: simplify media change handling". | 8 | |
9 | Probably broke host floppy media change. Host floppy pass-through | ||
10 | was dropped in commit f709623. bdrv_media_changed() has never been | ||
11 | used for anything else. Remove it. | ||
12 | (Source is Message-ID: <87y3ruaypm.fsf@dusky.pond.sub.org>) | ||
13 | |||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
18 | --- | 10 | --- |
19 | include/block/block.h | 1 - | 11 | include/block/block.h | 2 -- |
20 | include/block/block_int.h | 1 - | 12 | include/block/block_int.h | 5 +++++ |
21 | block.c | 14 -------------- | 13 | block.c | 32 +++++++++++++++++++++++++++++--- |
22 | block/raw-format.c | 6 ------ | 14 | block/io.c | 28 ++++++++++++++++++++++++---- |
23 | 4 files changed, 22 deletions(-) | 15 | 4 files changed, 58 insertions(+), 9 deletions(-) |
24 | 16 | ||
25 | diff --git a/include/block/block.h b/include/block/block.h | 17 | diff --git a/include/block/block.h b/include/block/block.h |
26 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/block/block.h | 19 | --- a/include/block/block.h |
28 | +++ b/include/block/block.h | 20 | +++ b/include/block/block.h |
29 | @@ -XXX,XX +XXX,XX @@ int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, | 21 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs); |
30 | int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); | 22 | /** |
31 | bool bdrv_is_sg(BlockDriverState *bs); | 23 | * Like bdrv_drained_begin, but recursively begins a quiesced section for |
32 | bool bdrv_is_inserted(BlockDriverState *bs); | 24 | * exclusive access to all child nodes as well. |
33 | -int bdrv_media_changed(BlockDriverState *bs); | 25 | - * |
34 | void bdrv_lock_medium(BlockDriverState *bs, bool locked); | 26 | - * Graph changes are not allowed during a subtree drain section. |
35 | void bdrv_eject(BlockDriverState *bs, bool eject_flag); | 27 | */ |
36 | const char *bdrv_get_format_name(BlockDriverState *bs); | 28 | void bdrv_subtree_drained_begin(BlockDriverState *bs); |
29 | |||
37 | diff --git a/include/block/block_int.h b/include/block/block_int.h | 30 | diff --git a/include/block/block_int.h b/include/block/block_int.h |
38 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/include/block/block_int.h | 32 | --- a/include/block/block_int.h |
40 | +++ b/include/block/block_int.h | 33 | +++ b/include/block/block_int.h |
41 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | 34 | @@ -XXX,XX +XXX,XX @@ struct BlockDriverState { |
42 | 35 | ||
43 | /* removable device specific */ | 36 | /* Accessed with atomic ops. */ |
44 | bool (*bdrv_is_inserted)(BlockDriverState *bs); | 37 | int quiesce_counter; |
45 | - int (*bdrv_media_changed)(BlockDriverState *bs); | 38 | + int recursive_quiesce_counter; |
46 | void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); | 39 | + |
47 | void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); | 40 | unsigned int write_gen; /* Current data generation */ |
48 | 41 | ||
42 | /* Protected by reqs_lock. */ | ||
43 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, | ||
44 | int64_t offset, unsigned int bytes, QEMUIOVector *qiov, | ||
45 | BdrvRequestFlags flags); | ||
46 | |||
47 | +void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent); | ||
48 | +void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_parent); | ||
49 | + | ||
50 | int get_tmp_filename(char *filename, int size); | ||
51 | BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, | ||
52 | const char *filename); | ||
49 | diff --git a/block.c b/block.c | 53 | diff --git a/block.c b/block.c |
50 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/block.c | 55 | --- a/block.c |
52 | +++ b/block.c | 56 | +++ b/block.c |
53 | @@ -XXX,XX +XXX,XX @@ bool bdrv_is_inserted(BlockDriverState *bs) | 57 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child) |
54 | } | 58 | bdrv_drained_end(bs); |
55 | 59 | } | |
56 | /** | 60 | |
57 | - * Return whether the media changed since the last call to this | 61 | +static void bdrv_child_cb_attach(BdrvChild *child) |
58 | - * function, or -ENOTSUP if we don't know. Most drivers don't know. | 62 | +{ |
59 | - */ | 63 | + BlockDriverState *bs = child->opaque; |
60 | -int bdrv_media_changed(BlockDriverState *bs) | 64 | + bdrv_apply_subtree_drain(child, bs); |
61 | -{ | 65 | +} |
62 | - BlockDriver *drv = bs->drv; | 66 | + |
63 | - | 67 | +static void bdrv_child_cb_detach(BdrvChild *child) |
64 | - if (drv && drv->bdrv_media_changed) { | 68 | +{ |
65 | - return drv->bdrv_media_changed(bs); | 69 | + BlockDriverState *bs = child->opaque; |
66 | - } | 70 | + bdrv_unapply_subtree_drain(child, bs); |
67 | - return -ENOTSUP; | 71 | +} |
68 | -} | 72 | + |
69 | - | 73 | static int bdrv_child_cb_inactivate(BdrvChild *child) |
70 | -/** | ||
71 | * If eject_flag is TRUE, eject the media. Otherwise, close the tray | ||
72 | */ | ||
73 | void bdrv_eject(BlockDriverState *bs, bool eject_flag) | ||
74 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/block/raw-format.c | ||
77 | +++ b/block/raw-format.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, | ||
79 | return bdrv_truncate(bs->file, offset, prealloc, errp); | ||
80 | } | ||
81 | |||
82 | -static int raw_media_changed(BlockDriverState *bs) | ||
83 | -{ | ||
84 | - return bdrv_media_changed(bs->file->bs); | ||
85 | -} | ||
86 | - | ||
87 | static void raw_eject(BlockDriverState *bs, bool eject_flag) | ||
88 | { | 74 | { |
89 | bdrv_eject(bs->file->bs, eject_flag); | 75 | BlockDriverState *bs = child->opaque; |
90 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_raw = { | 76 | @@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = { |
91 | .bdrv_refresh_limits = &raw_refresh_limits, | 77 | .inherit_options = bdrv_inherited_options, |
92 | .bdrv_probe_blocksizes = &raw_probe_blocksizes, | 78 | .drained_begin = bdrv_child_cb_drained_begin, |
93 | .bdrv_probe_geometry = &raw_probe_geometry, | 79 | .drained_end = bdrv_child_cb_drained_end, |
94 | - .bdrv_media_changed = &raw_media_changed, | 80 | + .attach = bdrv_child_cb_attach, |
95 | .bdrv_eject = &raw_eject, | 81 | + .detach = bdrv_child_cb_detach, |
96 | .bdrv_lock_medium = &raw_lock_medium, | 82 | .inactivate = bdrv_child_cb_inactivate, |
97 | .bdrv_co_ioctl = &raw_co_ioctl, | 83 | }; |
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = { | ||
86 | .inherit_options = bdrv_inherited_fmt_options, | ||
87 | .drained_begin = bdrv_child_cb_drained_begin, | ||
88 | .drained_end = bdrv_child_cb_drained_end, | ||
89 | + .attach = bdrv_child_cb_attach, | ||
90 | + .detach = bdrv_child_cb_detach, | ||
91 | .inactivate = bdrv_child_cb_inactivate, | ||
92 | }; | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_attach(BdrvChild *c) | ||
95 | parent->backing_blocker); | ||
96 | bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, | ||
97 | parent->backing_blocker); | ||
98 | + | ||
99 | + bdrv_child_cb_attach(c); | ||
100 | } | ||
101 | |||
102 | static void bdrv_backing_detach(BdrvChild *c) | ||
103 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_detach(BdrvChild *c) | ||
104 | bdrv_op_unblock_all(c->bs, parent->backing_blocker); | ||
105 | error_free(parent->backing_blocker); | ||
106 | parent->backing_blocker = NULL; | ||
107 | + | ||
108 | + bdrv_child_cb_detach(c); | ||
109 | } | ||
110 | |||
111 | /* | ||
112 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
113 | assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs)); | ||
114 | } | ||
115 | if (old_bs) { | ||
116 | + /* Detach first so that the recursive drain sections coming from @child | ||
117 | + * are already gone and we only end the drain sections that came from | ||
118 | + * elsewhere. */ | ||
119 | + if (child->role->detach) { | ||
120 | + child->role->detach(child); | ||
121 | + } | ||
122 | if (old_bs->quiesce_counter && child->role->drained_end) { | ||
123 | for (i = 0; i < old_bs->quiesce_counter; i++) { | ||
124 | child->role->drained_end(child); | ||
125 | } | ||
126 | } | ||
127 | - if (child->role->detach) { | ||
128 | - child->role->detach(child); | ||
129 | - } | ||
130 | QLIST_REMOVE(child, next_parent); | ||
131 | } | ||
132 | |||
133 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, | ||
134 | } | ||
135 | } | ||
136 | |||
137 | + /* Attach only after starting new drained sections, so that recursive | ||
138 | + * drain sections coming from @child don't get an extra .drained_begin | ||
139 | + * callback. */ | ||
140 | if (child->role->attach) { | ||
141 | child->role->attach(child); | ||
142 | } | ||
143 | diff --git a/block/io.c b/block/io.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/block/io.c | ||
146 | +++ b/block/io.c | ||
147 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
148 | assert(data.done); | ||
149 | } | ||
150 | |||
151 | -static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, | ||
152 | - BdrvChild *parent) | ||
153 | +void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, | ||
154 | + BdrvChild *parent) | ||
155 | { | ||
156 | BdrvChild *child, *next; | ||
157 | |||
158 | @@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, | ||
159 | bdrv_drain_recurse(bs); | ||
160 | |||
161 | if (recursive) { | ||
162 | + bs->recursive_quiesce_counter++; | ||
163 | QLIST_FOREACH_SAFE(child, &bs->children, next, next) { | ||
164 | bdrv_do_drained_begin(child->bs, true, child); | ||
165 | } | ||
166 | @@ -XXX,XX +XXX,XX @@ void bdrv_subtree_drained_begin(BlockDriverState *bs) | ||
167 | bdrv_do_drained_begin(bs, true, NULL); | ||
168 | } | ||
169 | |||
170 | -static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, | ||
171 | - BdrvChild *parent) | ||
172 | +void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, | ||
173 | + BdrvChild *parent) | ||
174 | { | ||
175 | BdrvChild *child, *next; | ||
176 | int old_quiesce_counter; | ||
177 | @@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, | ||
178 | } | ||
179 | |||
180 | if (recursive) { | ||
181 | + bs->recursive_quiesce_counter--; | ||
182 | QLIST_FOREACH_SAFE(child, &bs->children, next, next) { | ||
183 | bdrv_do_drained_end(child->bs, true, child); | ||
184 | } | ||
185 | @@ -XXX,XX +XXX,XX @@ void bdrv_subtree_drained_end(BlockDriverState *bs) | ||
186 | bdrv_do_drained_end(bs, true, NULL); | ||
187 | } | ||
188 | |||
189 | +void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_parent) | ||
190 | +{ | ||
191 | + int i; | ||
192 | + | ||
193 | + for (i = 0; i < new_parent->recursive_quiesce_counter; i++) { | ||
194 | + bdrv_do_drained_begin(child->bs, true, child); | ||
195 | + } | ||
196 | +} | ||
197 | + | ||
198 | +void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_parent) | ||
199 | +{ | ||
200 | + int i; | ||
201 | + | ||
202 | + for (i = 0; i < old_parent->recursive_quiesce_counter; i++) { | ||
203 | + bdrv_do_drained_end(child->bs, true, child); | ||
204 | + } | ||
205 | +} | ||
206 | + | ||
207 | /* | ||
208 | * Wait for pending requests to complete on a single BlockDriverState subtree, | ||
209 | * and suspend block driver's internal I/O until next request arrives. | ||
98 | -- | 210 | -- |
99 | 2.13.5 | 211 | 2.13.6 |
100 | 212 | ||
101 | 213 | diff view generated by jsdifflib |
1 | From: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
---|---|---|---|
2 | |||
3 | Now that bdrv_truncate is passed to bs->file by default, remove the | ||
4 | callback from block/blkdebug.c and set is_filter to true. is_filter also gives | ||
5 | access to other callbacks that are forwarded automatically to bs->file for | ||
6 | filters. | ||
7 | |||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | --- | 2 | --- |
13 | block/blkdebug.c | 8 +------- | 3 | tests/test-bdrv-drain.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | 1 file changed, 1 insertion(+), 7 deletions(-) | 4 | 1 file changed, 80 insertions(+) |
15 | 5 | ||
16 | diff --git a/block/blkdebug.c b/block/blkdebug.c | 6 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
17 | index XXXXXXX..XXXXXXX 100644 | 7 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/block/blkdebug.c | 8 | --- a/tests/test-bdrv-drain.c |
19 | +++ b/block/blkdebug.c | 9 | +++ b/tests/test-bdrv-drain.c |
20 | @@ -XXX,XX +XXX,XX @@ static int64_t blkdebug_getlength(BlockDriverState *bs) | 10 | @@ -XXX,XX +XXX,XX @@ static void test_multiparent(void) |
21 | return bdrv_getlength(bs->file->bs); | 11 | blk_unref(blk_b); |
22 | } | 12 | } |
23 | 13 | ||
24 | -static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, | 14 | +static void test_graph_change(void) |
25 | - PreallocMode prealloc, Error **errp) | 15 | +{ |
26 | -{ | 16 | + BlockBackend *blk_a, *blk_b; |
27 | - return bdrv_truncate(bs->file, offset, prealloc, errp); | 17 | + BlockDriverState *bs_a, *bs_b, *backing; |
28 | -} | 18 | + BDRVTestState *a_s, *b_s, *backing_s; |
29 | - | 19 | + |
30 | static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) | 20 | + blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
31 | { | 21 | + bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, |
32 | BDRVBlkdebugState *s = bs->opaque; | 22 | + &error_abort); |
33 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkdebug = { | 23 | + a_s = bs_a->opaque; |
34 | .format_name = "blkdebug", | 24 | + blk_insert_bs(blk_a, bs_a, &error_abort); |
35 | .protocol_name = "blkdebug", | 25 | + |
36 | .instance_size = sizeof(BDRVBlkdebugState), | 26 | + blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
37 | + .is_filter = true, | 27 | + bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, |
38 | 28 | + &error_abort); | |
39 | .bdrv_parse_filename = blkdebug_parse_filename, | 29 | + b_s = bs_b->opaque; |
40 | .bdrv_file_open = blkdebug_open, | 30 | + blk_insert_bs(blk_b, bs_b, &error_abort); |
41 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_blkdebug = { | 31 | + |
42 | .bdrv_child_perm = bdrv_filter_default_perms, | 32 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); |
43 | 33 | + backing_s = backing->opaque; | |
44 | .bdrv_getlength = blkdebug_getlength, | 34 | + bdrv_set_backing_hd(bs_a, backing, &error_abort); |
45 | - .bdrv_truncate = blkdebug_truncate, | 35 | + |
46 | .bdrv_refresh_filename = blkdebug_refresh_filename, | 36 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 0); |
47 | .bdrv_refresh_limits = blkdebug_refresh_limits, | 37 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 0); |
48 | 38 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | |
39 | + g_assert_cmpint(a_s->drain_count, ==, 0); | ||
40 | + g_assert_cmpint(b_s->drain_count, ==, 0); | ||
41 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
42 | + | ||
43 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); | ||
44 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); | ||
45 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); | ||
46 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); | ||
47 | + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); | ||
48 | + | ||
49 | + bdrv_set_backing_hd(bs_b, backing, &error_abort); | ||
50 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 5); | ||
51 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 5); | ||
52 | + g_assert_cmpint(backing->quiesce_counter, ==, 5); | ||
53 | + g_assert_cmpint(a_s->drain_count, ==, 5); | ||
54 | + g_assert_cmpint(b_s->drain_count, ==, 5); | ||
55 | + g_assert_cmpint(backing_s->drain_count, ==, 5); | ||
56 | + | ||
57 | + bdrv_set_backing_hd(bs_b, NULL, &error_abort); | ||
58 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 3); | ||
59 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 2); | ||
60 | + g_assert_cmpint(backing->quiesce_counter, ==, 3); | ||
61 | + g_assert_cmpint(a_s->drain_count, ==, 3); | ||
62 | + g_assert_cmpint(b_s->drain_count, ==, 2); | ||
63 | + g_assert_cmpint(backing_s->drain_count, ==, 3); | ||
64 | + | ||
65 | + bdrv_set_backing_hd(bs_b, backing, &error_abort); | ||
66 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 5); | ||
67 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 5); | ||
68 | + g_assert_cmpint(backing->quiesce_counter, ==, 5); | ||
69 | + g_assert_cmpint(a_s->drain_count, ==, 5); | ||
70 | + g_assert_cmpint(b_s->drain_count, ==, 5); | ||
71 | + g_assert_cmpint(backing_s->drain_count, ==, 5); | ||
72 | + | ||
73 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); | ||
74 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); | ||
75 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); | ||
76 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); | ||
77 | + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); | ||
78 | + | ||
79 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 0); | ||
80 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 0); | ||
81 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | ||
82 | + g_assert_cmpint(a_s->drain_count, ==, 0); | ||
83 | + g_assert_cmpint(b_s->drain_count, ==, 0); | ||
84 | + g_assert_cmpint(backing_s->drain_count, ==, 0); | ||
85 | + | ||
86 | + bdrv_unref(backing); | ||
87 | + bdrv_unref(bs_a); | ||
88 | + bdrv_unref(bs_b); | ||
89 | + blk_unref(blk_a); | ||
90 | + blk_unref(blk_b); | ||
91 | +} | ||
92 | + | ||
93 | |||
94 | typedef struct TestBlockJob { | ||
95 | BlockJob common; | ||
96 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
97 | |||
98 | g_test_add_func("/bdrv-drain/nested", test_nested); | ||
99 | g_test_add_func("/bdrv-drain/multiparent", test_multiparent); | ||
100 | + g_test_add_func("/bdrv-drain/graph-change", test_graph_change); | ||
101 | |||
102 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); | ||
103 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | ||
49 | -- | 104 | -- |
50 | 2.13.5 | 105 | 2.13.6 |
51 | 106 | ||
52 | 107 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Since commit bde70715, base is the only node that is reopened in | ||
2 | commit_start(). This means that the code, which still involves an | ||
3 | explicit BlockReopenQueue, can now be simplified by using bdrv_reopen(). | ||
1 | 4 | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
6 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
7 | --- | ||
8 | block/commit.c | 8 +------- | ||
9 | 1 file changed, 1 insertion(+), 7 deletions(-) | ||
10 | |||
11 | diff --git a/block/commit.c b/block/commit.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/block/commit.c | ||
14 | +++ b/block/commit.c | ||
15 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
16 | const char *filter_node_name, Error **errp) | ||
17 | { | ||
18 | CommitBlockJob *s; | ||
19 | - BlockReopenQueue *reopen_queue = NULL; | ||
20 | int orig_base_flags; | ||
21 | BlockDriverState *iter; | ||
22 | BlockDriverState *commit_top_bs = NULL; | ||
23 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
24 | /* convert base to r/w, if necessary */ | ||
25 | orig_base_flags = bdrv_get_flags(base); | ||
26 | if (!(orig_base_flags & BDRV_O_RDWR)) { | ||
27 | - reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL, | ||
28 | - orig_base_flags | BDRV_O_RDWR); | ||
29 | - } | ||
30 | - | ||
31 | - if (reopen_queue) { | ||
32 | - bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &local_err); | ||
33 | + bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err); | ||
34 | if (local_err != NULL) { | ||
35 | error_propagate(errp, local_err); | ||
36 | goto fail; | ||
37 | -- | ||
38 | 2.13.6 | ||
39 | |||
40 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The bdrv_reopen*() implementation doesn't like it if the graph is | ||
2 | changed between queuing nodes for reopen and actually reopening them | ||
3 | (one of the reasons is that queuing can be recursive). | ||
1 | 4 | ||
5 | So instead of draining the device only in bdrv_reopen_multiple(), | ||
6 | require that callers already drained all affected nodes, and assert this | ||
7 | in bdrv_reopen_queue(). | ||
8 | |||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
11 | --- | ||
12 | block.c | 23 ++++++++++++++++------- | ||
13 | block/replication.c | 6 ++++++ | ||
14 | qemu-io-cmds.c | 3 +++ | ||
15 | 3 files changed, 25 insertions(+), 7 deletions(-) | ||
16 | |||
17 | diff --git a/block.c b/block.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block.c | ||
20 | +++ b/block.c | ||
21 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, | ||
22 | * returns a pointer to bs_queue, which is either the newly allocated | ||
23 | * bs_queue, or the existing bs_queue being used. | ||
24 | * | ||
25 | + * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple(). | ||
26 | */ | ||
27 | static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
28 | BlockDriverState *bs, | ||
29 | @@ -XXX,XX +XXX,XX @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, | ||
30 | BdrvChild *child; | ||
31 | QDict *old_options, *explicit_options; | ||
32 | |||
33 | + /* Make sure that the caller remembered to use a drained section. This is | ||
34 | + * important to avoid graph changes between the recursive queuing here and | ||
35 | + * bdrv_reopen_multiple(). */ | ||
36 | + assert(bs->quiesce_counter > 0); | ||
37 | + | ||
38 | if (bs_queue == NULL) { | ||
39 | bs_queue = g_new0(BlockReopenQueue, 1); | ||
40 | QSIMPLEQ_INIT(bs_queue); | ||
41 | @@ -XXX,XX +XXX,XX @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, | ||
42 | * If all devices prepare successfully, then the changes are committed | ||
43 | * to all devices. | ||
44 | * | ||
45 | + * All affected nodes must be drained between bdrv_reopen_queue() and | ||
46 | + * bdrv_reopen_multiple(). | ||
47 | */ | ||
48 | int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp) | ||
49 | { | ||
50 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **er | ||
51 | |||
52 | assert(bs_queue != NULL); | ||
53 | |||
54 | - aio_context_release(ctx); | ||
55 | - bdrv_drain_all_begin(); | ||
56 | - aio_context_acquire(ctx); | ||
57 | - | ||
58 | QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { | ||
59 | + assert(bs_entry->state.bs->quiesce_counter > 0); | ||
60 | if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, &local_err)) { | ||
61 | error_propagate(errp, local_err); | ||
62 | goto cleanup; | ||
63 | @@ -XXX,XX +XXX,XX @@ cleanup: | ||
64 | } | ||
65 | g_free(bs_queue); | ||
66 | |||
67 | - bdrv_drain_all_end(); | ||
68 | - | ||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp) | ||
73 | { | ||
74 | int ret = -1; | ||
75 | Error *local_err = NULL; | ||
76 | - BlockReopenQueue *queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); | ||
77 | + BlockReopenQueue *queue; | ||
78 | |||
79 | + bdrv_subtree_drained_begin(bs); | ||
80 | + | ||
81 | + queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); | ||
82 | ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_err); | ||
83 | if (local_err != NULL) { | ||
84 | error_propagate(errp, local_err); | ||
85 | } | ||
86 | + | ||
87 | + bdrv_subtree_drained_end(bs); | ||
88 | + | ||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | diff --git a/block/replication.c b/block/replication.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/block/replication.c | ||
95 | +++ b/block/replication.c | ||
96 | @@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, | ||
97 | new_secondary_flags = s->orig_secondary_flags; | ||
98 | } | ||
99 | |||
100 | + bdrv_subtree_drained_begin(s->hidden_disk->bs); | ||
101 | + bdrv_subtree_drained_begin(s->secondary_disk->bs); | ||
102 | + | ||
103 | if (orig_hidden_flags != new_hidden_flags) { | ||
104 | reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL, | ||
105 | new_hidden_flags); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, | ||
107 | reopen_queue, &local_err); | ||
108 | error_propagate(errp, local_err); | ||
109 | } | ||
110 | + | ||
111 | + bdrv_subtree_drained_end(s->hidden_disk->bs); | ||
112 | + bdrv_subtree_drained_end(s->secondary_disk->bs); | ||
113 | } | ||
114 | |||
115 | static void backup_job_cleanup(BlockDriverState *bs) | ||
116 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/qemu-io-cmds.c | ||
119 | +++ b/qemu-io-cmds.c | ||
120 | @@ -XXX,XX +XXX,XX @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) | ||
121 | opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; | ||
122 | qemu_opts_reset(&reopen_opts); | ||
123 | |||
124 | + bdrv_subtree_drained_begin(bs); | ||
125 | brq = bdrv_reopen_queue(NULL, bs, opts, flags); | ||
126 | bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); | ||
127 | + bdrv_subtree_drained_end(bs); | ||
128 | + | ||
129 | if (local_err) { | ||
130 | error_report_err(local_err); | ||
131 | } else { | ||
132 | -- | ||
133 | 2.13.6 | ||
134 | |||
135 | diff view generated by jsdifflib |