1 | The following changes since commit a26a98dfb9d448d7234d931ae3720feddf6f0651: | 1 | The following changes since commit 281f327487c9c9b1599f93c589a408bbf4a651b8: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20171006' into staging (2017-10-06 13:19:03 +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 fc3fd63fc0573ffd2ee569591a2e7f6c7310fd18: | 9 | for you to fetch changes up to 1a63a907507fbbcfaee3f622907ec244b7eabda8: |
10 | 10 | ||
11 | Merge remote-tracking branch 'mreitz/tags/pull-block-2017-10-06' into queue-block (2017-10-06 16:32:08 +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 (6): | 17 | Doug Gale (1): |
18 | block: use 1 MB bounce buffers for crypto instead of 16KB | 18 | nvme: Add tracing |
19 | crypto: expose encryption sector size in APIs | ||
20 | block: fix data type casting for crypto payload offset | ||
21 | block: convert crypto driver to bdrv_co_preadv|pwritev | ||
22 | block: convert qcrypto_block_encrypt|decrypt to take bytes offset | ||
23 | block: support passthrough of BDRV_REQ_FUA in crypto driver | ||
24 | 19 | ||
25 | Eric Blake (27): | 20 | Edgar Kaziakhmedov (1): |
26 | block: Typo fix in copy_on_readv() | 21 | qcow2: get rid of qcow2_backing_read1 routine |
27 | block: Make bdrv_img_create() size selection easier to read | ||
28 | hbitmap: Rename serialization_granularity to serialization_align | ||
29 | qcow2: Ensure bitmap serialization is aligned | ||
30 | dirty-bitmap: Drop unused functions | ||
31 | dirty-bitmap: Avoid size query failure during truncate | ||
32 | dirty-bitmap: Change bdrv_dirty_bitmap_size() to report bytes | ||
33 | dirty-bitmap: Track bitmap size by bytes | ||
34 | dirty-bitmap: Change bdrv_dirty_bitmap_*serialize*() to take bytes | ||
35 | qcow2: Switch sectors_covered_by_bitmap_cluster() to byte-based | ||
36 | dirty-bitmap: Set iterator start by offset, not sector | ||
37 | dirty-bitmap: Change bdrv_dirty_iter_next() to report byte offset | ||
38 | dirty-bitmap: Change bdrv_get_dirty_count() to report bytes | ||
39 | dirty-bitmap: Change bdrv_get_dirty_locked() to take bytes | ||
40 | dirty-bitmap: Change bdrv_[re]set_dirty_bitmap() to use bytes | ||
41 | mirror: Switch mirror_dirty_init() to byte-based iteration | ||
42 | qcow2: Switch qcow2_measure() to byte-based iteration | ||
43 | qcow2: Switch load_bitmap_data() to byte-based iteration | ||
44 | qcow2: Switch store_bitmap_data() to byte-based iteration | ||
45 | dirty-bitmap: Switch bdrv_set_dirty() to bytes | ||
46 | dirty-bitmap: Convert internal hbitmap size/granularity | ||
47 | qemu-io: Add -C for opening with copy-on-read | ||
48 | block: Uniform handling of 0-length bdrv_get_block_status() | ||
49 | iotests: Restore stty settings on completion | ||
50 | block: Add blkdebug hook for copy-on-read | ||
51 | block: Perform copy-on-read in loop | ||
52 | iotests: Add test 197 for covering copy-on-read | ||
53 | 22 | ||
54 | Kevin Wolf (6): | 23 | Fam Zheng (2): |
55 | block: Introduce BdrvChildRole.update_filename | 24 | block: Open backing image in force share mode for size probe |
56 | commit: Support multiple roots above top node | 25 | block: Remove unused bdrv_requests_pending |
57 | qemu-iotests: Allow QMP pretty printing in common.qemu | ||
58 | qemu-iotests: Test commit block job where top has two parents | ||
59 | commit: Remove overlay_bs | ||
60 | Merge remote-tracking branch 'mreitz/tags/pull-block-2017-10-06' into queue-block | ||
61 | 26 | ||
62 | Max Reitz (1): | 27 | John Snow (1): |
63 | iotests: Fix 195 if IMGFMT is part of TEST_DIR | 28 | iotests: fix 197 for vpc |
64 | 29 | ||
65 | Paolo Bonzini (10): | 30 | Kevin Wolf (27): |
66 | qemu-iotests: remove dead code | 31 | block: Formats don't need CONSISTENT_READ with NO_IO |
67 | qemu-iotests: get rid of AWK_PROG | 32 | block: Make bdrv_drain_invoke() recursive |
68 | qemu-iotests: move "check" code out of common.rc | 33 | block: Call .drain_begin only once in bdrv_drain_all_begin() |
69 | qemu-iotests: cleanup and fix search for programs | 34 | test-bdrv-drain: Test BlockDriver callbacks for drain |
70 | qemu-iotests: limit non-_PROG-suffixed variables to common.rc | 35 | block: bdrv_drain_recurse(): Remove unused begin parameter |
71 | qemu-iotests: do not include common.rc in "check" | 36 | block: Don't wait for requests in bdrv_drain*_end() |
72 | qemu-iotests: disintegrate more parts of common.config | 37 | block: Unify order in drain functions |
73 | qemu-iotests: fix uninitialized variable | 38 | block: Don't acquire AioContext in hmp_qemu_io() |
74 | qemu-iotests: get rid of $iam | 39 | block: Document that x-blockdev-change breaks quorum children list |
75 | qemu-iotests: merge "check" and "common" | 40 | block: Assert drain_all is only called from main AioContext |
41 | block: Make bdrv_drain() driver callbacks non-recursive | ||
42 | test-bdrv-drain: Test callback for bdrv_drain | ||
43 | test-bdrv-drain: Test bs->quiesce_counter | ||
44 | blockjob: Pause job on draining any job BDS | ||
45 | test-bdrv-drain: Test drain vs. block jobs | ||
46 | block: Don't block_job_pause_all() in bdrv_drain_all() | ||
47 | block: Nested drain_end must still call callbacks | ||
48 | test-bdrv-drain: Test nested drain sections | ||
49 | block: Don't notify parents in drain call chain | ||
50 | block: Add bdrv_subtree_drained_begin/end() | ||
51 | test-bdrv-drain: Tests for bdrv_subtree_drain | ||
52 | test-bdrv-drain: Test behaviour in coroutine context | ||
53 | test-bdrv-drain: Recursive draining with multiple parents | ||
54 | block: Allow graph changes in subtree drained section | ||
55 | test-bdrv-drain: Test graph changes in drained section | ||
56 | commit: Simplify reopen of base | ||
57 | block: Keep nodes drained between reopen_queue/multiple | ||
76 | 58 | ||
77 | Pavel Butsykin (2): | 59 | Thomas Huth (3): |
78 | qcow2: fix return error code in qcow2_truncate() | 60 | block: Remove the obsolete -drive boot=on|off parameter |
79 | qcow2: truncate the tail of the image file after shrinking the image | 61 | block: Remove the deprecated -hdachs option |
62 | block: Mention -drive cyls/heads/secs/trans/serial/addr in deprecation chapter | ||
80 | 63 | ||
81 | Thomas Huth (1): | 64 | qapi/block-core.json | 4 + |
82 | hw/block/onenand: Remove dead code block | 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 | ||
83 | 88 | ||
84 | Vladimir Sementsov-Ogievskiy (2): | ||
85 | block/mirror: check backing in bdrv_mirror_top_refresh_filename | ||
86 | block/mirror: check backing in bdrv_mirror_top_flush | ||
87 | |||
88 | qapi/block-core.json | 5 +- | ||
89 | block/qcow2.h | 1 + | ||
90 | crypto/blockpriv.h | 5 +- | ||
91 | include/block/block.h | 3 +- | ||
92 | include/block/block_int.h | 8 +- | ||
93 | include/block/dirty-bitmap.h | 43 +- | ||
94 | include/crypto/block.h | 29 +- | ||
95 | include/qemu/hbitmap.h | 8 +- | ||
96 | block.c | 109 ++++-- | ||
97 | block/backup.c | 7 +- | ||
98 | block/commit.c | 64 +-- | ||
99 | block/crypto.c | 130 +++--- | ||
100 | block/dirty-bitmap.c | 134 ++----- | ||
101 | block/io.c | 131 +++++-- | ||
102 | block/mirror.c | 88 ++--- | ||
103 | block/qcow.c | 11 +- | ||
104 | block/qcow2-bitmap.c | 62 +-- | ||
105 | block/qcow2-cluster.c | 8 +- | ||
106 | block/qcow2-refcount.c | 22 ++ | ||
107 | block/qcow2.c | 53 ++- | ||
108 | crypto/block-luks.c | 18 +- | ||
109 | crypto/block-qcow.c | 13 +- | ||
110 | crypto/block.c | 26 +- | ||
111 | hw/block/onenand.c | 4 - | ||
112 | migration/block.c | 12 +- | ||
113 | qemu-io.c | 15 +- | ||
114 | tests/test-hbitmap.c | 10 +- | ||
115 | util/hbitmap.c | 8 +- | ||
116 | tests/qemu-iotests/030 | 4 - | ||
117 | tests/qemu-iotests/039.out | 10 +- | ||
118 | tests/qemu-iotests/061.out | 4 +- | ||
119 | tests/qemu-iotests/137.out | 2 +- | ||
120 | tests/qemu-iotests/165 | 2 +- | ||
121 | tests/qemu-iotests/191 | 153 ++++++++ | ||
122 | tests/qemu-iotests/191.out | 827 +++++++++++++++++++++++++++++++++++++++ | ||
123 | tests/qemu-iotests/195 | 7 +- | ||
124 | tests/qemu-iotests/197 | 109 ++++++ | ||
125 | tests/qemu-iotests/197.out | 26 ++ | ||
126 | tests/qemu-iotests/check | 585 ++++++++++++++++++++++++--- | ||
127 | tests/qemu-iotests/common | 459 ---------------------- | ||
128 | tests/qemu-iotests/common.config | 206 +--------- | ||
129 | tests/qemu-iotests/common.filter | 1 + | ||
130 | tests/qemu-iotests/common.qemu | 15 +- | ||
131 | tests/qemu-iotests/common.rc | 205 +++++----- | ||
132 | tests/qemu-iotests/group | 2 + | ||
133 | 45 files changed, 2333 insertions(+), 1311 deletions(-) | ||
134 | create mode 100755 tests/qemu-iotests/191 | ||
135 | create mode 100644 tests/qemu-iotests/191.out | ||
136 | create mode 100755 tests/qemu-iotests/197 | ||
137 | create mode 100644 tests/qemu-iotests/197.out | ||
138 | delete mode 100644 tests/qemu-iotests/common | ||
139 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 4 | ||
3 | We've previously fixed several places where we failed to account | 5 | As this permission is geared towards whether the guest-visible data is |
4 | for possible errors from bdrv_nb_sectors(). Fix another one by | 6 | consistent, and has no impact on whether the metadata is sane, and |
5 | making bdrv_dirty_bitmap_truncate() take the new size from the | 7 | 'qemu-img info' does not read guest-visible data (except for the raw |
6 | caller instead of querying itself; then adjust the sole caller | 8 | format), it makes sense to not require BLK_PERM_CONSISTENT_READ if there |
7 | bdrv_truncate() to pass the size just determined by a successful | 9 | is not going to be any guest I/O performed, regardless of image format. |
8 | resize, or to reuse the size given to the original truncate | ||
9 | operation when refresh_total_sectors() was not able to confirm the | ||
10 | actual size (the two sizes can potentially differ according to | ||
11 | rounding constraints), thus avoiding sizing the bitmaps to -1. | ||
12 | This also fixes a bug where not all failure paths in | ||
13 | bdrv_truncate() would set errp. | ||
14 | 10 | ||
15 | Note that bdrv_truncate() is still a bit awkward. We may want | ||
16 | to revisit it later and clean up things to better guarantee that | ||
17 | a resize attempt either fails cleanly up front, or cannot fail | ||
18 | after guest-visible changes have been made (if temporary changes | ||
19 | are made, then they need to be cleanly rolled back). But that | ||
20 | is a task for another day; for now, the goal is the bare minimum | ||
21 | fix to ensure that just bdrv_dirty_bitmap_truncate() cannot fail. | ||
22 | |||
23 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
24 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
25 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
26 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
27 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
28 | --- | 12 | --- |
29 | include/block/dirty-bitmap.h | 2 +- | 13 | block.c | 6 +++++- |
30 | block.c | 16 +++++++++++----- | 14 | 1 file changed, 5 insertions(+), 1 deletion(-) |
31 | block/dirty-bitmap.c | 6 +++--- | ||
32 | 3 files changed, 15 insertions(+), 9 deletions(-) | ||
33 | 15 | ||
34 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/block/dirty-bitmap.h | ||
37 | +++ b/include/block/dirty-bitmap.h | ||
38 | @@ -XXX,XX +XXX,XX @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); | ||
39 | void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t sector_num); | ||
40 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); | ||
41 | int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); | ||
42 | -void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); | ||
43 | +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes); | ||
44 | bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); | ||
45 | bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); | ||
46 | bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); | ||
47 | diff --git a/block.c b/block.c | 16 | diff --git a/block.c b/block.c |
48 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/block.c | 18 | --- a/block.c |
50 | +++ b/block.c | 19 | +++ b/block.c |
51 | @@ -XXX,XX +XXX,XX @@ int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, | 20 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, |
52 | assert(!(bs->open_flags & BDRV_O_INACTIVE)); | 21 | assert(role == &child_backing || role == &child_file); |
53 | 22 | ||
54 | ret = drv->bdrv_truncate(bs, offset, prealloc, errp); | 23 | if (!backing) { |
55 | - if (ret == 0) { | 24 | + int flags = bdrv_reopen_get_flags(reopen_queue, bs); |
56 | - ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); | 25 | + |
57 | - bdrv_dirty_bitmap_truncate(bs); | 26 | /* Apart from the modifications below, the same permissions are |
58 | - bdrv_parent_cb_resize(bs); | 27 | * forwarded and left alone as for filters */ |
59 | - atomic_inc(&bs->write_gen); | 28 | bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, |
60 | + if (ret < 0) { | 29 | @@ -XXX,XX +XXX,XX @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, |
61 | + return ret; | 30 | |
62 | + } | 31 | /* bs->file always needs to be consistent because of the metadata. We |
63 | + ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); | 32 | * can never allow other users to resize or write to it. */ |
64 | + if (ret < 0) { | 33 | - perm |= BLK_PERM_CONSISTENT_READ; |
65 | + error_setg_errno(errp, -ret, "Could not refresh total sector count"); | 34 | + if (!(flags & BDRV_O_NO_IO)) { |
66 | + } else { | 35 | + perm |= BLK_PERM_CONSISTENT_READ; |
67 | + offset = bs->total_sectors * BDRV_SECTOR_SIZE; | 36 | + } |
68 | } | 37 | shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); |
69 | + bdrv_dirty_bitmap_truncate(bs, offset); | 38 | } else { |
70 | + bdrv_parent_cb_resize(bs); | 39 | /* We want consistent read from backing files if the parent needs it. |
71 | + atomic_inc(&bs->write_gen); | ||
72 | return ret; | ||
73 | } | ||
74 | |||
75 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/block/dirty-bitmap.c | ||
78 | +++ b/block/dirty-bitmap.c | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | /* | ||
81 | * Block Dirty Bitmap | ||
82 | * | ||
83 | - * Copyright (c) 2016 Red Hat. Inc | ||
84 | + * Copyright (c) 2016-2017 Red Hat. Inc | ||
85 | * | ||
86 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
87 | * of this software and associated documentation files (the "Software"), to deal | ||
88 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, | ||
89 | * Truncates _all_ bitmaps attached to a BDS. | ||
90 | * Called with BQL taken. | ||
91 | */ | ||
92 | -void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) | ||
93 | +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes) | ||
94 | { | ||
95 | BdrvDirtyBitmap *bitmap; | ||
96 | - uint64_t size = bdrv_nb_sectors(bs); | ||
97 | + int64_t size = DIV_ROUND_UP(bytes, BDRV_SECTOR_SIZE); | ||
98 | |||
99 | bdrv_dirty_bitmaps_lock(bs); | ||
100 | QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { | ||
101 | -- | 40 | -- |
102 | 2.13.6 | 41 | 2.13.6 |
103 | 42 | ||
104 | 43 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Add a test for qcow2 copy-on-read behavior, including exposure | 3 | VPC has some difficulty creating geometries of particular size. |
4 | for the just-fixed bugs. | 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. | ||
5 | 7 | ||
6 | The copy-on-read behavior is always to a qcow2 image, but the | 8 | Signed-off-by: John Snow <jsnow@redhat.com> |
7 | test is careful to allow running with most image protocol/format | 9 | Reviewed-by: Eric Blake <eblake@redhat.com> |
8 | combos as the backing file being copied from (luks being the | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | exception, as it is harder to pass the right secret to all the | ||
10 | right places). In fact, for './check nbd', this appears to be | ||
11 | the first time we've had a qcow2 image wrapping NBD, requiring | ||
12 | an additional line in _filter_img_create to match the similar | ||
13 | line in _filter_img_info. | ||
14 | |||
15 | Invoking blkdebug to prove we don't write too much took some | ||
16 | effort to get working; and it requires that $TEST_WRAP (based | ||
17 | on $TEST_DIR) not be subject to word splitting. We may decide | ||
18 | later to have the entire iotests suite use relative rather than | ||
19 | absolute names, to avoid problems inherited by the absolute | ||
20 | name of $PWD or $TEST_DIR, at which point the sanity check in | ||
21 | this commit could be simplified. | ||
22 | |||
23 | This test requires at least 2G of consecutive memory to succeed; | ||
24 | as such, it is prone to spurious failures, particularly on | ||
25 | 32-bit machines under load. This situation is detected and | ||
26 | triggers an early exit to skip the test, rather than a failure. | ||
27 | To manually provoke this setup on a beefier machine, I used: | ||
28 | $ (ulimit -S -v 1000000; ./check -qcow2 197) | ||
29 | |||
30 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
31 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | Reviewed-by: Lukáš Doktor <ldoktor@redhat.com> | ||
32 | --- | 13 | --- |
33 | tests/qemu-iotests/197 | 109 +++++++++++++++++++++++++++++++++++++++ | 14 | tests/qemu-iotests/197 | 4 ++++ |
34 | tests/qemu-iotests/197.out | 26 ++++++++++ | 15 | tests/qemu-iotests/common.filter | 3 ++- |
35 | tests/qemu-iotests/common.filter | 1 + | 16 | 2 files changed, 6 insertions(+), 1 deletion(-) |
36 | tests/qemu-iotests/group | 1 + | ||
37 | 4 files changed, 137 insertions(+) | ||
38 | create mode 100755 tests/qemu-iotests/197 | ||
39 | create mode 100644 tests/qemu-iotests/197.out | ||
40 | 17 | ||
41 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 | 18 | diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 |
42 | new file mode 100755 | 19 | index XXXXXXX..XXXXXXX 100755 |
43 | index XXXXXXX..XXXXXXX | 20 | --- a/tests/qemu-iotests/197 |
44 | --- /dev/null | ||
45 | +++ b/tests/qemu-iotests/197 | 21 | +++ b/tests/qemu-iotests/197 |
46 | @@ -XXX,XX +XXX,XX @@ | 22 | @@ -XXX,XX +XXX,XX @@ echo '=== Copy-on-read ===' |
47 | +#!/bin/bash | 23 | echo |
48 | +# | 24 | |
49 | +# Test case for copy-on-read into qcow2 | 25 | # Prep the images |
50 | +# | 26 | +# VPC rounds image sizes to a specific geometry, force a specific size. |
51 | +# Copyright (C) 2017 Red Hat, Inc. | 27 | +if [ "$IMGFMT" = "vpc" ]; then |
52 | +# | 28 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size") |
53 | +# This program is free software; you can redistribute it and/or modify | 29 | +fi |
54 | +# it under the terms of the GNU General Public License as published by | 30 | _make_test_img 4G |
55 | +# the Free Software Foundation; either version 2 of the License, or | 31 | $QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io |
56 | +# (at your option) any later version. | 32 | IMGPROTO=file IMGFMT=qcow2 IMGOPTS= TEST_IMG_FILE="$TEST_WRAP" \ |
57 | +# | ||
58 | +# This program is distributed in the hope that it will be useful, | ||
59 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
60 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
61 | +# GNU General Public License for more details. | ||
62 | +# | ||
63 | +# You should have received a copy of the GNU General Public License | ||
64 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
65 | +# | ||
66 | + | ||
67 | +# creator | ||
68 | +owner=eblake@redhat.com | ||
69 | + | ||
70 | +seq="$(basename $0)" | ||
71 | +echo "QA output created by $seq" | ||
72 | + | ||
73 | +here="$PWD" | ||
74 | +status=1 # failure is the default! | ||
75 | + | ||
76 | +# get standard environment, filters and checks | ||
77 | +. ./common.rc | ||
78 | +. ./common.filter | ||
79 | + | ||
80 | +TEST_WRAP="$TEST_DIR/t.wrap.qcow2" | ||
81 | +BLKDBG_CONF="$TEST_DIR/blkdebug.conf" | ||
82 | + | ||
83 | +# Sanity check: our use of blkdebug fails if $TEST_DIR contains spaces | ||
84 | +# or other problems | ||
85 | +case "$TEST_DIR" in | ||
86 | + *[^-_a-zA-Z0-9/]*) | ||
87 | + _notrun "Suspicious TEST_DIR='$TEST_DIR', cowardly refusing to run" ;; | ||
88 | +esac | ||
89 | + | ||
90 | +_cleanup() | ||
91 | +{ | ||
92 | + _cleanup_test_img | ||
93 | + rm -f "$BLKDBG_CONF" | ||
94 | +} | ||
95 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
96 | + | ||
97 | +# Test is supported for any backing file; but we force qcow2 for our wrapper. | ||
98 | +_supported_fmt generic | ||
99 | +_supported_proto generic | ||
100 | +_supported_os Linux | ||
101 | +# LUKS support may be possible, but it complicates things. | ||
102 | +_unsupported_fmt luks | ||
103 | + | ||
104 | +echo | ||
105 | +echo '=== Copy-on-read ===' | ||
106 | +echo | ||
107 | + | ||
108 | +# Prep the images | ||
109 | +_make_test_img 4G | ||
110 | +$QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io | ||
111 | +IMGPROTO=file IMGFMT=qcow2 IMGOPTS= TEST_IMG_FILE="$TEST_WRAP" \ | ||
112 | + _make_test_img -F "$IMGFMT" -b "$TEST_IMG" | _filter_img_create | ||
113 | +$QEMU_IO -f qcow2 -c "write -z -u 1M 64k" "$TEST_WRAP" | _filter_qemu_io | ||
114 | + | ||
115 | +# Ensure that a read of two clusters, but where one is already allocated, | ||
116 | +# does not re-write the allocated cluster | ||
117 | +cat > "$BLKDBG_CONF" <<EOF | ||
118 | +[inject-error] | ||
119 | +event = "cor_write" | ||
120 | +sector = "2048" | ||
121 | +EOF | ||
122 | +$QEMU_IO -c "open -C \ | ||
123 | + -o driver=blkdebug,config=$BLKDBG_CONF,image.driver=qcow2 $TEST_WRAP" \ | ||
124 | + -c "read -P 0 1M 128k" | _filter_qemu_io | ||
125 | + | ||
126 | +# Read the areas we want copied. A zero-length read should still be a | ||
127 | +# no-op. The next read is under 2G, but aligned so that rounding to | ||
128 | +# clusters copies more than 2G of zeroes. The final read will pick up | ||
129 | +# the non-zero data in the same cluster. Since a 2G read may exhaust | ||
130 | +# memory on some machines (particularly 32-bit), we skip the test if | ||
131 | +# that fails due to memory pressure. | ||
132 | +$QEMU_IO -f qcow2 -C -c "read 0 0" "$TEST_WRAP" | _filter_qemu_io | ||
133 | +output=$($QEMU_IO -f qcow2 -C -c "read -P 0 1k $((2*1024*1024*1024 - 512))" \ | ||
134 | + "$TEST_WRAP" 2>&1 | _filter_qemu_io) | ||
135 | +case $output in | ||
136 | + *allocate*) | ||
137 | + _notrun "Insufficent memory to run test" ;; | ||
138 | + *) printf '%s\n' "$output" ;; | ||
139 | +esac | ||
140 | +$QEMU_IO -f qcow2 -C -c "read -P 0 $((3*1024*1024*1024 + 1024)) 1k" \ | ||
141 | + "$TEST_WRAP" | _filter_qemu_io | ||
142 | + | ||
143 | +# Copy-on-read is incompatible with read-only | ||
144 | +$QEMU_IO -f qcow2 -C -r "$TEST_WRAP" 2>&1 | _filter_testdir | ||
145 | + | ||
146 | +# Break the backing chain, and show that images are identical, and that | ||
147 | +# we properly copied over explicit zeros. | ||
148 | +$QEMU_IMG rebase -u -b "" -f qcow2 "$TEST_WRAP" | ||
149 | +$QEMU_IO -f qcow2 -c map "$TEST_WRAP" | ||
150 | +_check_test_img | ||
151 | +$QEMU_IMG compare -f $IMGFMT -F qcow2 "$TEST_IMG" "$TEST_WRAP" | ||
152 | + | ||
153 | +# success, all done | ||
154 | +echo '*** done' | ||
155 | +status=0 | ||
156 | diff --git a/tests/qemu-iotests/197.out b/tests/qemu-iotests/197.out | ||
157 | new file mode 100644 | ||
158 | index XXXXXXX..XXXXXXX | ||
159 | --- /dev/null | ||
160 | +++ b/tests/qemu-iotests/197.out | ||
161 | @@ -XXX,XX +XXX,XX @@ | ||
162 | +QA output created by 197 | ||
163 | + | ||
164 | +=== Copy-on-read === | ||
165 | + | ||
166 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4294967296 | ||
167 | +wrote 1024/1024 bytes at offset 3221225472 | ||
168 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
169 | +Formatting 'TEST_DIR/t.wrap.IMGFMT', fmt=IMGFMT size=4294967296 backing_file=TEST_DIR/t.IMGFMT backing_fmt=IMGFMT | ||
170 | +wrote 65536/65536 bytes at offset 1048576 | ||
171 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
172 | +read 131072/131072 bytes at offset 1048576 | ||
173 | +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
174 | +read 0/0 bytes at offset 0 | ||
175 | +0 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
176 | +read 2147483136/2147483136 bytes at offset 1024 | ||
177 | +2 GiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
178 | +read 1024/1024 bytes at offset 3221226496 | ||
179 | +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
180 | +can't open device TEST_DIR/t.wrap.qcow2: Can't use copy-on-read on read-only device | ||
181 | +2 GiB (0x80010000) bytes allocated at offset 0 bytes (0x0) | ||
182 | +1023.938 MiB (0x3fff0000) bytes not allocated at offset 2 GiB (0x80010000) | ||
183 | +64 KiB (0x10000) bytes allocated at offset 3 GiB (0xc0000000) | ||
184 | +1023.938 MiB (0x3fff0000) bytes not allocated at offset 3 GiB (0xc0010000) | ||
185 | +No errors were found on the image. | ||
186 | +Images are identical. | ||
187 | +*** done | ||
188 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | 33 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter |
189 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
190 | --- a/tests/qemu-iotests/common.filter | 35 | --- a/tests/qemu-iotests/common.filter |
191 | +++ b/tests/qemu-iotests/common.filter | 36 | +++ b/tests/qemu-iotests/common.filter |
192 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() | 37 | @@ -XXX,XX +XXX,XX @@ _filter_img_create() |
193 | sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \ | 38 | -e "s# log_size=[0-9]\\+##g" \ |
194 | -e "s#$TEST_DIR#TEST_DIR#g" \ | 39 | -e "s# refcount_bits=[0-9]\\+##g" \ |
195 | -e "s#$IMGFMT#IMGFMT#g" \ | 40 | -e "s# key-secret=[a-zA-Z0-9]\\+##g" \ |
196 | + -e 's#nbd:127.0.0.1:10810#TEST_DIR/t.IMGFMT#g' \ | 41 | - -e "s# iter-time=[0-9]\\+##g" |
197 | -e "s# encryption=off##g" \ | 42 | + -e "s# iter-time=[0-9]\\+##g" \ |
198 | -e "s# cluster_size=[0-9]\\+##g" \ | 43 | + -e "s# force_size=\\(on\\|off\\)##g" |
199 | -e "s# table_size=[0-9]\\+##g" \ | 44 | } |
200 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | 45 | |
201 | index XXXXXXX..XXXXXXX 100644 | 46 | _filter_img_info() |
202 | --- a/tests/qemu-iotests/group | ||
203 | +++ b/tests/qemu-iotests/group | ||
204 | @@ -XXX,XX +XXX,XX @@ | ||
205 | 192 rw auto quick | ||
206 | 194 rw auto migration quick | ||
207 | 195 rw auto quick | ||
208 | +197 rw auto quick | ||
209 | -- | 47 | -- |
210 | 2.13.6 | 48 | 2.13.6 |
211 | 49 | ||
212 | 50 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 4 | ||
3 | All callers to bdrv_dirty_iter_new() passed 0 for their initial | 5 | One reason for this is that bdrv_drain_recurse() can be called multiple |
4 | starting point, drop that parameter. | 6 | times by bdrv_drain_all_begin(), but the callbacks may only be called |
7 | once. The separation is necessary to fix this bug. | ||
5 | 8 | ||
6 | Most callers to bdrv_set_dirty_iter() were scaling a byte offset to | 9 | The other reason is that we intend to go to a model where we call all |
7 | a sector number; the exception qcow2-bitmap will be converted later | 10 | driver callbacks first, and only then start polling. This is not fully |
8 | to use byte rather than sector iteration. Move the scaling to occur | 11 | achieved yet with this patch, as bdrv_drain_invoke() contains a |
9 | internally to dirty bitmap code instead, so that callers now pass | 12 | BDRV_POLL_WHILE() loop for the block driver callbacks, which can still |
10 | in bytes. | 13 | call callbacks for any unrelated event. It's a step in this direction |
14 | anyway. | ||
11 | 15 | ||
12 | Signed-off-by: Eric Blake <eblake@redhat.com> | 16 | Cc: qemu-stable@nongnu.org |
13 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
14 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
18 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | --- | 19 | --- |
18 | include/block/dirty-bitmap.h | 5 ++--- | 20 | block/io.c | 14 +++++++++++--- |
19 | block/backup.c | 5 ++--- | 21 | 1 file changed, 11 insertions(+), 3 deletions(-) |
20 | block/dirty-bitmap.c | 9 ++++----- | ||
21 | block/mirror.c | 4 ++-- | ||
22 | block/qcow2-bitmap.c | 4 ++-- | ||
23 | 5 files changed, 12 insertions(+), 15 deletions(-) | ||
24 | 22 | ||
25 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | 23 | diff --git a/block/io.c b/block/io.c |
26 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/block/dirty-bitmap.h | 25 | --- a/block/io.c |
28 | +++ b/include/block/dirty-bitmap.h | 26 | +++ b/block/io.c |
29 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | 27 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) |
30 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, | 28 | bdrv_wakeup(bs); |
31 | int64_t cur_sector, int64_t nr_sectors); | ||
32 | BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyBitmap *bitmap); | ||
33 | -BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, | ||
34 | - uint64_t first_sector); | ||
35 | +BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap); | ||
36 | void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); | ||
37 | |||
38 | uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, | ||
39 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
40 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
41 | int64_t cur_sector, int64_t nr_sectors); | ||
42 | int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); | ||
43 | -void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t sector_num); | ||
44 | +void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); | ||
45 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); | ||
46 | int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); | ||
47 | void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes); | ||
48 | diff --git a/block/backup.c b/block/backup.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/block/backup.c | ||
51 | +++ b/block/backup.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) | ||
53 | |||
54 | granularity = bdrv_dirty_bitmap_granularity(job->sync_bitmap); | ||
55 | clusters_per_iter = MAX((granularity / job->cluster_size), 1); | ||
56 | - dbi = bdrv_dirty_iter_new(job->sync_bitmap, 0); | ||
57 | + dbi = bdrv_dirty_iter_new(job->sync_bitmap); | ||
58 | |||
59 | /* Find the next dirty sector(s) */ | ||
60 | while ((offset = bdrv_dirty_iter_next(dbi) * BDRV_SECTOR_SIZE) >= 0) { | ||
61 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) | ||
62 | /* If the bitmap granularity is smaller than the backup granularity, | ||
63 | * we need to advance the iterator pointer to the next cluster. */ | ||
64 | if (granularity < job->cluster_size) { | ||
65 | - bdrv_set_dirty_iter(dbi, | ||
66 | - cluster * job->cluster_size / BDRV_SECTOR_SIZE); | ||
67 | + bdrv_set_dirty_iter(dbi, cluster * job->cluster_size); | ||
68 | } | ||
69 | |||
70 | last_cluster = cluster - 1; | ||
71 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/block/dirty-bitmap.c | ||
74 | +++ b/block/dirty-bitmap.c | ||
75 | @@ -XXX,XX +XXX,XX @@ uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap) | ||
76 | return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap); | ||
77 | } | 29 | } |
78 | 30 | ||
79 | -BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, | 31 | +/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ |
80 | - uint64_t first_sector) | 32 | static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) |
81 | +BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap) | ||
82 | { | 33 | { |
83 | BdrvDirtyBitmapIter *iter = g_new(BdrvDirtyBitmapIter, 1); | 34 | + BdrvChild *child, *tmp; |
84 | - hbitmap_iter_init(&iter->hbi, bitmap->bitmap, first_sector); | 35 | BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; |
85 | + hbitmap_iter_init(&iter->hbi, bitmap->bitmap, 0); | 36 | |
86 | iter->bitmap = bitmap; | 37 | if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) || |
87 | bitmap->active_iterators++; | 38 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) |
88 | return iter; | 39 | data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data); |
89 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, | 40 | bdrv_coroutine_enter(bs, data.co); |
90 | /** | 41 | BDRV_POLL_WHILE(bs, !data.done); |
91 | * Advance a BdrvDirtyBitmapIter to an arbitrary offset. | 42 | + |
92 | */ | 43 | + QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { |
93 | -void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *iter, int64_t sector_num) | 44 | + bdrv_drain_invoke(child->bs, begin); |
94 | +void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *iter, int64_t offset) | 45 | + } |
95 | { | ||
96 | - hbitmap_iter_init(&iter->hbi, iter->hbi.hb, sector_num); | ||
97 | + hbitmap_iter_init(&iter->hbi, iter->hbi.hb, offset >> BDRV_SECTOR_BITS); | ||
98 | } | 46 | } |
99 | 47 | ||
100 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap) | 48 | static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) |
101 | diff --git a/block/mirror.c b/block/mirror.c | 49 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) |
102 | index XXXXXXX..XXXXXXX 100644 | 50 | BdrvChild *child, *tmp; |
103 | --- a/block/mirror.c | 51 | bool waited; |
104 | +++ b/block/mirror.c | 52 | |
105 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | 53 | - /* Ensure any pending metadata writes are submitted to bs->file. */ |
106 | next_dirty = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | 54 | - bdrv_drain_invoke(bs, begin); |
107 | if (next_dirty > next_offset || next_dirty < 0) { | 55 | - |
108 | /* The bitmap iterator's cache is stale, refresh it */ | 56 | /* Wait for drained requests to finish */ |
109 | - bdrv_set_dirty_iter(s->dbi, next_offset >> BDRV_SECTOR_BITS); | 57 | waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); |
110 | + bdrv_set_dirty_iter(s->dbi, next_offset); | 58 | |
111 | next_dirty = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | 59 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) |
112 | } | 60 | bdrv_parent_drained_begin(bs); |
113 | assert(next_dirty == next_offset); | ||
114 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn mirror_run(void *opaque) | ||
115 | } | 61 | } |
116 | 62 | ||
117 | assert(!s->dbi); | 63 | + bdrv_drain_invoke(bs, true); |
118 | - s->dbi = bdrv_dirty_iter_new(s->dirty_bitmap, 0); | 64 | bdrv_drain_recurse(bs, true); |
119 | + s->dbi = bdrv_dirty_iter_new(s->dirty_bitmap); | 65 | } |
120 | for (;;) { | 66 | |
121 | uint64_t delay_ns = 0; | 67 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
122 | int64_t cnt, delta; | ||
123 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/block/qcow2-bitmap.c | ||
126 | +++ b/block/qcow2-bitmap.c | ||
127 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
128 | return NULL; | ||
129 | } | 68 | } |
130 | 69 | ||
131 | - dbi = bdrv_dirty_iter_new(bitmap, 0); | 70 | bdrv_parent_drained_end(bs); |
132 | + dbi = bdrv_dirty_iter_new(bitmap); | 71 | + bdrv_drain_invoke(bs, false); |
133 | buf = g_malloc(s->cluster_size); | 72 | bdrv_drain_recurse(bs, false); |
134 | limit = bytes_covered_by_bitmap_cluster(s, bitmap); | 73 | aio_enable_external(bdrv_get_aio_context(bs)); |
135 | sbc = limit >> BDRV_SECTOR_BITS; | 74 | } |
136 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 75 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
137 | break; | 76 | aio_context_acquire(aio_context); |
138 | } | 77 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
139 | 78 | if (aio_context == bdrv_get_aio_context(bs)) { | |
140 | - bdrv_set_dirty_iter(dbi, end); | 79 | + /* FIXME Calling this multiple times is wrong */ |
141 | + bdrv_set_dirty_iter(dbi, end * BDRV_SECTOR_SIZE); | 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); | ||
142 | } | 91 | } |
143 | |||
144 | *bitmap_table_size = tb_size; | ||
145 | -- | 92 | -- |
146 | 2.13.6 | 93 | 2.13.6 |
147 | 94 | ||
148 | 95 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 4 | ||
3 | Handle a 0-length block status request up front, with a uniform | 5 | This is obviously not right and results in nodes that stay drained even |
4 | return value claiming the area is not allocated. | 6 | after bdrv_drain_all_end(), which calls .bdrv_co_drain_begin() once per |
7 | node. | ||
5 | 8 | ||
6 | Most callers don't pass a length of 0 to bdrv_get_block_status() | 9 | Fix bdrv_drain_all_begin() to call the callback only once, too. |
7 | and friends; but it definitely happens with a 0-length read when | ||
8 | copy-on-read is enabled. While we could audit all callers to | ||
9 | ensure that they never make a 0-length request, and then assert | ||
10 | that fact, it was just as easy to fix things to always report | ||
11 | success (as long as the callers are careful to not go into an | ||
12 | infinite loop). However, we had inconsistent behavior on whether | ||
13 | the status is reported as allocated or defers to the backing | ||
14 | layer, depending on what callbacks the driver implements, and | ||
15 | possibly wasting quite a few CPU cycles to get to that answer. | ||
16 | Consistently reporting unallocated up front doesn't really hurt | ||
17 | anything, and makes it easier both for callers (0-length requests | ||
18 | now have well-defined behavior) and for drivers (drivers don't | ||
19 | have to deal with 0-length requests). | ||
20 | 10 | ||
21 | Signed-off-by: Eric Blake <eblake@redhat.com> | 11 | Cc: qemu-stable@nongnu.org |
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
22 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 13 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
23 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
24 | --- | 14 | --- |
25 | block/io.c | 4 ++++ | 15 | block/io.c | 3 +-- |
26 | 1 file changed, 4 insertions(+) | 16 | 1 file changed, 1 insertion(+), 2 deletions(-) |
27 | 17 | ||
28 | diff --git a/block/io.c b/block/io.c | 18 | diff --git a/block/io.c b/block/io.c |
29 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/block/io.c | 20 | --- a/block/io.c |
31 | +++ b/block/io.c | 21 | +++ b/block/io.c |
32 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs, | 22 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
33 | *pnum = 0; | 23 | aio_context_acquire(aio_context); |
34 | return BDRV_BLOCK_EOF; | 24 | bdrv_parent_drained_begin(bs); |
35 | } | 25 | aio_disable_external(aio_context); |
36 | + if (!nb_sectors) { | 26 | + bdrv_drain_invoke(bs, true); |
37 | + *pnum = 0; | 27 | aio_context_release(aio_context); |
38 | + return 0; | 28 | |
39 | + } | 29 | if (!g_slist_find(aio_ctxs, aio_context)) { |
40 | 30 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) | |
41 | n = total_sectors - sector_num; | 31 | aio_context_acquire(aio_context); |
42 | if (n < nb_sectors) { | 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 | } | ||
43 | -- | 39 | -- |
44 | 2.13.6 | 40 | 2.13.6 |
45 | 41 | ||
46 | 42 | diff view generated by jsdifflib |
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. | ||
4 | |||
1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
2 | --- | 8 | --- |
3 | tests/qemu-iotests/191 | 153 +++++++++ | 9 | tests/test-bdrv-drain.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | tests/qemu-iotests/191.out | 827 +++++++++++++++++++++++++++++++++++++++++++++ | 10 | tests/Makefile.include | 2 + |
5 | tests/qemu-iotests/group | 1 + | 11 | 2 files changed, 139 insertions(+) |
6 | 3 files changed, 981 insertions(+) | 12 | create mode 100644 tests/test-bdrv-drain.c |
7 | create mode 100755 tests/qemu-iotests/191 | ||
8 | create mode 100644 tests/qemu-iotests/191.out | ||
9 | 13 | ||
10 | diff --git a/tests/qemu-iotests/191 b/tests/qemu-iotests/191 | 14 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
11 | new file mode 100755 | ||
12 | index XXXXXXX..XXXXXXX | ||
13 | --- /dev/null | ||
14 | +++ b/tests/qemu-iotests/191 | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | +#!/bin/bash | ||
17 | +# | ||
18 | +# Test commit block job where top has two parents | ||
19 | +# | ||
20 | +# Copyright (C) 2017 Red Hat, Inc. | ||
21 | +# | ||
22 | +# This program is free software; you can redistribute it and/or modify | ||
23 | +# it under the terms of the GNU General Public License as published by | ||
24 | +# the Free Software Foundation; either version 2 of the License, or | ||
25 | +# (at your option) any later version. | ||
26 | +# | ||
27 | +# This program is distributed in the hope that it will be useful, | ||
28 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
29 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
30 | +# GNU General Public License for more details. | ||
31 | +# | ||
32 | +# You should have received a copy of the GNU General Public License | ||
33 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
34 | +# | ||
35 | + | ||
36 | +# creator | ||
37 | +owner=kwolf@redhat.com | ||
38 | + | ||
39 | +seq=`basename $0` | ||
40 | +echo "QA output created by $seq" | ||
41 | + | ||
42 | +here=`pwd` | ||
43 | +status=1 # failure is the default! | ||
44 | + | ||
45 | +MIG_SOCKET="${TEST_DIR}/migrate" | ||
46 | + | ||
47 | +_cleanup() | ||
48 | +{ | ||
49 | + rm -f "${TEST_IMG}.mid" | ||
50 | + rm -f "${TEST_IMG}.ovl2" | ||
51 | + rm -f "${TEST_IMG}.ovl3" | ||
52 | + _cleanup_test_img | ||
53 | + _cleanup_qemu | ||
54 | +} | ||
55 | +trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
56 | + | ||
57 | +# get standard environment, filters and checks | ||
58 | +. ./common.rc | ||
59 | +. ./common.filter | ||
60 | +. ./common.qemu | ||
61 | + | ||
62 | +_supported_fmt qcow2 | ||
63 | +_unsupported_imgopts compat=0.10 | ||
64 | +_supported_proto file | ||
65 | +_supported_os Linux | ||
66 | + | ||
67 | +size=64M | ||
68 | + | ||
69 | +echo | ||
70 | +echo === Preparing and starting VM === | ||
71 | +echo | ||
72 | + | ||
73 | +TEST_IMG="${TEST_IMG}.base" _make_test_img $size | ||
74 | +TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" | ||
75 | +_make_test_img -b "${TEST_IMG}.mid" | ||
76 | +TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" | ||
77 | + | ||
78 | +$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io | ||
79 | + | ||
80 | +qemu_comm_method="qmp" | ||
81 | +qmp_pretty="y" | ||
82 | + | ||
83 | +_launch_qemu \ | ||
84 | + -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \ | ||
85 | + -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \ | ||
86 | + -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \ | ||
87 | + -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid" | ||
88 | +h=$QEMU_HANDLE | ||
89 | +_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' | ||
90 | + | ||
91 | +echo | ||
92 | +echo === Perform commit job === | ||
93 | +echo | ||
94 | + | ||
95 | +_send_qemu_cmd $h \ | ||
96 | + "{ 'execute': 'block-commit', | ||
97 | + 'arguments': { 'job-id': 'commit0', | ||
98 | + 'device': 'top', | ||
99 | + 'base':'$TEST_IMG.base', | ||
100 | + 'top': '$TEST_IMG.mid' } }" \ | ||
101 | + "BLOCK_JOB_COMPLETED" | ||
102 | +_send_qemu_cmd $h "" "^}" | ||
103 | + | ||
104 | +echo | ||
105 | +echo === Check that both top and top2 point to base now === | ||
106 | +echo | ||
107 | + | ||
108 | +_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | | ||
109 | + _filter_generated_node_ids | ||
110 | + | ||
111 | +_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" | ||
112 | +wait=1 _cleanup_qemu | ||
113 | + | ||
114 | +_img_info | ||
115 | +TEST_IMG="$TEST_IMG.ovl2" _img_info | ||
116 | + | ||
117 | + | ||
118 | +echo | ||
119 | +echo === Preparing and starting VM with -drive === | ||
120 | +echo | ||
121 | + | ||
122 | +TEST_IMG="${TEST_IMG}.base" _make_test_img $size | ||
123 | +TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base" | ||
124 | +_make_test_img -b "${TEST_IMG}.mid" | ||
125 | +TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid" | ||
126 | +TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2" | ||
127 | + | ||
128 | +$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io | ||
129 | + | ||
130 | +qemu_comm_method="qmp" | ||
131 | +qmp_pretty="y" | ||
132 | + | ||
133 | +_launch_qemu \ | ||
134 | + -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \ | ||
135 | + -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid" | ||
136 | +h=$QEMU_HANDLE | ||
137 | +_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}' | ||
138 | + | ||
139 | +echo | ||
140 | +echo === Perform commit job === | ||
141 | +echo | ||
142 | + | ||
143 | +_send_qemu_cmd $h \ | ||
144 | + "{ 'execute': 'block-commit', | ||
145 | + 'arguments': { 'job-id': 'commit0', | ||
146 | + 'device': 'top', | ||
147 | + 'base':'$TEST_IMG.base', | ||
148 | + 'top': '$TEST_IMG.mid' } }" \ | ||
149 | + "BLOCK_JOB_COMPLETED" | ||
150 | +_send_qemu_cmd $h "" "^}" | ||
151 | + | ||
152 | +echo | ||
153 | +echo === Check that both top and top2 point to base now === | ||
154 | +echo | ||
155 | + | ||
156 | +_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" | | ||
157 | + _filter_generated_node_ids | ||
158 | + | ||
159 | +_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}" | ||
160 | +wait=1 _cleanup_qemu | ||
161 | + | ||
162 | +_img_info | ||
163 | +TEST_IMG="$TEST_IMG.ovl2" _img_info | ||
164 | + | ||
165 | +# success, all done | ||
166 | +echo "*** done" | ||
167 | +rm -f $seq.full | ||
168 | +status=0 | ||
169 | diff --git a/tests/qemu-iotests/191.out b/tests/qemu-iotests/191.out | ||
170 | new file mode 100644 | 15 | new file mode 100644 |
171 | index XXXXXXX..XXXXXXX | 16 | index XXXXXXX..XXXXXXX |
172 | --- /dev/null | 17 | --- /dev/null |
173 | +++ b/tests/qemu-iotests/191.out | 18 | +++ b/tests/test-bdrv-drain.c |
174 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
175 | +QA output created by 191 | 20 | +/* |
21 | + * Block node draining tests | ||
22 | + * | ||
23 | + * Copyright (c) 2017 Kevin Wolf <kwolf@redhat.com> | ||
24 | + * | ||
25 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
26 | + * of this software and associated documentation files (the "Software"), to deal | ||
27 | + * in the Software without restriction, including without limitation the rights | ||
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: | ||
31 | + * | ||
32 | + * The above copyright notice and this permission notice shall be included in | ||
33 | + * all copies or substantial portions of the Software. | ||
34 | + * | ||
35 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
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. | ||
42 | + */ | ||
176 | + | 43 | + |
177 | +=== Preparing and starting VM === | 44 | +#include "qemu/osdep.h" |
45 | +#include "block/block.h" | ||
46 | +#include "sysemu/block-backend.h" | ||
47 | +#include "qapi/error.h" | ||
178 | + | 48 | + |
179 | +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | 49 | +typedef struct BDRVTestState { |
180 | +Formatting 'TEST_DIR/t.IMGFMT.mid', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | 50 | + int drain_count; |
181 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.mid | 51 | +} BDRVTestState; |
182 | +Formatting 'TEST_DIR/t.IMGFMT.ovl2', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.mid | 52 | + |
183 | +wrote 65536/65536 bytes at offset 1048576 | 53 | +static void coroutine_fn bdrv_test_co_drain_begin(BlockDriverState *bs) |
184 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
185 | +{ | 54 | +{ |
186 | + "return": { | 55 | + BDRVTestState *s = bs->opaque; |
187 | + } | 56 | + s->drain_count++; |
188 | +} | 57 | +} |
189 | + | 58 | + |
190 | +=== Perform commit job === | 59 | +static void coroutine_fn bdrv_test_co_drain_end(BlockDriverState *bs) |
191 | + | ||
192 | +{ | 60 | +{ |
193 | + "return": { | 61 | + BDRVTestState *s = bs->opaque; |
194 | + } | 62 | + s->drain_count--; |
195 | +} | ||
196 | +{ | ||
197 | + "timestamp": { | ||
198 | + "seconds": TIMESTAMP, | ||
199 | + "microseconds": TIMESTAMP | ||
200 | + }, | ||
201 | + "event": "BLOCK_JOB_COMPLETED", | ||
202 | + "data": { | ||
203 | + "device": "commit0", | ||
204 | + "len": 67108864, | ||
205 | + "offset": 67108864, | ||
206 | + "speed": 0, | ||
207 | + "type": "commit" | ||
208 | + } | ||
209 | +} | 63 | +} |
210 | + | 64 | + |
211 | +=== Check that both top and top2 point to base now === | 65 | +static void bdrv_test_close(BlockDriverState *bs) |
212 | + | ||
213 | +{ | 66 | +{ |
214 | + "return": [ | 67 | + BDRVTestState *s = bs->opaque; |
215 | + { | 68 | + g_assert_cmpint(s->drain_count, >, 0); |
216 | + "iops_rd": 0, | ||
217 | + "detect_zeroes": "off", | ||
218 | + "image": { | ||
219 | + "backing-image": { | ||
220 | + "virtual-size": 67108864, | ||
221 | + "filename": "TEST_DIR/t.qcow2.base", | ||
222 | + "cluster-size": 65536, | ||
223 | + "format": "qcow2", | ||
224 | + "actual-size": 397312, | ||
225 | + "format-specific": { | ||
226 | + "type": "qcow2", | ||
227 | + "data": { | ||
228 | + "compat": "1.1", | ||
229 | + "lazy-refcounts": false, | ||
230 | + "refcount-bits": 16, | ||
231 | + "corrupt": false | ||
232 | + } | ||
233 | + }, | ||
234 | + "dirty-flag": false | ||
235 | + }, | ||
236 | + "backing-filename-format": "qcow2", | ||
237 | + "virtual-size": 67108864, | ||
238 | + "filename": "TEST_DIR/t.qcow2.ovl2", | ||
239 | + "cluster-size": 65536, | ||
240 | + "format": "qcow2", | ||
241 | + "actual-size": 200704, | ||
242 | + "format-specific": { | ||
243 | + "type": "qcow2", | ||
244 | + "data": { | ||
245 | + "compat": "1.1", | ||
246 | + "lazy-refcounts": false, | ||
247 | + "refcount-bits": 16, | ||
248 | + "corrupt": false | ||
249 | + } | ||
250 | + }, | ||
251 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
252 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
253 | + "dirty-flag": false | ||
254 | + }, | ||
255 | + "iops_wr": 0, | ||
256 | + "ro": false, | ||
257 | + "node-name": "top2", | ||
258 | + "backing_file_depth": 1, | ||
259 | + "drv": "qcow2", | ||
260 | + "iops": 0, | ||
261 | + "bps_wr": 0, | ||
262 | + "write_threshold": 0, | ||
263 | + "backing_file": "TEST_DIR/t.qcow2.base", | ||
264 | + "encrypted": false, | ||
265 | + "bps": 0, | ||
266 | + "bps_rd": 0, | ||
267 | + "cache": { | ||
268 | + "no-flush": false, | ||
269 | + "direct": false, | ||
270 | + "writeback": true | ||
271 | + }, | ||
272 | + "file": "TEST_DIR/t.qcow2.ovl2", | ||
273 | + "encryption_key_missing": false | ||
274 | + }, | ||
275 | + { | ||
276 | + "iops_rd": 0, | ||
277 | + "detect_zeroes": "off", | ||
278 | + "image": { | ||
279 | + "virtual-size": 197120, | ||
280 | + "filename": "TEST_DIR/t.qcow2.ovl2", | ||
281 | + "format": "file", | ||
282 | + "actual-size": 200704, | ||
283 | + "dirty-flag": false | ||
284 | + }, | ||
285 | + "iops_wr": 0, | ||
286 | + "ro": false, | ||
287 | + "node-name": "NODE_NAME", | ||
288 | + "backing_file_depth": 0, | ||
289 | + "drv": "file", | ||
290 | + "iops": 0, | ||
291 | + "bps_wr": 0, | ||
292 | + "write_threshold": 0, | ||
293 | + "encrypted": false, | ||
294 | + "bps": 0, | ||
295 | + "bps_rd": 0, | ||
296 | + "cache": { | ||
297 | + "no-flush": false, | ||
298 | + "direct": false, | ||
299 | + "writeback": true | ||
300 | + }, | ||
301 | + "file": "TEST_DIR/t.qcow2.ovl2", | ||
302 | + "encryption_key_missing": false | ||
303 | + }, | ||
304 | + { | ||
305 | + "iops_rd": 0, | ||
306 | + "detect_zeroes": "off", | ||
307 | + "image": { | ||
308 | + "backing-image": { | ||
309 | + "virtual-size": 67108864, | ||
310 | + "filename": "TEST_DIR/t.qcow2.base", | ||
311 | + "cluster-size": 65536, | ||
312 | + "format": "qcow2", | ||
313 | + "actual-size": 397312, | ||
314 | + "format-specific": { | ||
315 | + "type": "qcow2", | ||
316 | + "data": { | ||
317 | + "compat": "1.1", | ||
318 | + "lazy-refcounts": false, | ||
319 | + "refcount-bits": 16, | ||
320 | + "corrupt": false | ||
321 | + } | ||
322 | + }, | ||
323 | + "dirty-flag": false | ||
324 | + }, | ||
325 | + "backing-filename-format": "qcow2", | ||
326 | + "virtual-size": 67108864, | ||
327 | + "filename": "TEST_DIR/t.qcow2", | ||
328 | + "cluster-size": 65536, | ||
329 | + "format": "qcow2", | ||
330 | + "actual-size": 200704, | ||
331 | + "format-specific": { | ||
332 | + "type": "qcow2", | ||
333 | + "data": { | ||
334 | + "compat": "1.1", | ||
335 | + "lazy-refcounts": false, | ||
336 | + "refcount-bits": 16, | ||
337 | + "corrupt": false | ||
338 | + } | ||
339 | + }, | ||
340 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
341 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
342 | + "dirty-flag": false | ||
343 | + }, | ||
344 | + "iops_wr": 0, | ||
345 | + "ro": false, | ||
346 | + "node-name": "top", | ||
347 | + "backing_file_depth": 1, | ||
348 | + "drv": "qcow2", | ||
349 | + "iops": 0, | ||
350 | + "bps_wr": 0, | ||
351 | + "write_threshold": 0, | ||
352 | + "backing_file": "TEST_DIR/t.qcow2.base", | ||
353 | + "encrypted": false, | ||
354 | + "bps": 0, | ||
355 | + "bps_rd": 0, | ||
356 | + "cache": { | ||
357 | + "no-flush": false, | ||
358 | + "direct": false, | ||
359 | + "writeback": true | ||
360 | + }, | ||
361 | + "file": "TEST_DIR/t.qcow2", | ||
362 | + "encryption_key_missing": false | ||
363 | + }, | ||
364 | + { | ||
365 | + "iops_rd": 0, | ||
366 | + "detect_zeroes": "off", | ||
367 | + "image": { | ||
368 | + "virtual-size": 197120, | ||
369 | + "filename": "TEST_DIR/t.qcow2", | ||
370 | + "format": "file", | ||
371 | + "actual-size": 200704, | ||
372 | + "dirty-flag": false | ||
373 | + }, | ||
374 | + "iops_wr": 0, | ||
375 | + "ro": false, | ||
376 | + "node-name": "NODE_NAME", | ||
377 | + "backing_file_depth": 0, | ||
378 | + "drv": "file", | ||
379 | + "iops": 0, | ||
380 | + "bps_wr": 0, | ||
381 | + "write_threshold": 0, | ||
382 | + "encrypted": false, | ||
383 | + "bps": 0, | ||
384 | + "bps_rd": 0, | ||
385 | + "cache": { | ||
386 | + "no-flush": false, | ||
387 | + "direct": false, | ||
388 | + "writeback": true | ||
389 | + }, | ||
390 | + "file": "TEST_DIR/t.qcow2", | ||
391 | + "encryption_key_missing": false | ||
392 | + }, | ||
393 | + { | ||
394 | + "iops_rd": 0, | ||
395 | + "detect_zeroes": "off", | ||
396 | + "image": { | ||
397 | + "backing-image": { | ||
398 | + "virtual-size": 67108864, | ||
399 | + "filename": "TEST_DIR/t.qcow2.base", | ||
400 | + "cluster-size": 65536, | ||
401 | + "format": "qcow2", | ||
402 | + "actual-size": 397312, | ||
403 | + "format-specific": { | ||
404 | + "type": "qcow2", | ||
405 | + "data": { | ||
406 | + "compat": "1.1", | ||
407 | + "lazy-refcounts": false, | ||
408 | + "refcount-bits": 16, | ||
409 | + "corrupt": false | ||
410 | + } | ||
411 | + }, | ||
412 | + "dirty-flag": false | ||
413 | + }, | ||
414 | + "backing-filename-format": "qcow2", | ||
415 | + "virtual-size": 67108864, | ||
416 | + "filename": "TEST_DIR/t.qcow2.mid", | ||
417 | + "cluster-size": 65536, | ||
418 | + "format": "qcow2", | ||
419 | + "actual-size": 397312, | ||
420 | + "format-specific": { | ||
421 | + "type": "qcow2", | ||
422 | + "data": { | ||
423 | + "compat": "1.1", | ||
424 | + "lazy-refcounts": false, | ||
425 | + "refcount-bits": 16, | ||
426 | + "corrupt": false | ||
427 | + } | ||
428 | + }, | ||
429 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
430 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
431 | + "dirty-flag": false | ||
432 | + }, | ||
433 | + "iops_wr": 0, | ||
434 | + "ro": false, | ||
435 | + "node-name": "mid", | ||
436 | + "backing_file_depth": 1, | ||
437 | + "drv": "qcow2", | ||
438 | + "iops": 0, | ||
439 | + "bps_wr": 0, | ||
440 | + "write_threshold": 0, | ||
441 | + "backing_file": "TEST_DIR/t.qcow2.base", | ||
442 | + "encrypted": false, | ||
443 | + "bps": 0, | ||
444 | + "bps_rd": 0, | ||
445 | + "cache": { | ||
446 | + "no-flush": false, | ||
447 | + "direct": false, | ||
448 | + "writeback": true | ||
449 | + }, | ||
450 | + "file": "TEST_DIR/t.qcow2.mid", | ||
451 | + "encryption_key_missing": false | ||
452 | + }, | ||
453 | + { | ||
454 | + "iops_rd": 0, | ||
455 | + "detect_zeroes": "off", | ||
456 | + "image": { | ||
457 | + "virtual-size": 393216, | ||
458 | + "filename": "TEST_DIR/t.qcow2.mid", | ||
459 | + "format": "file", | ||
460 | + "actual-size": 397312, | ||
461 | + "dirty-flag": false | ||
462 | + }, | ||
463 | + "iops_wr": 0, | ||
464 | + "ro": false, | ||
465 | + "node-name": "NODE_NAME", | ||
466 | + "backing_file_depth": 0, | ||
467 | + "drv": "file", | ||
468 | + "iops": 0, | ||
469 | + "bps_wr": 0, | ||
470 | + "write_threshold": 0, | ||
471 | + "encrypted": false, | ||
472 | + "bps": 0, | ||
473 | + "bps_rd": 0, | ||
474 | + "cache": { | ||
475 | + "no-flush": false, | ||
476 | + "direct": false, | ||
477 | + "writeback": true | ||
478 | + }, | ||
479 | + "file": "TEST_DIR/t.qcow2.mid", | ||
480 | + "encryption_key_missing": false | ||
481 | + }, | ||
482 | + { | ||
483 | + "iops_rd": 0, | ||
484 | + "detect_zeroes": "off", | ||
485 | + "image": { | ||
486 | + "virtual-size": 67108864, | ||
487 | + "filename": "TEST_DIR/t.qcow2.base", | ||
488 | + "cluster-size": 65536, | ||
489 | + "format": "qcow2", | ||
490 | + "actual-size": 397312, | ||
491 | + "format-specific": { | ||
492 | + "type": "qcow2", | ||
493 | + "data": { | ||
494 | + "compat": "1.1", | ||
495 | + "lazy-refcounts": false, | ||
496 | + "refcount-bits": 16, | ||
497 | + "corrupt": false | ||
498 | + } | ||
499 | + }, | ||
500 | + "dirty-flag": false | ||
501 | + }, | ||
502 | + "iops_wr": 0, | ||
503 | + "ro": false, | ||
504 | + "node-name": "base", | ||
505 | + "backing_file_depth": 0, | ||
506 | + "drv": "qcow2", | ||
507 | + "iops": 0, | ||
508 | + "bps_wr": 0, | ||
509 | + "write_threshold": 0, | ||
510 | + "encrypted": false, | ||
511 | + "bps": 0, | ||
512 | + "bps_rd": 0, | ||
513 | + "cache": { | ||
514 | + "no-flush": false, | ||
515 | + "direct": false, | ||
516 | + "writeback": true | ||
517 | + }, | ||
518 | + "file": "TEST_DIR/t.qcow2.base", | ||
519 | + "encryption_key_missing": false | ||
520 | + }, | ||
521 | + { | ||
522 | + "iops_rd": 0, | ||
523 | + "detect_zeroes": "off", | ||
524 | + "image": { | ||
525 | + "virtual-size": 393216, | ||
526 | + "filename": "TEST_DIR/t.qcow2.base", | ||
527 | + "format": "file", | ||
528 | + "actual-size": 397312, | ||
529 | + "dirty-flag": false | ||
530 | + }, | ||
531 | + "iops_wr": 0, | ||
532 | + "ro": false, | ||
533 | + "node-name": "NODE_NAME", | ||
534 | + "backing_file_depth": 0, | ||
535 | + "drv": "file", | ||
536 | + "iops": 0, | ||
537 | + "bps_wr": 0, | ||
538 | + "write_threshold": 0, | ||
539 | + "encrypted": false, | ||
540 | + "bps": 0, | ||
541 | + "bps_rd": 0, | ||
542 | + "cache": { | ||
543 | + "no-flush": false, | ||
544 | + "direct": false, | ||
545 | + "writeback": true | ||
546 | + }, | ||
547 | + "file": "TEST_DIR/t.qcow2.base", | ||
548 | + "encryption_key_missing": false | ||
549 | + } | ||
550 | + ] | ||
551 | +} | ||
552 | +{ | ||
553 | + "return": { | ||
554 | + } | ||
555 | +} | ||
556 | +{ | ||
557 | + "timestamp": { | ||
558 | + "seconds": TIMESTAMP, | ||
559 | + "microseconds": TIMESTAMP | ||
560 | + }, | ||
561 | + "event": "SHUTDOWN", | ||
562 | + "data": { | ||
563 | + "guest": false | ||
564 | + } | ||
565 | +} | ||
566 | +image: TEST_DIR/t.IMGFMT | ||
567 | +file format: IMGFMT | ||
568 | +virtual size: 64M (67108864 bytes) | ||
569 | +cluster_size: 65536 | ||
570 | +backing file: TEST_DIR/t.IMGFMT.base | ||
571 | +backing file format: IMGFMT | ||
572 | +image: TEST_DIR/t.IMGFMT.ovl2 | ||
573 | +file format: IMGFMT | ||
574 | +virtual size: 64M (67108864 bytes) | ||
575 | +cluster_size: 65536 | ||
576 | +backing file: TEST_DIR/t.IMGFMT.base | ||
577 | +backing file format: IMGFMT | ||
578 | + | ||
579 | +=== Preparing and starting VM with -drive === | ||
580 | + | ||
581 | +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 | ||
582 | +Formatting 'TEST_DIR/t.IMGFMT.mid', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.base | ||
583 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.mid | ||
584 | +Formatting 'TEST_DIR/t.IMGFMT.ovl2', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.mid | ||
585 | +Formatting 'TEST_DIR/t.IMGFMT.ovl3', fmt=IMGFMT size=67108864 backing_file=TEST_DIR/t.IMGFMT.ovl2 | ||
586 | +wrote 65536/65536 bytes at offset 1048576 | ||
587 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
588 | +{ | ||
589 | + "return": { | ||
590 | + } | ||
591 | +} | 69 | +} |
592 | + | 70 | + |
593 | +=== Perform commit job === | 71 | +static int coroutine_fn bdrv_test_co_preadv(BlockDriverState *bs, |
72 | + uint64_t offset, uint64_t bytes, | ||
73 | + QEMUIOVector *qiov, int flags) | ||
74 | +{ | ||
75 | + /* We want this request to stay until the polling loop in drain waits for | ||
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); | ||
594 | + | 80 | + |
595 | +{ | 81 | + return 0; |
596 | + "return": { | ||
597 | + } | ||
598 | +} | ||
599 | +{ | ||
600 | + "timestamp": { | ||
601 | + "seconds": TIMESTAMP, | ||
602 | + "microseconds": TIMESTAMP | ||
603 | + }, | ||
604 | + "event": "BLOCK_JOB_COMPLETED", | ||
605 | + "data": { | ||
606 | + "device": "commit0", | ||
607 | + "len": 67108864, | ||
608 | + "offset": 67108864, | ||
609 | + "speed": 0, | ||
610 | + "type": "commit" | ||
611 | + } | ||
612 | +} | 82 | +} |
613 | + | 83 | + |
614 | +=== Check that both top and top2 point to base now === | 84 | +static BlockDriver bdrv_test = { |
85 | + .format_name = "test", | ||
86 | + .instance_size = sizeof(BDRVTestState), | ||
615 | + | 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) | ||
616 | +{ | 96 | +{ |
617 | + "return": [ | 97 | + int *aio_ret = opaque; |
618 | + { | 98 | + *aio_ret = ret; |
619 | + "iops_rd": 0, | ||
620 | + "detect_zeroes": "off", | ||
621 | + "image": { | ||
622 | + "backing-image": { | ||
623 | + "virtual-size": 67108864, | ||
624 | + "filename": "TEST_DIR/t.qcow2.base", | ||
625 | + "cluster-size": 65536, | ||
626 | + "format": "qcow2", | ||
627 | + "actual-size": 397312, | ||
628 | + "format-specific": { | ||
629 | + "type": "qcow2", | ||
630 | + "data": { | ||
631 | + "compat": "1.1", | ||
632 | + "lazy-refcounts": false, | ||
633 | + "refcount-bits": 16, | ||
634 | + "corrupt": false | ||
635 | + } | ||
636 | + }, | ||
637 | + "dirty-flag": false | ||
638 | + }, | ||
639 | + "backing-filename-format": "qcow2", | ||
640 | + "virtual-size": 67108864, | ||
641 | + "filename": "TEST_DIR/t.qcow2.ovl2", | ||
642 | + "cluster-size": 65536, | ||
643 | + "format": "qcow2", | ||
644 | + "actual-size": 200704, | ||
645 | + "format-specific": { | ||
646 | + "type": "qcow2", | ||
647 | + "data": { | ||
648 | + "compat": "1.1", | ||
649 | + "lazy-refcounts": false, | ||
650 | + "refcount-bits": 16, | ||
651 | + "corrupt": false | ||
652 | + } | ||
653 | + }, | ||
654 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
655 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
656 | + "dirty-flag": false | ||
657 | + }, | ||
658 | + "iops_wr": 0, | ||
659 | + "ro": true, | ||
660 | + "node-name": "NODE_NAME", | ||
661 | + "backing_file_depth": 1, | ||
662 | + "drv": "qcow2", | ||
663 | + "iops": 0, | ||
664 | + "bps_wr": 0, | ||
665 | + "write_threshold": 0, | ||
666 | + "backing_file": "TEST_DIR/t.qcow2.base", | ||
667 | + "encrypted": false, | ||
668 | + "bps": 0, | ||
669 | + "bps_rd": 0, | ||
670 | + "cache": { | ||
671 | + "no-flush": false, | ||
672 | + "direct": false, | ||
673 | + "writeback": true | ||
674 | + }, | ||
675 | + "file": "TEST_DIR/t.qcow2.ovl2", | ||
676 | + "encryption_key_missing": false | ||
677 | + }, | ||
678 | + { | ||
679 | + "iops_rd": 0, | ||
680 | + "detect_zeroes": "off", | ||
681 | + "image": { | ||
682 | + "virtual-size": 197120, | ||
683 | + "filename": "TEST_DIR/t.qcow2.ovl2", | ||
684 | + "format": "file", | ||
685 | + "actual-size": 200704, | ||
686 | + "dirty-flag": false | ||
687 | + }, | ||
688 | + "iops_wr": 0, | ||
689 | + "ro": true, | ||
690 | + "node-name": "NODE_NAME", | ||
691 | + "backing_file_depth": 0, | ||
692 | + "drv": "file", | ||
693 | + "iops": 0, | ||
694 | + "bps_wr": 0, | ||
695 | + "write_threshold": 0, | ||
696 | + "encrypted": false, | ||
697 | + "bps": 0, | ||
698 | + "bps_rd": 0, | ||
699 | + "cache": { | ||
700 | + "no-flush": false, | ||
701 | + "direct": false, | ||
702 | + "writeback": true | ||
703 | + }, | ||
704 | + "file": "TEST_DIR/t.qcow2.ovl2", | ||
705 | + "encryption_key_missing": false | ||
706 | + }, | ||
707 | + { | ||
708 | + "iops_rd": 0, | ||
709 | + "detect_zeroes": "off", | ||
710 | + "image": { | ||
711 | + "backing-image": { | ||
712 | + "backing-image": { | ||
713 | + "virtual-size": 67108864, | ||
714 | + "filename": "TEST_DIR/t.qcow2.base", | ||
715 | + "cluster-size": 65536, | ||
716 | + "format": "qcow2", | ||
717 | + "actual-size": 397312, | ||
718 | + "format-specific": { | ||
719 | + "type": "qcow2", | ||
720 | + "data": { | ||
721 | + "compat": "1.1", | ||
722 | + "lazy-refcounts": false, | ||
723 | + "refcount-bits": 16, | ||
724 | + "corrupt": false | ||
725 | + } | ||
726 | + }, | ||
727 | + "dirty-flag": false | ||
728 | + }, | ||
729 | + "backing-filename-format": "qcow2", | ||
730 | + "virtual-size": 67108864, | ||
731 | + "filename": "TEST_DIR/t.qcow2.ovl2", | ||
732 | + "cluster-size": 65536, | ||
733 | + "format": "qcow2", | ||
734 | + "actual-size": 200704, | ||
735 | + "format-specific": { | ||
736 | + "type": "qcow2", | ||
737 | + "data": { | ||
738 | + "compat": "1.1", | ||
739 | + "lazy-refcounts": false, | ||
740 | + "refcount-bits": 16, | ||
741 | + "corrupt": false | ||
742 | + } | ||
743 | + }, | ||
744 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
745 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
746 | + "dirty-flag": false | ||
747 | + }, | ||
748 | + "backing-filename-format": "qcow2", | ||
749 | + "virtual-size": 67108864, | ||
750 | + "filename": "TEST_DIR/t.qcow2.ovl3", | ||
751 | + "cluster-size": 65536, | ||
752 | + "format": "qcow2", | ||
753 | + "actual-size": 200704, | ||
754 | + "format-specific": { | ||
755 | + "type": "qcow2", | ||
756 | + "data": { | ||
757 | + "compat": "1.1", | ||
758 | + "lazy-refcounts": false, | ||
759 | + "refcount-bits": 16, | ||
760 | + "corrupt": false | ||
761 | + } | ||
762 | + }, | ||
763 | + "full-backing-filename": "TEST_DIR/t.qcow2.ovl2", | ||
764 | + "backing-filename": "TEST_DIR/t.qcow2.ovl2", | ||
765 | + "dirty-flag": false | ||
766 | + }, | ||
767 | + "iops_wr": 0, | ||
768 | + "ro": false, | ||
769 | + "node-name": "top2", | ||
770 | + "backing_file_depth": 2, | ||
771 | + "drv": "qcow2", | ||
772 | + "iops": 0, | ||
773 | + "bps_wr": 0, | ||
774 | + "write_threshold": 0, | ||
775 | + "backing_file": "TEST_DIR/t.qcow2.ovl2", | ||
776 | + "encrypted": false, | ||
777 | + "bps": 0, | ||
778 | + "bps_rd": 0, | ||
779 | + "cache": { | ||
780 | + "no-flush": false, | ||
781 | + "direct": false, | ||
782 | + "writeback": true | ||
783 | + }, | ||
784 | + "file": "TEST_DIR/t.qcow2.ovl3", | ||
785 | + "encryption_key_missing": false | ||
786 | + }, | ||
787 | + { | ||
788 | + "iops_rd": 0, | ||
789 | + "detect_zeroes": "off", | ||
790 | + "image": { | ||
791 | + "virtual-size": 197120, | ||
792 | + "filename": "TEST_DIR/t.qcow2.ovl3", | ||
793 | + "format": "file", | ||
794 | + "actual-size": 200704, | ||
795 | + "dirty-flag": false | ||
796 | + }, | ||
797 | + "iops_wr": 0, | ||
798 | + "ro": false, | ||
799 | + "node-name": "NODE_NAME", | ||
800 | + "backing_file_depth": 0, | ||
801 | + "drv": "file", | ||
802 | + "iops": 0, | ||
803 | + "bps_wr": 0, | ||
804 | + "write_threshold": 0, | ||
805 | + "encrypted": false, | ||
806 | + "bps": 0, | ||
807 | + "bps_rd": 0, | ||
808 | + "cache": { | ||
809 | + "no-flush": false, | ||
810 | + "direct": false, | ||
811 | + "writeback": true | ||
812 | + }, | ||
813 | + "file": "TEST_DIR/t.qcow2.ovl3", | ||
814 | + "encryption_key_missing": false | ||
815 | + }, | ||
816 | + { | ||
817 | + "iops_rd": 0, | ||
818 | + "detect_zeroes": "off", | ||
819 | + "image": { | ||
820 | + "virtual-size": 67108864, | ||
821 | + "filename": "TEST_DIR/t.qcow2.base", | ||
822 | + "cluster-size": 65536, | ||
823 | + "format": "qcow2", | ||
824 | + "actual-size": 397312, | ||
825 | + "format-specific": { | ||
826 | + "type": "qcow2", | ||
827 | + "data": { | ||
828 | + "compat": "1.1", | ||
829 | + "lazy-refcounts": false, | ||
830 | + "refcount-bits": 16, | ||
831 | + "corrupt": false | ||
832 | + } | ||
833 | + }, | ||
834 | + "dirty-flag": false | ||
835 | + }, | ||
836 | + "iops_wr": 0, | ||
837 | + "ro": true, | ||
838 | + "node-name": "NODE_NAME", | ||
839 | + "backing_file_depth": 0, | ||
840 | + "drv": "qcow2", | ||
841 | + "iops": 0, | ||
842 | + "bps_wr": 0, | ||
843 | + "write_threshold": 0, | ||
844 | + "encrypted": false, | ||
845 | + "bps": 0, | ||
846 | + "bps_rd": 0, | ||
847 | + "cache": { | ||
848 | + "no-flush": false, | ||
849 | + "direct": false, | ||
850 | + "writeback": true | ||
851 | + }, | ||
852 | + "file": "TEST_DIR/t.qcow2.base", | ||
853 | + "encryption_key_missing": false | ||
854 | + }, | ||
855 | + { | ||
856 | + "iops_rd": 0, | ||
857 | + "detect_zeroes": "off", | ||
858 | + "image": { | ||
859 | + "virtual-size": 393216, | ||
860 | + "filename": "TEST_DIR/t.qcow2.base", | ||
861 | + "format": "file", | ||
862 | + "actual-size": 397312, | ||
863 | + "dirty-flag": false | ||
864 | + }, | ||
865 | + "iops_wr": 0, | ||
866 | + "ro": true, | ||
867 | + "node-name": "NODE_NAME", | ||
868 | + "backing_file_depth": 0, | ||
869 | + "drv": "file", | ||
870 | + "iops": 0, | ||
871 | + "bps_wr": 0, | ||
872 | + "write_threshold": 0, | ||
873 | + "encrypted": false, | ||
874 | + "bps": 0, | ||
875 | + "bps_rd": 0, | ||
876 | + "cache": { | ||
877 | + "no-flush": false, | ||
878 | + "direct": false, | ||
879 | + "writeback": true | ||
880 | + }, | ||
881 | + "file": "TEST_DIR/t.qcow2.base", | ||
882 | + "encryption_key_missing": false | ||
883 | + }, | ||
884 | + { | ||
885 | + "iops_rd": 0, | ||
886 | + "detect_zeroes": "off", | ||
887 | + "image": { | ||
888 | + "backing-image": { | ||
889 | + "virtual-size": 67108864, | ||
890 | + "filename": "TEST_DIR/t.qcow2.base", | ||
891 | + "cluster-size": 65536, | ||
892 | + "format": "qcow2", | ||
893 | + "actual-size": 397312, | ||
894 | + "format-specific": { | ||
895 | + "type": "qcow2", | ||
896 | + "data": { | ||
897 | + "compat": "1.1", | ||
898 | + "lazy-refcounts": false, | ||
899 | + "refcount-bits": 16, | ||
900 | + "corrupt": false | ||
901 | + } | ||
902 | + }, | ||
903 | + "dirty-flag": false | ||
904 | + }, | ||
905 | + "backing-filename-format": "qcow2", | ||
906 | + "virtual-size": 67108864, | ||
907 | + "filename": "TEST_DIR/t.qcow2", | ||
908 | + "cluster-size": 65536, | ||
909 | + "format": "qcow2", | ||
910 | + "actual-size": 200704, | ||
911 | + "format-specific": { | ||
912 | + "type": "qcow2", | ||
913 | + "data": { | ||
914 | + "compat": "1.1", | ||
915 | + "lazy-refcounts": false, | ||
916 | + "refcount-bits": 16, | ||
917 | + "corrupt": false | ||
918 | + } | ||
919 | + }, | ||
920 | + "full-backing-filename": "TEST_DIR/t.qcow2.base", | ||
921 | + "backing-filename": "TEST_DIR/t.qcow2.base", | ||
922 | + "dirty-flag": false | ||
923 | + }, | ||
924 | + "iops_wr": 0, | ||
925 | + "ro": false, | ||
926 | + "node-name": "top", | ||
927 | + "backing_file_depth": 1, | ||
928 | + "drv": "qcow2", | ||
929 | + "iops": 0, | ||
930 | + "bps_wr": 0, | ||
931 | + "write_threshold": 0, | ||
932 | + "backing_file": "TEST_DIR/t.qcow2.base", | ||
933 | + "encrypted": false, | ||
934 | + "bps": 0, | ||
935 | + "bps_rd": 0, | ||
936 | + "cache": { | ||
937 | + "no-flush": false, | ||
938 | + "direct": false, | ||
939 | + "writeback": true | ||
940 | + }, | ||
941 | + "file": "TEST_DIR/t.qcow2", | ||
942 | + "encryption_key_missing": false | ||
943 | + }, | ||
944 | + { | ||
945 | + "iops_rd": 0, | ||
946 | + "detect_zeroes": "off", | ||
947 | + "image": { | ||
948 | + "virtual-size": 197120, | ||
949 | + "filename": "TEST_DIR/t.qcow2", | ||
950 | + "format": "file", | ||
951 | + "actual-size": 200704, | ||
952 | + "dirty-flag": false | ||
953 | + }, | ||
954 | + "iops_wr": 0, | ||
955 | + "ro": false, | ||
956 | + "node-name": "NODE_NAME", | ||
957 | + "backing_file_depth": 0, | ||
958 | + "drv": "file", | ||
959 | + "iops": 0, | ||
960 | + "bps_wr": 0, | ||
961 | + "write_threshold": 0, | ||
962 | + "encrypted": false, | ||
963 | + "bps": 0, | ||
964 | + "bps_rd": 0, | ||
965 | + "cache": { | ||
966 | + "no-flush": false, | ||
967 | + "direct": false, | ||
968 | + "writeback": true | ||
969 | + }, | ||
970 | + "file": "TEST_DIR/t.qcow2", | ||
971 | + "encryption_key_missing": false | ||
972 | + } | ||
973 | + ] | ||
974 | +} | 99 | +} |
100 | + | ||
101 | +static void test_drv_cb_drain_all(void) | ||
975 | +{ | 102 | +{ |
976 | + "return": { | 103 | + BlockBackend *blk; |
977 | + } | 104 | + BlockDriverState *bs; |
105 | + BDRVTestState *s; | ||
106 | + BlockAIOCB *acb; | ||
107 | + int aio_ret; | ||
108 | + | ||
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); | ||
978 | +} | 144 | +} |
145 | + | ||
146 | +int main(int argc, char **argv) | ||
979 | +{ | 147 | +{ |
980 | + "timestamp": { | 148 | + bdrv_init(); |
981 | + "seconds": TIMESTAMP, | 149 | + qemu_init_main_loop(&error_abort); |
982 | + "microseconds": TIMESTAMP | 150 | + |
983 | + }, | 151 | + g_test_init(&argc, &argv, NULL); |
984 | + "event": "SHUTDOWN", | 152 | + |
985 | + "data": { | 153 | + g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_all); |
986 | + "guest": false | 154 | + |
987 | + } | 155 | + return g_test_run(); |
988 | +} | 156 | +} |
989 | +image: TEST_DIR/t.IMGFMT | 157 | diff --git a/tests/Makefile.include b/tests/Makefile.include |
990 | +file format: IMGFMT | ||
991 | +virtual size: 64M (67108864 bytes) | ||
992 | +cluster_size: 65536 | ||
993 | +backing file: TEST_DIR/t.IMGFMT.base | ||
994 | +backing file format: IMGFMT | ||
995 | +image: TEST_DIR/t.IMGFMT.ovl2 | ||
996 | +file format: IMGFMT | ||
997 | +virtual size: 64M (67108864 bytes) | ||
998 | +cluster_size: 65536 | ||
999 | +backing file: TEST_DIR/t.IMGFMT.base | ||
1000 | +backing file format: IMGFMT | ||
1001 | +*** done | ||
1002 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
1003 | index XXXXXXX..XXXXXXX 100644 | 158 | index XXXXXXX..XXXXXXX 100644 |
1004 | --- a/tests/qemu-iotests/group | 159 | --- a/tests/Makefile.include |
1005 | +++ b/tests/qemu-iotests/group | 160 | +++ b/tests/Makefile.include |
1006 | @@ -XXX,XX +XXX,XX @@ | 161 | @@ -XXX,XX +XXX,XX @@ gcov-files-test-thread-pool-y = thread-pool.c |
1007 | 188 rw auto quick | 162 | gcov-files-test-hbitmap-y = util/hbitmap.c |
1008 | 189 rw auto | 163 | check-unit-y += tests/test-hbitmap$(EXESUF) |
1009 | 190 rw auto quick | 164 | gcov-files-test-hbitmap-y = blockjob.c |
1010 | +191 rw auto | 165 | +check-unit-y += tests/test-bdrv-drain$(EXESUF) |
1011 | 192 rw auto quick | 166 | check-unit-y += tests/test-blockjob$(EXESUF) |
1012 | 194 rw auto migration quick | 167 | check-unit-y += tests/test-blockjob-txn$(EXESUF) |
1013 | 195 rw auto quick | 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) | ||
1014 | -- | 177 | -- |
1015 | 2.13.6 | 178 | 2.13.6 |
1016 | 179 | ||
1017 | 180 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 3 | ||
3 | The only client of hbitmap_serialization_granularity() is dirty-bitmap's | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
4 | bdrv_dirty_bitmap_serialization_align(). Keeping the two names consistent | 5 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
5 | is worthwhile, and the shorter name is more representative of what the | 6 | --- |
6 | function returns (the required alignment to be used for start/count of | 7 | block/io.c | 12 ++++++------ |
7 | other serialization functions, where violating the alignment causes | 8 | 1 file changed, 6 insertions(+), 6 deletions(-) |
8 | assertion failures). | ||
9 | 9 | ||
10 | Signed-off-by: Eric Blake <eblake@redhat.com> | 10 | diff --git a/block/io.c b/block/io.c |
11 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | --- | ||
16 | include/qemu/hbitmap.h | 8 ++++---- | ||
17 | block/dirty-bitmap.c | 2 +- | ||
18 | tests/test-hbitmap.c | 10 +++++----- | ||
19 | util/hbitmap.c | 8 ++++---- | ||
20 | 4 files changed, 14 insertions(+), 14 deletions(-) | ||
21 | |||
22 | diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/qemu/hbitmap.h | 12 | --- a/block/io.c |
25 | +++ b/include/qemu/hbitmap.h | 13 | +++ b/block/io.c |
26 | @@ -XXX,XX +XXX,XX @@ bool hbitmap_get(const HBitmap *hb, uint64_t item); | 14 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) |
27 | bool hbitmap_is_serializable(const HBitmap *hb); | ||
28 | |||
29 | /** | ||
30 | - * hbitmap_serialization_granularity: | ||
31 | + * hbitmap_serialization_align: | ||
32 | * @hb: HBitmap to operate on. | ||
33 | * | ||
34 | - * Granularity of serialization chunks, used by other serialization functions. | ||
35 | - * For every chunk: | ||
36 | + * Required alignment of serialization chunks, used by other serialization | ||
37 | + * functions. For every chunk: | ||
38 | * 1. Chunk start should be aligned to this granularity. | ||
39 | * 2. Chunk size should be aligned too, except for last chunk (for which | ||
40 | * start + count == hb->size) | ||
41 | */ | ||
42 | -uint64_t hbitmap_serialization_granularity(const HBitmap *hb); | ||
43 | +uint64_t hbitmap_serialization_align(const HBitmap *hb); | ||
44 | |||
45 | /** | ||
46 | * hbitmap_serialization_size: | ||
47 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/block/dirty-bitmap.c | ||
50 | +++ b/block/dirty-bitmap.c | ||
51 | @@ -XXX,XX +XXX,XX @@ uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, | ||
52 | |||
53 | uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap) | ||
54 | { | ||
55 | - return hbitmap_serialization_granularity(bitmap->bitmap); | ||
56 | + return hbitmap_serialization_align(bitmap->bitmap); | ||
57 | } | ||
58 | |||
59 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, | ||
60 | diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/tests/test-hbitmap.c | ||
63 | +++ b/tests/test-hbitmap.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static void test_hbitmap_meta_one(TestHBitmapData *data, const void *unused) | ||
65 | } | 15 | } |
66 | } | 16 | } |
67 | 17 | ||
68 | -static void test_hbitmap_serialize_granularity(TestHBitmapData *data, | 18 | -static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) |
69 | - const void *unused) | 19 | +static bool bdrv_drain_recurse(BlockDriverState *bs) |
70 | +static void test_hbitmap_serialize_align(TestHBitmapData *data, | ||
71 | + const void *unused) | ||
72 | { | 20 | { |
73 | int r; | 21 | BdrvChild *child, *tmp; |
74 | 22 | bool waited; | |
75 | hbitmap_test_init(data, L3 * 2, 3); | 23 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) |
76 | g_assert(hbitmap_is_serializable(data->hb)); | 24 | */ |
77 | 25 | bdrv_ref(bs); | |
78 | - r = hbitmap_serialization_granularity(data->hb); | 26 | } |
79 | + r = hbitmap_serialization_align(data->hb); | 27 | - waited |= bdrv_drain_recurse(bs, begin); |
80 | g_assert_cmpint(r, ==, 64 << 3); | 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); | ||
81 | } | 38 | } |
82 | 39 | ||
83 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | 40 | void bdrv_drained_end(BlockDriverState *bs) |
84 | hbitmap_test_add("/hbitmap/meta/word", test_hbitmap_meta_word); | 41 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
85 | hbitmap_test_add("/hbitmap/meta/sector", test_hbitmap_meta_sector); | 42 | |
86 | 43 | bdrv_parent_drained_end(bs); | |
87 | - hbitmap_test_add("/hbitmap/serialize/granularity", | 44 | bdrv_drain_invoke(bs, false); |
88 | - test_hbitmap_serialize_granularity); | 45 | - bdrv_drain_recurse(bs, false); |
89 | + hbitmap_test_add("/hbitmap/serialize/align", | 46 | + bdrv_drain_recurse(bs); |
90 | + test_hbitmap_serialize_align); | 47 | aio_enable_external(bdrv_get_aio_context(bs)); |
91 | hbitmap_test_add("/hbitmap/serialize/basic", | ||
92 | test_hbitmap_serialize_basic); | ||
93 | hbitmap_test_add("/hbitmap/serialize/part", | ||
94 | diff --git a/util/hbitmap.c b/util/hbitmap.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/util/hbitmap.c | ||
97 | +++ b/util/hbitmap.c | ||
98 | @@ -XXX,XX +XXX,XX @@ bool hbitmap_is_serializable(const HBitmap *hb) | ||
99 | { | ||
100 | /* Every serialized chunk must be aligned to 64 bits so that endianness | ||
101 | * requirements can be fulfilled on both 64 bit and 32 bit hosts. | ||
102 | - * We have hbitmap_serialization_granularity() which converts this | ||
103 | + * We have hbitmap_serialization_align() which converts this | ||
104 | * alignment requirement from bitmap bits to items covered (e.g. sectors). | ||
105 | * That value is: | ||
106 | * 64 << hb->granularity | ||
107 | * Since this value must not exceed UINT64_MAX, hb->granularity must be | ||
108 | * less than 58 (== 64 - 6, where 6 is ld(64), i.e. 1 << 6 == 64). | ||
109 | * | ||
110 | - * In order for hbitmap_serialization_granularity() to always return a | ||
111 | + * In order for hbitmap_serialization_align() to always return a | ||
112 | * meaningful value, bitmaps that are to be serialized must have a | ||
113 | * granularity of less than 58. */ | ||
114 | |||
115 | @@ -XXX,XX +XXX,XX @@ bool hbitmap_get(const HBitmap *hb, uint64_t item) | ||
116 | return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0; | ||
117 | } | 48 | } |
118 | 49 | ||
119 | -uint64_t hbitmap_serialization_granularity(const HBitmap *hb) | 50 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
120 | +uint64_t hbitmap_serialization_align(const HBitmap *hb) | 51 | aio_context_acquire(aio_context); |
121 | { | 52 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
122 | assert(hbitmap_is_serializable(hb)); | 53 | if (aio_context == bdrv_get_aio_context(bs)) { |
123 | 54 | - waited |= bdrv_drain_recurse(bs, true); | |
124 | @@ -XXX,XX +XXX,XX @@ static void serialization_chunk(const HBitmap *hb, | 55 | + waited |= bdrv_drain_recurse(bs); |
125 | unsigned long **first_el, uint64_t *el_count) | 56 | } |
126 | { | 57 | } |
127 | uint64_t last = start + count - 1; | 58 | aio_context_release(aio_context); |
128 | - uint64_t gran = hbitmap_serialization_granularity(hb); | 59 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) |
129 | + uint64_t gran = hbitmap_serialization_align(hb); | 60 | aio_enable_external(aio_context); |
130 | 61 | bdrv_parent_drained_end(bs); | |
131 | assert((start & (gran - 1)) == 0); | 62 | bdrv_drain_invoke(bs, false); |
132 | assert((last >> hb->granularity) < hb->size); | 63 | - bdrv_drain_recurse(bs, false); |
64 | + bdrv_drain_recurse(bs); | ||
65 | aio_context_release(aio_context); | ||
66 | } | ||
67 | |||
133 | -- | 68 | -- |
134 | 2.13.6 | 69 | 2.13.6 |
135 | 70 | ||
136 | 71 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 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. | ||
2 | 4 | ||
3 | The variable is almost unused, and one of the two uses is actually | 5 | The bdrv_drain_recurse() calls were introduced in commit 481cad48e5e |
4 | uninitialized. | 6 | in order to call the .bdrv_co_drain_end() driver callback. This is now |
7 | done by a separate bdrv_drain_invoke() call. | ||
5 | 8 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 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> | ||
9 | --- | 12 | --- |
10 | tests/qemu-iotests/check | 5 +---- | 13 | block/io.c | 2 -- |
11 | tests/qemu-iotests/common.rc | 2 +- | 14 | 1 file changed, 2 deletions(-) |
12 | 2 files changed, 2 insertions(+), 5 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 16 | diff --git a/block/io.c b/block/io.c |
15 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tests/qemu-iotests/check | 18 | --- a/block/io.c |
17 | +++ b/tests/qemu-iotests/check | 19 | +++ b/block/io.c |
18 | @@ -XXX,XX +XXX,XX @@ interrupt=true | 20 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
19 | # by default don't output timestamps | 21 | |
20 | timestamp=${TIMESTAMP:=false} | 22 | bdrv_parent_drained_end(bs); |
21 | 23 | bdrv_drain_invoke(bs, false); | |
22 | -# generic initialization | 24 | - bdrv_drain_recurse(bs); |
23 | -iam=check | 25 | aio_enable_external(bdrv_get_aio_context(bs)); |
24 | - | ||
25 | _init_error() | ||
26 | { | ||
27 | - echo "$iam: $1" >&2 | ||
28 | + echo "check: $1" >&2 | ||
29 | exit 1 | ||
30 | } | 26 | } |
31 | 27 | ||
32 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | 28 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) |
33 | index XXXXXXX..XXXXXXX 100644 | 29 | aio_enable_external(aio_context); |
34 | --- a/tests/qemu-iotests/common.rc | 30 | bdrv_parent_drained_end(bs); |
35 | +++ b/tests/qemu-iotests/common.rc | 31 | bdrv_drain_invoke(bs, false); |
36 | @@ -XXX,XX +XXX,XX @@ poke_file() | 32 | - bdrv_drain_recurse(bs); |
37 | 33 | aio_context_release(aio_context); | |
38 | if ! . ./common.config | 34 | } |
39 | then | ||
40 | - echo "$iam: failed to source common.config" | ||
41 | + echo "$0: failed to source common.config" | ||
42 | exit 1 | ||
43 | fi | ||
44 | 35 | ||
45 | -- | 36 | -- |
46 | 2.13.6 | 37 | 2.13.6 |
47 | 38 | ||
48 | 39 | diff view generated by jsdifflib |
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | 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. | ||
2 | 4 | ||
3 | Make the crypto driver implement the bdrv_co_preadv|pwritev | 5 | The correct order is to keep children only drained when their parents |
4 | callbacks, and also use bdrv_co_preadv|pwritev for I/O | 6 | are also drained. This means that at the start of a drained section, the |
5 | with the protocol driver beneath. This replaces sector based | 7 | AioContext needs to be drained first, the parents second and only then |
6 | I/O with byte based I/O, and allows us to stop assuming the | 8 | the children. The correct order for the end of a drained section is the |
7 | physical sector size matches the encryption sector size. | 9 | opposite. |
8 | 10 | ||
9 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | 11 | This patch changes the three other functions to follow the example of |
10 | Message-id: 20170927125340.12360-5-berrange@redhat.com | 12 | bdrv_drained_begin(), which is the only one that got it right. |
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | 13 | |
12 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 14 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
13 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 16 | --- |
15 | block/crypto.c | 106 +++++++++++++++++++++++++++++---------------------------- | 17 | block/io.c | 12 ++++++++---- |
16 | 1 file changed, 54 insertions(+), 52 deletions(-) | 18 | 1 file changed, 8 insertions(+), 4 deletions(-) |
17 | 19 | ||
18 | diff --git a/block/crypto.c b/block/crypto.c | 20 | diff --git a/block/io.c b/block/io.c |
19 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/block/crypto.c | 22 | --- a/block/io.c |
21 | +++ b/block/crypto.c | 23 | +++ b/block/io.c |
22 | @@ -XXX,XX +XXX,XX @@ static void block_crypto_close(BlockDriverState *bs) | 24 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) |
23 | #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) | 25 | return; |
24 | |||
25 | static coroutine_fn int | ||
26 | -block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
27 | - int remaining_sectors, QEMUIOVector *qiov) | ||
28 | +block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
29 | + QEMUIOVector *qiov, int flags) | ||
30 | { | ||
31 | BlockCrypto *crypto = bs->opaque; | ||
32 | - int cur_nr_sectors; /* number of sectors in current iteration */ | ||
33 | + uint64_t cur_bytes; /* number of bytes in current iteration */ | ||
34 | uint64_t bytes_done = 0; | ||
35 | uint8_t *cipher_data = NULL; | ||
36 | QEMUIOVector hd_qiov; | ||
37 | int ret = 0; | ||
38 | - uint64_t payload_offset = | ||
39 | - qcrypto_block_get_payload_offset(crypto->block) / 512; | ||
40 | - assert(payload_offset < (INT64_MAX / 512)); | ||
41 | + uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | ||
42 | + uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block); | ||
43 | + uint64_t sector_num = offset / sector_size; | ||
44 | + | ||
45 | + assert(!flags); | ||
46 | + assert(payload_offset < INT64_MAX); | ||
47 | + assert(QEMU_IS_ALIGNED(offset, sector_size)); | ||
48 | + assert(QEMU_IS_ALIGNED(bytes, sector_size)); | ||
49 | |||
50 | qemu_iovec_init(&hd_qiov, qiov->niov); | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
53 | goto cleanup; | ||
54 | } | 26 | } |
55 | 27 | ||
56 | - while (remaining_sectors) { | 28 | + /* Stop things in parent-to-child order */ |
57 | - cur_nr_sectors = remaining_sectors; | 29 | if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { |
58 | - | 30 | aio_disable_external(bdrv_get_aio_context(bs)); |
59 | - if (cur_nr_sectors > (BLOCK_CRYPTO_MAX_IO_SIZE / 512)) { | 31 | bdrv_parent_drained_begin(bs); |
60 | - cur_nr_sectors = (BLOCK_CRYPTO_MAX_IO_SIZE / 512); | 32 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
61 | - } | 33 | return; |
62 | + while (bytes) { | ||
63 | + cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE); | ||
64 | |||
65 | qemu_iovec_reset(&hd_qiov); | ||
66 | - qemu_iovec_add(&hd_qiov, cipher_data, cur_nr_sectors * 512); | ||
67 | + qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes); | ||
68 | |||
69 | - ret = bdrv_co_readv(bs->file, | ||
70 | - payload_offset + sector_num, | ||
71 | - cur_nr_sectors, &hd_qiov); | ||
72 | + ret = bdrv_co_preadv(bs->file, payload_offset + offset + bytes_done, | ||
73 | + cur_bytes, &hd_qiov, 0); | ||
74 | if (ret < 0) { | ||
75 | goto cleanup; | ||
76 | } | ||
77 | |||
78 | - if (qcrypto_block_decrypt(crypto->block, | ||
79 | - sector_num, | ||
80 | - cipher_data, cur_nr_sectors * 512, | ||
81 | - NULL) < 0) { | ||
82 | + if (qcrypto_block_decrypt(crypto->block, sector_num, cipher_data, | ||
83 | + cur_bytes, NULL) < 0) { | ||
84 | ret = -EIO; | ||
85 | goto cleanup; | ||
86 | } | ||
87 | |||
88 | - qemu_iovec_from_buf(qiov, bytes_done, | ||
89 | - cipher_data, cur_nr_sectors * 512); | ||
90 | + qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes); | ||
91 | |||
92 | - remaining_sectors -= cur_nr_sectors; | ||
93 | - sector_num += cur_nr_sectors; | ||
94 | - bytes_done += cur_nr_sectors * 512; | ||
95 | + sector_num += cur_bytes / sector_size; | ||
96 | + bytes -= cur_bytes; | ||
97 | + bytes_done += cur_bytes; | ||
98 | } | 34 | } |
99 | 35 | ||
100 | cleanup: | 36 | - bdrv_parent_drained_end(bs); |
101 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | 37 | + /* Re-enable things in child-to-parent order */ |
102 | 38 | bdrv_drain_invoke(bs, false); | |
103 | 39 | + bdrv_parent_drained_end(bs); | |
104 | static coroutine_fn int | 40 | aio_enable_external(bdrv_get_aio_context(bs)); |
105 | -block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | 41 | } |
106 | - int remaining_sectors, QEMUIOVector *qiov) | 42 | |
107 | +block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | 43 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
108 | + QEMUIOVector *qiov, int flags) | 44 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
109 | { | 45 | AioContext *aio_context = bdrv_get_aio_context(bs); |
110 | BlockCrypto *crypto = bs->opaque; | 46 | |
111 | - int cur_nr_sectors; /* number of sectors in current iteration */ | 47 | + /* Stop things in parent-to-child order */ |
112 | + uint64_t cur_bytes; /* number of bytes in current iteration */ | 48 | aio_context_acquire(aio_context); |
113 | uint64_t bytes_done = 0; | 49 | - bdrv_parent_drained_begin(bs); |
114 | uint8_t *cipher_data = NULL; | 50 | aio_disable_external(aio_context); |
115 | QEMUIOVector hd_qiov; | 51 | + bdrv_parent_drained_begin(bs); |
116 | int ret = 0; | 52 | bdrv_drain_invoke(bs, true); |
117 | - uint64_t payload_offset = | 53 | aio_context_release(aio_context); |
118 | - qcrypto_block_get_payload_offset(crypto->block) / 512; | 54 | |
119 | - assert(payload_offset < (INT64_MAX / 512)); | 55 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) |
120 | + uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | 56 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
121 | + uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block); | 57 | AioContext *aio_context = bdrv_get_aio_context(bs); |
122 | + uint64_t sector_num = offset / sector_size; | 58 | |
123 | + | 59 | + /* Re-enable things in child-to-parent order */ |
124 | + assert(!flags); | 60 | aio_context_acquire(aio_context); |
125 | + assert(payload_offset < INT64_MAX); | 61 | - aio_enable_external(aio_context); |
126 | + assert(QEMU_IS_ALIGNED(offset, sector_size)); | 62 | - bdrv_parent_drained_end(bs); |
127 | + assert(QEMU_IS_ALIGNED(bytes, sector_size)); | 63 | bdrv_drain_invoke(bs, false); |
128 | 64 | + bdrv_parent_drained_end(bs); | |
129 | qemu_iovec_init(&hd_qiov, qiov->niov); | 65 | + aio_enable_external(aio_context); |
130 | 66 | aio_context_release(aio_context); | |
131 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
132 | goto cleanup; | ||
133 | } | 67 | } |
134 | 68 | ||
135 | - while (remaining_sectors) { | ||
136 | - cur_nr_sectors = remaining_sectors; | ||
137 | + while (bytes) { | ||
138 | + cur_bytes = MIN(bytes, BLOCK_CRYPTO_MAX_IO_SIZE); | ||
139 | |||
140 | - if (cur_nr_sectors > (BLOCK_CRYPTO_MAX_IO_SIZE / 512)) { | ||
141 | - cur_nr_sectors = (BLOCK_CRYPTO_MAX_IO_SIZE / 512); | ||
142 | - } | ||
143 | - | ||
144 | - qemu_iovec_to_buf(qiov, bytes_done, | ||
145 | - cipher_data, cur_nr_sectors * 512); | ||
146 | + qemu_iovec_to_buf(qiov, bytes_done, cipher_data, cur_bytes); | ||
147 | |||
148 | - if (qcrypto_block_encrypt(crypto->block, | ||
149 | - sector_num, | ||
150 | - cipher_data, cur_nr_sectors * 512, | ||
151 | - NULL) < 0) { | ||
152 | + if (qcrypto_block_encrypt(crypto->block, sector_num, cipher_data, | ||
153 | + cur_bytes, NULL) < 0) { | ||
154 | ret = -EIO; | ||
155 | goto cleanup; | ||
156 | } | ||
157 | |||
158 | qemu_iovec_reset(&hd_qiov); | ||
159 | - qemu_iovec_add(&hd_qiov, cipher_data, cur_nr_sectors * 512); | ||
160 | + qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes); | ||
161 | |||
162 | - ret = bdrv_co_writev(bs->file, | ||
163 | - payload_offset + sector_num, | ||
164 | - cur_nr_sectors, &hd_qiov); | ||
165 | + ret = bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_done, | ||
166 | + cur_bytes, &hd_qiov, 0); | ||
167 | if (ret < 0) { | ||
168 | goto cleanup; | ||
169 | } | ||
170 | |||
171 | - remaining_sectors -= cur_nr_sectors; | ||
172 | - sector_num += cur_nr_sectors; | ||
173 | - bytes_done += cur_nr_sectors * 512; | ||
174 | + sector_num += cur_bytes / sector_size; | ||
175 | + bytes -= cur_bytes; | ||
176 | + bytes_done += cur_bytes; | ||
177 | } | ||
178 | |||
179 | cleanup: | ||
180 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | +static void block_crypto_refresh_limits(BlockDriverState *bs, Error **errp) | ||
185 | +{ | ||
186 | + BlockCrypto *crypto = bs->opaque; | ||
187 | + uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | ||
188 | + bs->bl.request_alignment = sector_size; /* No sub-sector I/O */ | ||
189 | +} | ||
190 | + | ||
191 | |||
192 | static int64_t block_crypto_getlength(BlockDriverState *bs) | ||
193 | { | ||
194 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_crypto_luks = { | ||
195 | .bdrv_truncate = block_crypto_truncate, | ||
196 | .create_opts = &block_crypto_create_opts_luks, | ||
197 | |||
198 | - .bdrv_co_readv = block_crypto_co_readv, | ||
199 | - .bdrv_co_writev = block_crypto_co_writev, | ||
200 | + .bdrv_refresh_limits = block_crypto_refresh_limits, | ||
201 | + .bdrv_co_preadv = block_crypto_co_preadv, | ||
202 | + .bdrv_co_pwritev = block_crypto_co_pwritev, | ||
203 | .bdrv_getlength = block_crypto_getlength, | ||
204 | .bdrv_get_info = block_crypto_get_info_luks, | ||
205 | .bdrv_get_specific_info = block_crypto_get_specific_info_luks, | ||
206 | -- | 69 | -- |
207 | 2.13.6 | 70 | 2.13.6 |
208 | 71 | ||
209 | 72 | diff view generated by jsdifflib |
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | 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. | ||
2 | 5 | ||
3 | While current encryption schemes all have a fixed sector size of | 6 | Dropping the first locking from hmp_qemu_io() fixes the problem. |
4 | 512 bytes, this is not guaranteed to be the case in future. Expose | ||
5 | the sector size in the APIs so the block layer can remove assumptions | ||
6 | about fixed 512 byte sectors. | ||
7 | 7 | ||
8 | Reviewed-by: Max Reitz <mreitz@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | 9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
10 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
11 | Message-id: 20170927125340.12360-3-berrange@redhat.com | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | --- | 10 | --- |
14 | crypto/blockpriv.h | 1 + | 11 | hmp.c | 6 ------ |
15 | include/crypto/block.h | 15 +++++++++++++++ | 12 | 1 file changed, 6 deletions(-) |
16 | crypto/block-luks.c | 6 ++++-- | ||
17 | crypto/block-qcow.c | 1 + | ||
18 | crypto/block.c | 6 ++++++ | ||
19 | 5 files changed, 27 insertions(+), 2 deletions(-) | ||
20 | 13 | ||
21 | diff --git a/crypto/blockpriv.h b/crypto/blockpriv.h | 14 | diff --git a/hmp.c b/hmp.c |
22 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/crypto/blockpriv.h | 16 | --- a/hmp.c |
24 | +++ b/crypto/blockpriv.h | 17 | +++ b/hmp.c |
25 | @@ -XXX,XX +XXX,XX @@ struct QCryptoBlock { | 18 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
26 | QCryptoHashAlgorithm kdfhash; | 19 | { |
27 | size_t niv; | 20 | BlockBackend *blk; |
28 | uint64_t payload_offset; /* In bytes */ | 21 | BlockBackend *local_blk = NULL; |
29 | + uint64_t sector_size; /* In bytes */ | 22 | - AioContext *aio_context; |
30 | }; | 23 | const char* device = qdict_get_str(qdict, "device"); |
31 | 24 | const char* command = qdict_get_str(qdict, "command"); | |
32 | struct QCryptoBlockDriver { | 25 | Error *err = NULL; |
33 | diff --git a/include/crypto/block.h b/include/crypto/block.h | 26 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/crypto/block.h | ||
36 | +++ b/include/crypto/block.h | ||
37 | @@ -XXX,XX +XXX,XX @@ QCryptoHashAlgorithm qcrypto_block_get_kdf_hash(QCryptoBlock *block); | ||
38 | uint64_t qcrypto_block_get_payload_offset(QCryptoBlock *block); | ||
39 | |||
40 | /** | ||
41 | + * qcrypto_block_get_sector_size: | ||
42 | + * @block: the block encryption object | ||
43 | + * | ||
44 | + * Get the size of sectors used for payload encryption. A new | ||
45 | + * IV is used at the start of each sector. The encryption | ||
46 | + * sector size is not required to match the sector size of the | ||
47 | + * underlying storage. For example LUKS will always use a 512 | ||
48 | + * byte sector size, even if the volume is on a disk with 4k | ||
49 | + * sectors. | ||
50 | + * | ||
51 | + * Returns: the sector in bytes | ||
52 | + */ | ||
53 | +uint64_t qcrypto_block_get_sector_size(QCryptoBlock *block); | ||
54 | + | ||
55 | +/** | ||
56 | * qcrypto_block_free: | ||
57 | * @block: the block encryption object | ||
58 | * | ||
59 | diff --git a/crypto/block-luks.c b/crypto/block-luks.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/crypto/block-luks.c | ||
62 | +++ b/crypto/block-luks.c | ||
63 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_open(QCryptoBlock *block, | ||
64 | } | 27 | } |
65 | } | 28 | } |
66 | 29 | ||
67 | + block->sector_size = QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; | 30 | - aio_context = blk_get_aio_context(blk); |
68 | block->payload_offset = luks->header.payload_offset * | 31 | - aio_context_acquire(aio_context); |
69 | - QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; | 32 | - |
70 | + block->sector_size; | 33 | /* |
71 | 34 | * Notably absent: Proper permission management. This is sad, but it seems | |
72 | luks->cipher_alg = cipheralg; | 35 | * almost impossible to achieve without changing the semantics and thereby |
73 | luks->cipher_mode = ciphermode; | 36 | @@ -XXX,XX +XXX,XX @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) |
74 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_luks_create(QCryptoBlock *block, | 37 | */ |
75 | QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)) * | 38 | qemuio_command(blk, command); |
76 | QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS); | 39 | |
77 | 40 | - aio_context_release(aio_context); | |
78 | + block->sector_size = QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; | 41 | - |
79 | block->payload_offset = luks->header.payload_offset * | 42 | fail: |
80 | - QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; | 43 | blk_unref(local_blk); |
81 | + block->sector_size; | 44 | hmp_handle_error(mon, &err); |
82 | |||
83 | /* Reserve header space to match payload offset */ | ||
84 | initfunc(block, block->payload_offset, opaque, &local_err); | ||
85 | diff --git a/crypto/block-qcow.c b/crypto/block-qcow.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/crypto/block-qcow.c | ||
88 | +++ b/crypto/block-qcow.c | ||
89 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_qcow_init(QCryptoBlock *block, | ||
90 | goto fail; | ||
91 | } | ||
92 | |||
93 | + block->sector_size = QCRYPTO_BLOCK_QCOW_SECTOR_SIZE; | ||
94 | block->payload_offset = 0; | ||
95 | |||
96 | return 0; | ||
97 | diff --git a/crypto/block.c b/crypto/block.c | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/crypto/block.c | ||
100 | +++ b/crypto/block.c | ||
101 | @@ -XXX,XX +XXX,XX @@ uint64_t qcrypto_block_get_payload_offset(QCryptoBlock *block) | ||
102 | } | ||
103 | |||
104 | |||
105 | +uint64_t qcrypto_block_get_sector_size(QCryptoBlock *block) | ||
106 | +{ | ||
107 | + return block->sector_size; | ||
108 | +} | ||
109 | + | ||
110 | + | ||
111 | void qcrypto_block_free(QCryptoBlock *block) | ||
112 | { | ||
113 | if (!block) { | ||
114 | -- | 45 | -- |
115 | 2.13.6 | 46 | 2.13.6 |
116 | 47 | ||
117 | 48 | diff view generated by jsdifflib |
1 | From: Pavel Butsykin <pbutsykin@virtuozzo.com> | 1 | From: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> |
---|---|---|---|
2 | 2 | ||
3 | Now after shrinking the image, at the end of the image file, there might be a | 3 | Since bdrv_co_preadv does all neccessary checks including |
4 | tail that probably will never be used. So we can find the last used cluster and | 4 | reading after the end of the backing file, avoid duplication |
5 | cut the tail. | 5 | of verification before bdrv_co_preadv call. |
6 | 6 | ||
7 | Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> | 7 | Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com> |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
9 | Message-id: 20170929121613.25997-3-pbutsykin@virtuozzo.com | 9 | Reviewed-by: Eric Blake <eblake@redhat.com> |
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | --- | 11 | --- |
12 | block/qcow2.h | 1 + | 12 | block/qcow2.h | 3 --- |
13 | block/qcow2-refcount.c | 22 ++++++++++++++++++++++ | 13 | block/qcow2.c | 51 ++++++++------------------------------------------- |
14 | block/qcow2.c | 23 +++++++++++++++++++++++ | 14 | 2 files changed, 8 insertions(+), 46 deletions(-) |
15 | 3 files changed, 46 insertions(+) | ||
16 | 15 | ||
17 | diff --git a/block/qcow2.h b/block/qcow2.h | 16 | diff --git a/block/qcow2.h b/block/qcow2.h |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/qcow2.h | 18 | --- a/block/qcow2.h |
20 | +++ b/block/qcow2.h | 19 | +++ b/block/qcow2.h |
21 | @@ -XXX,XX +XXX,XX @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, | 20 | @@ -XXX,XX +XXX,XX @@ uint32_t offset_to_reftable_index(BDRVQcow2State *s, uint64_t offset) |
22 | BlockDriverAmendStatusCB *status_cb, | ||
23 | void *cb_opaque, Error **errp); | ||
24 | int qcow2_shrink_reftable(BlockDriverState *bs); | ||
25 | +int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); | ||
26 | |||
27 | /* qcow2-cluster.c functions */ | ||
28 | int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, | ||
29 | diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/block/qcow2-refcount.c | ||
32 | +++ b/block/qcow2-refcount.c | ||
33 | @@ -XXX,XX +XXX,XX @@ out: | ||
34 | g_free(reftable_tmp); | ||
35 | return ret; | ||
36 | } | 21 | } |
37 | + | 22 | |
38 | +int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size) | 23 | /* qcow2.c functions */ |
39 | +{ | 24 | -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, |
40 | + BDRVQcow2State *s = bs->opaque; | 25 | - int64_t sector_num, int nb_sectors); |
41 | + int64_t i; | 26 | - |
42 | + | 27 | int64_t qcow2_refcount_metadata_size(int64_t clusters, size_t cluster_size, |
43 | + for (i = size_to_clusters(s, size) - 1; i >= 0; i--) { | 28 | int refcount_order, bool generous_increase, |
44 | + uint64_t refcount; | 29 | uint64_t *refblock_count); |
45 | + int ret = qcow2_get_refcount(bs, i, &refcount); | ||
46 | + if (ret < 0) { | ||
47 | + fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n", | ||
48 | + i, strerror(-ret)); | ||
49 | + return ret; | ||
50 | + } | ||
51 | + if (refcount > 0) { | ||
52 | + return i; | ||
53 | + } | ||
54 | + } | ||
55 | + qcow2_signal_corruption(bs, true, -1, -1, | ||
56 | + "There are no references in the refcount table."); | ||
57 | + return -EIO; | ||
58 | +} | ||
59 | diff --git a/block/qcow2.c b/block/qcow2.c | 30 | diff --git a/block/qcow2.c b/block/qcow2.c |
60 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/block/qcow2.c | 32 | --- a/block/qcow2.c |
62 | +++ b/block/qcow2.c | 33 | +++ b/block/qcow2.c |
63 | @@ -XXX,XX +XXX,XX @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, | 34 | @@ -XXX,XX +XXX,XX @@ static int64_t coroutine_fn qcow2_co_get_block_status(BlockDriverState *bs, |
64 | new_l1_size = size_to_l1(s, offset); | 35 | return status; |
65 | 36 | } | |
66 | if (offset < old_length) { | 37 | |
67 | + int64_t last_cluster, old_file_size; | 38 | -/* handle reading after the end of the backing file */ |
68 | if (prealloc != PREALLOC_MODE_OFF) { | 39 | -int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, |
69 | error_setg(errp, | 40 | - int64_t offset, int bytes) |
70 | "Preallocation can't be used for shrinking an image"); | 41 | -{ |
71 | @@ -XXX,XX +XXX,XX @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, | 42 | - uint64_t bs_size = bs->total_sectors * BDRV_SECTOR_SIZE; |
72 | "Failed to discard unused refblocks"); | 43 | - int n1; |
73 | return ret; | 44 | - |
74 | } | 45 | - if ((offset + bytes) <= bs_size) { |
75 | + | 46 | - return bytes; |
76 | + old_file_size = bdrv_getlength(bs->file->bs); | 47 | - } |
77 | + if (old_file_size < 0) { | 48 | - |
78 | + error_setg_errno(errp, -old_file_size, | 49 | - if (offset >= bs_size) { |
79 | + "Failed to inquire current file length"); | 50 | - n1 = 0; |
80 | + return old_file_size; | 51 | - } else { |
81 | + } | 52 | - n1 = bs_size - offset; |
82 | + last_cluster = qcow2_get_last_cluster(bs, old_file_size); | 53 | - } |
83 | + if (last_cluster < 0) { | 54 | - |
84 | + error_setg_errno(errp, -last_cluster, | 55 | - qemu_iovec_memset(qiov, n1, 0, bytes - n1); |
85 | + "Failed to find the last cluster"); | 56 | - |
86 | + return last_cluster; | 57 | - return n1; |
87 | + } | 58 | -} |
88 | + if ((last_cluster + 1) * s->cluster_size < old_file_size) { | 59 | - |
89 | + ret = bdrv_truncate(bs->file, (last_cluster + 1) * s->cluster_size, | 60 | static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, |
90 | + PREALLOC_MODE_OFF, NULL); | 61 | uint64_t bytes, QEMUIOVector *qiov, |
91 | + if (ret < 0) { | 62 | int flags) |
92 | + warn_report("Failed to truncate the tail of the image: %s", | 63 | { |
93 | + strerror(-ret)); | 64 | BDRVQcow2State *s = bs->opaque; |
94 | + ret = 0; | 65 | - int offset_in_cluster, n1; |
95 | + } | 66 | + int offset_in_cluster; |
96 | + } | 67 | int ret; |
97 | } else { | 68 | unsigned int cur_bytes; /* number of bytes in current iteration */ |
98 | ret = qcow2_grow_l1_table(bs, new_l1_size, true); | 69 | uint64_t cluster_offset = 0; |
99 | if (ret < 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 */ | ||
100 | -- | 104 | -- |
101 | 2.13.6 | 105 | 2.13.6 |
102 | 106 | ||
103 | 107 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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(). | ||
2 | 5 | ||
3 | Make it possible to inject errors on writes performed during a | 6 | Document this problem so that we won't accidentally mark the command |
4 | read operation due to copy-on-read semantics. | 7 | stable without having addressed it. |
5 | 8 | ||
6 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
7 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
12 | --- | 11 | --- |
13 | qapi/block-core.json | 5 ++++- | 12 | qapi/block-core.json | 4 ++++ |
14 | block/io.c | 1 + | 13 | 1 file changed, 4 insertions(+) |
15 | 2 files changed, 5 insertions(+), 1 deletion(-) | ||
16 | 14 | ||
17 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 15 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/qapi/block-core.json | 17 | --- a/qapi/block-core.json |
20 | +++ b/qapi/block-core.json | 18 | +++ b/qapi/block-core.json |
21 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
20 | # does not support all kinds of operations, all kinds of children, nor | ||
21 | # all block drivers. | ||
22 | # | 22 | # |
23 | # @l1_shrink_free_l2_clusters: discard the l2 tables. (since 2.11) | 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. | ||
24 | # | 29 | # |
25 | +# @cor_write: a write due to copy-on-read (since 2.11) | ||
26 | +# | ||
27 | # Since: 2.9 | ||
28 | ## | ||
29 | { 'enum': 'BlkdebugEvent', 'prefix': 'BLKDBG', | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | 'flush_to_disk', 'pwritev_rmw_head', 'pwritev_rmw_after_head', | ||
32 | 'pwritev_rmw_tail', 'pwritev_rmw_after_tail', 'pwritev', | ||
33 | 'pwritev_zero', 'pwritev_done', 'empty_image_prepare', | ||
34 | - 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters' ] } | ||
35 | + 'l1_shrink_write_table', 'l1_shrink_free_l2_clusters', | ||
36 | + 'cor_write'] } | ||
37 | |||
38 | ## | ||
39 | # @BlkdebugInjectErrorOptions: | ||
40 | diff --git a/block/io.c b/block/io.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/block/io.c | ||
43 | +++ b/block/io.c | ||
44 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, | ||
45 | goto err; | ||
46 | } | ||
47 | |||
48 | + bdrv_debug_event(bs, BLKDBG_COR_WRITE); | ||
49 | if (drv->bdrv_co_pwrite_zeroes && | ||
50 | buffer_is_zero(bounce_buffer, iov.iov_len)) { | ||
51 | /* FIXME: Should we (perhaps conditionally) be setting | ||
52 | -- | 30 | -- |
53 | 2.13.6 | 31 | 2.13.6 |
54 | 32 | ||
55 | 33 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Doug Gale <doug16k@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Make it easier to enable copy-on-read during iotests, by | 3 | Add trace output for commands, errors, and undefined behavior. |
4 | exposing a new bool option to main and open. | 4 | Add guest error log output for undefined behavior. |
5 | Report invalid undefined accesses to MMIO. | ||
6 | Annotate unlikely error checks with unlikely. | ||
5 | 7 | ||
6 | Signed-off-by: Eric Blake <eblake@redhat.com> | 8 | Signed-off-by: Doug Gale <doug16k@gmail.com> |
7 | Reviewed-by: Jeff Cody <jcody@redhat.com> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
12 | --- | 12 | --- |
13 | qemu-io.c | 15 ++++++++++++--- | 13 | hw/block/nvme.c | 349 ++++++++++++++++++++++++++++++++++++++++++-------- |
14 | 1 file changed, 12 insertions(+), 3 deletions(-) | 14 | hw/block/trace-events | 93 ++++++++++++++ |
15 | 2 files changed, 390 insertions(+), 52 deletions(-) | ||
15 | 16 | ||
16 | diff --git a/qemu-io.c b/qemu-io.c | 17 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/qemu-io.c | 19 | --- a/hw/block/nvme.c |
19 | +++ b/qemu-io.c | 20 | +++ b/hw/block/nvme.c |
20 | @@ -XXX,XX +XXX,XX @@ static void open_help(void) | 21 | @@ -XXX,XX +XXX,XX @@ |
21 | " Opens a file for subsequent use by all of the other qemu-io commands.\n" | 22 | #include "qapi/visitor.h" |
22 | " -r, -- open file read-only\n" | 23 | #include "sysemu/block-backend.h" |
23 | " -s, -- use snapshot file\n" | 24 | |
24 | +" -C, -- use copy-on-read\n" | 25 | +#include "qemu/log.h" |
25 | " -n, -- disable host cache, short for -t none\n" | 26 | +#include "trace.h" |
26 | " -U, -- force shared permissions\n" | 27 | #include "nvme.h" |
27 | " -k, -- use kernel AIO implementation (on Linux only)\n" | 28 | |
28 | @@ -XXX,XX +XXX,XX @@ static const cmdinfo_t open_cmd = { | 29 | +#define NVME_GUEST_ERR(trace, fmt, ...) \ |
29 | .argmin = 1, | 30 | + do { \ |
30 | .argmax = -1, | 31 | + (trace_##trace)(__VA_ARGS__); \ |
31 | .flags = CMD_NOFILE_OK, | 32 | + qemu_log_mask(LOG_GUEST_ERROR, #trace \ |
32 | - .args = "[-rsnkU] [-t cache] [-d discard] [-o options] [path]", | 33 | + " in %s: " fmt "\n", __func__, ## __VA_ARGS__); \ |
33 | + .args = "[-rsCnkU] [-t cache] [-d discard] [-o options] [path]", | 34 | + } while (0) |
34 | .oneline = "open the file specified by path", | 35 | + |
35 | .help = open_help, | 36 | static void nvme_process_sq(void *opaque); |
36 | }; | 37 | |
37 | @@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv) | 38 | static void nvme_addr_read(NvmeCtrl *n, hwaddr addr, void *buf, int size) |
38 | QDict *opts; | 39 | @@ -XXX,XX +XXX,XX @@ static void nvme_isr_notify(NvmeCtrl *n, NvmeCQueue *cq) |
39 | bool force_share = false; | ||
40 | |||
41 | - while ((c = getopt(argc, argv, "snro:kt:d:U")) != -1) { | ||
42 | + while ((c = getopt(argc, argv, "snCro:kt:d:U")) != -1) { | ||
43 | switch (c) { | ||
44 | case 's': | ||
45 | flags |= BDRV_O_SNAPSHOT; | ||
46 | @@ -XXX,XX +XXX,XX @@ static int open_f(BlockBackend *blk, int argc, char **argv) | ||
47 | flags |= BDRV_O_NOCACHE; | ||
48 | writethrough = false; | ||
49 | break; | ||
50 | + case 'C': | ||
51 | + flags |= BDRV_O_COPY_ON_READ; | ||
52 | + break; | ||
53 | case 'r': | ||
54 | readonly = 1; | ||
55 | break; | ||
56 | @@ -XXX,XX +XXX,XX @@ static void usage(const char *name) | ||
57 | " -r, --read-only export read-only\n" | ||
58 | " -s, --snapshot use snapshot file\n" | ||
59 | " -n, --nocache disable host cache, short for -t none\n" | ||
60 | +" -C, --copy-on-read enable copy-on-read\n" | ||
61 | " -m, --misalign misalign allocations for O_DIRECT\n" | ||
62 | " -k, --native-aio use kernel AIO implementation (on Linux only)\n" | ||
63 | " -t, --cache=MODE use the given cache mode for the image\n" | ||
64 | @@ -XXX,XX +XXX,XX @@ static QemuOptsList file_opts = { | ||
65 | int main(int argc, char **argv) | ||
66 | { | 40 | { |
67 | int readonly = 0; | 41 | if (cq->irq_enabled) { |
68 | - const char *sopt = "hVc:d:f:rsnmkt:T:U"; | 42 | if (msix_enabled(&(n->parent_obj))) { |
69 | + const char *sopt = "hVc:d:f:rsnCmkt:T:U"; | 43 | + trace_nvme_irq_msix(cq->vector); |
70 | const struct option lopt[] = { | 44 | msix_notify(&(n->parent_obj), cq->vector); |
71 | { "help", no_argument, NULL, 'h' }, | 45 | } else { |
72 | { "version", no_argument, NULL, 'V' }, | 46 | + trace_nvme_irq_pin(); |
73 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | 47 | pci_irq_pulse(&n->parent_obj); |
74 | { "read-only", no_argument, NULL, 'r' }, | 48 | } |
75 | { "snapshot", no_argument, NULL, 's' }, | 49 | + } else { |
76 | { "nocache", no_argument, NULL, 'n' }, | 50 | + trace_nvme_irq_masked(); |
77 | + { "copy-on-read", no_argument, NULL, 'C' }, | 51 | } |
78 | { "misalign", no_argument, NULL, 'm' }, | 52 | } |
79 | { "native-aio", no_argument, NULL, 'k' }, | 53 | |
80 | { "discard", required_argument, NULL, 'd' }, | 54 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, |
81 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | 55 | trans_len = MIN(len, trans_len); |
82 | flags |= BDRV_O_NOCACHE; | 56 | int num_prps = (len >> n->page_bits) + 1; |
83 | writethrough = false; | 57 | |
84 | break; | 58 | - if (!prp1) { |
85 | + case 'C': | 59 | + if (unlikely(!prp1)) { |
86 | + flags |= BDRV_O_COPY_ON_READ; | 60 | + trace_nvme_err_invalid_prp(); |
87 | + break; | 61 | return NVME_INVALID_FIELD | NVME_DNR; |
88 | case 'd': | 62 | } else if (n->cmbsz && prp1 >= n->ctrl_mem.addr && |
89 | if (bdrv_parse_discard_flags(optarg, &flags) < 0) { | 63 | prp1 < n->ctrl_mem.addr + int128_get64(n->ctrl_mem.size)) { |
90 | error_report("Invalid discard option: %s", optarg); | 64 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, |
65 | } | ||
66 | len -= trans_len; | ||
67 | if (len) { | ||
68 | - if (!prp2) { | ||
69 | + if (unlikely(!prp2)) { | ||
70 | + trace_nvme_err_invalid_prp2_missing(); | ||
71 | goto unmap; | ||
72 | } | ||
73 | if (len > n->page_size) { | ||
74 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_map_prp(QEMUSGList *qsg, QEMUIOVector *iov, uint64_t prp1, | ||
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++; | ||
96 | } | ||
97 | } else { | ||
98 | - if (prp2 & (n->page_size - 1)) { | ||
99 | + if (unlikely(prp2 & (n->page_size - 1))) { | ||
100 | + trace_nvme_err_invalid_prp2_align(prp2); | ||
101 | goto unmap; | ||
102 | } | ||
103 | if (qsg->nsg) { | ||
104 | @@ -XXX,XX +XXX,XX @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len, | ||
105 | QEMUIOVector iov; | ||
106 | uint16_t status = NVME_SUCCESS; | ||
107 | |||
108 | + trace_nvme_dma_read(prp1, prp2); | ||
109 | + | ||
110 | if (nvme_map_prp(&qsg, &iov, prp1, prp2, len, n)) { | ||
111 | return NVME_INVALID_FIELD | NVME_DNR; | ||
112 | } | ||
113 | if (qsg.nsg > 0) { | ||
114 | - if (dma_buf_read(ptr, len, &qsg)) { | ||
115 | + if (unlikely(dma_buf_read(ptr, len, &qsg))) { | ||
116 | + trace_nvme_err_invalid_dma(); | ||
117 | status = NVME_INVALID_FIELD | NVME_DNR; | ||
118 | } | ||
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" | ||
91 | -- | 784 | -- |
92 | 2.13.6 | 785 | 2.13.6 |
93 | 786 | ||
94 | 787 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | All callers of bdrv_img_create() pass in a size, or -1 to read the | 3 | Management tools create overlays of running guests with qemu-img: |
4 | size from the backing file. We then set that size as the QemuOpt | ||
5 | default, which means we will reuse that default rather than the | ||
6 | final parameter to qemu_opt_get_size() several lines later. But | ||
7 | it is rather confusing to read subsequent checks of 'size == -1' | ||
8 | when it looks (without seeing the full context) like size defaults | ||
9 | to 0; it also doesn't help that a size of 0 is valid (for some | ||
10 | formats). | ||
11 | 4 | ||
12 | Rework the logic to make things more legible. | 5 | $ qemu-img create -b /image/in/use.qcow2 -f qcow2 /overlay/image.qcow2 |
13 | 6 | ||
14 | Signed-off-by: Eric Blake <eblake@redhat.com> | 7 | but this doesn't work anymore due to image locking: |
15 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | |
16 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 9 | qemu-img: /overlay/image.qcow2: Failed to get shared "write" lock |
17 | Reviewed-by: Fam Zheng <famz@redhat.com> | 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> | ||
16 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
19 | --- | 18 | --- |
20 | block.c | 2 +- | 19 | block.c | 3 ++- |
21 | 1 file changed, 1 insertion(+), 1 deletion(-) | 20 | 1 file changed, 2 insertions(+), 1 deletion(-) |
22 | 21 | ||
23 | diff --git a/block.c b/block.c | 22 | diff --git a/block.c b/block.c |
24 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/block.c | 24 | --- a/block.c |
26 | +++ b/block.c | 25 | +++ b/block.c |
27 | @@ -XXX,XX +XXX,XX @@ void bdrv_img_create(const char *filename, const char *fmt, | 26 | @@ -XXX,XX +XXX,XX @@ void bdrv_img_create(const char *filename, const char *fmt, |
28 | 27 | back_flags = flags; | |
29 | /* The size for the image must always be specified, unless we have a backing | 28 | back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING); |
30 | * file and we have not been forbidden from opening it. */ | 29 | |
31 | - size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); | 30 | + backing_options = qdict_new(); |
32 | + size = qemu_opt_get_size(opts, BLOCK_OPT_SIZE, img_size); | 31 | if (backing_fmt) { |
33 | if (backing_file && !(flags & BDRV_O_NO_BACKING)) { | 32 | - backing_options = qdict_new(); |
34 | BlockDriverState *bs; | 33 | qdict_put_str(backing_options, "driver", backing_fmt); |
35 | char *full_backing = g_new0(char, PATH_MAX); | 34 | } |
35 | + qdict_put_bool(backing_options, BDRV_OPT_FORCE_SHARE, true); | ||
36 | |||
37 | bs = bdrv_open(full_backing, NULL, backing_options, back_flags, | ||
38 | &local_err); | ||
36 | -- | 39 | -- |
37 | 2.13.6 | 40 | 2.13.6 |
38 | 41 | ||
39 | 42 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | We are gradually converting to byte-based interfaces, as they are | 3 | It's not working anymore since QEMU v1.3.0 - time to remove it now. |
4 | easier to reason about than sector-based. Change the qcow2 bitmap | ||
5 | helper function sectors_covered_by_bitmap_cluster(), renaming it | ||
6 | to bytes_covered_by_bitmap_cluster() in the process. | ||
7 | 4 | ||
8 | Signed-off-by: Eric Blake <eblake@redhat.com> | 5 | Signed-off-by: Thomas Huth <thuth@redhat.com> |
9 | Reviewed-by: John Snow <jsnow@redhat.com> | 6 | Reviewed-by: John Snow <jsnow@redhat.com> |
10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | 7 | Reviewed-by: Markus Armbruster <armbru@redhat.com> |
11 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
13 | --- | 9 | --- |
14 | block/qcow2-bitmap.c | 28 ++++++++++++++-------------- | 10 | blockdev.c | 11 ----------- |
15 | 1 file changed, 14 insertions(+), 14 deletions(-) | 11 | qemu-doc.texi | 6 ------ |
12 | 2 files changed, 17 deletions(-) | ||
16 | 13 | ||
17 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | 14 | diff --git a/blockdev.c b/blockdev.c |
18 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/qcow2-bitmap.c | 16 | --- a/blockdev.c |
20 | +++ b/block/qcow2-bitmap.c | 17 | +++ b/blockdev.c |
21 | @@ -XXX,XX +XXX,XX @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb) | 18 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_legacy_drive_opts = { |
22 | return 0; | 19 | .type = QEMU_OPT_STRING, |
23 | } | 20 | .help = "chs translation (auto, lba, none)", |
24 | 21 | },{ | |
25 | -/* This function returns the number of disk sectors covered by a single qcow2 | 22 | - .name = "boot", |
26 | - * cluster of bitmap data. */ | 23 | - .type = QEMU_OPT_BOOL, |
27 | -static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s, | 24 | - .help = "(deprecated, ignored)", |
28 | - const BdrvDirtyBitmap *bitmap) | 25 | - },{ |
29 | +/* Return the disk size covered by a single qcow2 cluster of bitmap data. */ | 26 | .name = "addr", |
30 | +static uint64_t bytes_covered_by_bitmap_cluster(const BDRVQcow2State *s, | 27 | .type = QEMU_OPT_STRING, |
31 | + const BdrvDirtyBitmap *bitmap) | 28 | .help = "pci address (virtio only)", |
32 | { | 29 | @@ -XXX,XX +XXX,XX @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) |
33 | - uint64_t sector_granularity = | 30 | goto fail; |
34 | - bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; | ||
35 | - uint64_t sbc = sector_granularity * (s->cluster_size << 3); | ||
36 | + uint64_t granularity = bdrv_dirty_bitmap_granularity(bitmap); | ||
37 | + uint64_t limit = granularity * (s->cluster_size << 3); | ||
38 | |||
39 | - assert(QEMU_IS_ALIGNED(sbc << BDRV_SECTOR_BITS, | ||
40 | + assert(QEMU_IS_ALIGNED(limit, | ||
41 | bdrv_dirty_bitmap_serialization_align(bitmap))); | ||
42 | - return sbc; | ||
43 | + return limit; | ||
44 | } | ||
45 | |||
46 | /* load_bitmap_data | ||
47 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
48 | { | ||
49 | int ret = 0; | ||
50 | BDRVQcow2State *s = bs->opaque; | ||
51 | - uint64_t sector, sbc; | ||
52 | + uint64_t sector, limit, sbc; | ||
53 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | ||
54 | uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | ||
55 | uint8_t *buf = NULL; | ||
56 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
57 | } | 31 | } |
58 | 32 | ||
59 | buf = g_malloc(s->cluster_size); | 33 | - /* Deprecated option boot=[on|off] */ |
60 | - sbc = sectors_covered_by_bitmap_cluster(s, bitmap); | 34 | - if (qemu_opt_get(legacy_opts, "boot") != NULL) { |
61 | + limit = bytes_covered_by_bitmap_cluster(s, bitmap); | 35 | - fprintf(stderr, "qemu-kvm: boot=on|off is deprecated and will be " |
62 | + sbc = limit >> BDRV_SECTOR_BITS; | 36 | - "ignored. Future versions will reject this parameter. Please " |
63 | for (i = 0, sector = 0; i < tab_size; ++i, sector += sbc) { | 37 | - "update your scripts.\n"); |
64 | uint64_t count = MIN(bm_sectors - sector, sbc); | 38 | - } |
65 | uint64_t entry = bitmap_table[i]; | 39 | - |
66 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 40 | /* Other deprecated options */ |
67 | int ret; | 41 | if (!qtest_enabled()) { |
68 | BDRVQcow2State *s = bs->opaque; | 42 | for (i = 0; i < ARRAY_SIZE(deprecated); i++) { |
69 | int64_t sector; | 43 | diff --git a/qemu-doc.texi b/qemu-doc.texi |
70 | - uint64_t sbc; | 44 | index XXXXXXX..XXXXXXX 100644 |
71 | + uint64_t limit, sbc; | 45 | --- a/qemu-doc.texi |
72 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | 46 | +++ b/qemu-doc.texi |
73 | uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | 47 | @@ -XXX,XX +XXX,XX @@ deprecated. |
74 | const char *bm_name = bdrv_dirty_bitmap_name(bitmap); | 48 | |
75 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 49 | @section System emulator command line arguments |
76 | 50 | ||
77 | dbi = bdrv_dirty_iter_new(bitmap, 0); | 51 | -@subsection -drive boot=on|off (since 1.3.0) |
78 | buf = g_malloc(s->cluster_size); | 52 | - |
79 | - sbc = sectors_covered_by_bitmap_cluster(s, bitmap); | 53 | -The ``boot=on|off'' option to the ``-drive'' argument is |
80 | - assert(DIV_ROUND_UP(bm_sectors, sbc) == tb_size); | 54 | -ignored. Applications should use the ``bootindex=N'' parameter |
81 | + limit = bytes_covered_by_bitmap_cluster(s, bitmap); | 55 | -to set an absolute ordering between devices instead. |
82 | + sbc = limit >> BDRV_SECTOR_BITS; | 56 | - |
83 | + assert(DIV_ROUND_UP(bm_size, limit) == tb_size); | 57 | @subsection -tdf (since 1.3.0) |
84 | 58 | ||
85 | while ((sector = bdrv_dirty_iter_next(dbi)) != -1) { | 59 | The ``-tdf'' argument is ignored. The behaviour implemented |
86 | uint64_t cluster = sector / sbc; | ||
87 | -- | 60 | -- |
88 | 2.13.6 | 61 | 2.13.6 |
89 | 62 | ||
90 | 63 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Executing qemu with a terminal as stdin will temporarily alter stty | 3 | It's been marked as deprecated since QEMU v2.10.0, and so far nobody |
4 | settings on that terminal (for example, disabling echo), because of | 4 | complained that we should keep it, so let's remove this legacy option |
5 | how we run both the monitor and any multiplexing with guest input. | 5 | now to simplify the code quite a bit. |
6 | Normally, qemu restores the original settings on exit; but if an | 6 | |
7 | iotest triggers qemu to abort in the middle, we can be left with | 7 | Signed-off-by: Thomas Huth <thuth@redhat.com> |
8 | the altered terminal setup. This can make life very annoying when | 8 | Reviewed-by: John Snow <jsnow@redhat.com> |
9 | debugging an iotest failure (not everyone remembers the trick of | 9 | Reviewed-by: Markus Armbruster <armbru@redhat.com> |
10 | blind-typing 'stty sane' without echo, and some people prefer | ||
11 | terminal settings that are slightly different than the defaults | ||
12 | picked by 'stty sane'). | ||
13 | |||
14 | It is possible to avoid qemu corrupting the terminal by not passing | ||
15 | a terminal to qemu's stdin in the first place (as in, use | ||
16 | './check ... </dev/null'), but that's extra typing to have to | ||
17 | remember. But running 'exec </dev/null' in the harness seems like | ||
18 | it might be too heavy of a hammer. So I instead went the the | ||
19 | solution of saving and restoring the stty settings, only when the | ||
20 | harness detects that it is run interactively. | ||
21 | |||
22 | I tested this patch by forcing an allocation failure (I can't | ||
23 | guarantee that this particular limit will work on all setups, but | ||
24 | it shows the idea): | ||
25 | $ (ulimit -S -v 500000; ./check -qcow2 1) | ||
26 | |||
27 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
28 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
29 | --- | 11 | --- |
30 | tests/qemu-iotests/check | 10 ++++++++++ | 12 | vl.c | 86 ++------------------------------------------------------- |
31 | 1 file changed, 10 insertions(+) | 13 | qemu-doc.texi | 8 ------ |
32 | 14 | qemu-options.hx | 19 ++----------- | |
33 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 15 | 3 files changed, 4 insertions(+), 109 deletions(-) |
34 | index XXXXXXX..XXXXXXX 100755 | 16 | |
35 | --- a/tests/qemu-iotests/check | 17 | diff --git a/vl.c b/vl.c |
36 | +++ b/tests/qemu-iotests/check | 18 | index XXXXXXX..XXXXXXX 100644 |
37 | @@ -XXX,XX +XXX,XX @@ export VALGRIND_QEMU= | 19 | --- a/vl.c |
38 | export IMGKEYSECRET= | 20 | +++ b/vl.c |
39 | export IMGOPTSSYNTAX=false | 21 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) |
40 | 22 | const char *boot_order = NULL; | |
41 | +# Save current tty settings, since an aborting qemu call may leave things | 23 | const char *boot_once = NULL; |
42 | +# screwed up | 24 | DisplayState *ds; |
43 | +STTY_RESTORE= | 25 | - int cyls, heads, secs, translation; |
44 | +if test -t 0; then | 26 | QemuOpts *opts, *machine_opts; |
45 | + STTY_RESTORE=$(stty -g) | 27 | - QemuOpts *hda_opts = NULL, *icount_opts = NULL, *accel_opts = NULL; |
46 | +fi | 28 | + QemuOpts *icount_opts = NULL, *accel_opts = NULL; |
47 | + | 29 | QemuOptsList *olist; |
48 | for r | 30 | int optind; |
49 | do | 31 | const char *optarg; |
50 | 32 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | |
51 | @@ -XXX,XX +XXX,XX @@ END { if (NR > 0) { | 33 | |
52 | needwrap=false | 34 | cpu_model = NULL; |
53 | fi | 35 | snapshot = 0; |
54 | 36 | - cyls = heads = secs = 0; | |
55 | + if test -n "$STTY_RESTORE"; then | 37 | - translation = BIOS_ATA_TRANSLATION_AUTO; |
56 | + stty $STTY_RESTORE | 38 | |
57 | + fi | 39 | nb_nics = 0; |
58 | rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time | 40 | |
59 | rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts | 41 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) |
60 | rm -f $tmp.* | 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" | ||
61 | -- | 199 | -- |
62 | 2.13.6 | 200 | 2.13.6 |
63 | 201 | ||
64 | 202 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The condition of the for-loop makes sure that b is always smaller | 3 | Looks like we forgot to announce the deprecation of these options in |
4 | than s->blocks, so the "if (b >= s->blocks)" statement is completely | 4 | the corresponding chapter of the qemu-doc text, so let's do that now. |
5 | superfluous here. | ||
6 | 5 | ||
7 | Buglink: https://bugs.launchpad.net/qemu/+bug/1715007 | ||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 6 | Signed-off-by: Thomas Huth <thuth@redhat.com> |
9 | Reviewed-by: Laurent Vivier <lvivier@redhat.com> | 7 | Reviewed-by: John Snow <jsnow@redhat.com> |
8 | Reviewed-by: Markus Armbruster <armbru@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | --- | 10 | --- |
12 | hw/block/onenand.c | 4 ---- | 11 | qemu-doc.texi | 15 +++++++++++++++ |
13 | 1 file changed, 4 deletions(-) | 12 | 1 file changed, 15 insertions(+) |
14 | 13 | ||
15 | diff --git a/hw/block/onenand.c b/hw/block/onenand.c | 14 | diff --git a/qemu-doc.texi b/qemu-doc.texi |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/block/onenand.c | 16 | --- a/qemu-doc.texi |
18 | +++ b/hw/block/onenand.c | 17 | +++ b/qemu-doc.texi |
19 | @@ -XXX,XX +XXX,XX @@ static void onenand_command(OneNANDState *s) | 18 | @@ -XXX,XX +XXX,XX @@ longer be directly supported in QEMU. |
20 | s->intstatus |= ONEN_INT; | 19 | The ``-drive if=scsi'' argument is replaced by the the |
21 | 20 | ``-device BUS-TYPE'' argument combined with ``-drive if=none''. | |
22 | for (b = 0; b < s->blocks; b ++) { | 21 | |
23 | - if (b >= s->blocks) { | 22 | +@subsection -drive cyls=...,heads=...,secs=...,trans=... (since 2.10.0) |
24 | - s->status |= ONEN_ERR_CMD; | 23 | + |
25 | - break; | 24 | +The drive geometry arguments are replaced by the the geometry arguments |
26 | - } | 25 | +that can be specified with the ``-device'' parameter. |
27 | if (s->blockwp[b] == ONEN_LOCK_LOCKTIGHTEN) | 26 | + |
28 | break; | 27 | +@subsection -drive serial=... (since 2.10.0) |
29 | 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 | ||
30 | -- | 40 | -- |
31 | 2.13.6 | 41 | 2.13.6 |
32 | 42 | ||
33 | 43 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 1 | From: Fam Zheng <famz@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Both callers already had bytes available, but were scaling to | 3 | Signed-off-by: Fam Zheng <famz@redhat.com> |
4 | sectors. Move the scaling to internal code. In the case of | ||
5 | bdrv_aligned_pwritev(), we are now passing the exact offset | ||
6 | rather than a rounded sector-aligned value, but that's okay | ||
7 | as long as dirty bitmap widens start/bytes to granularity | ||
8 | boundaries. | ||
9 | |||
10 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
11 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
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 | 2 +- | 6 | include/block/block_int.h | 1 - |
17 | block/dirty-bitmap.c | 7 ++++--- | 7 | block/io.c | 18 ------------------ |
18 | block/io.c | 6 ++---- | 8 | 2 files changed, 19 deletions(-) |
19 | 3 files changed, 7 insertions(+), 8 deletions(-) | ||
20 | 9 | ||
21 | 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 |
22 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/block/block_int.h | 12 | --- a/include/block/block_int.h |
24 | +++ b/include/block/block_int.h | 13 | +++ b/include/block/block_int.h |
25 | @@ -XXX,XX +XXX,XX @@ void blk_dev_eject_request(BlockBackend *blk, bool force); | 14 | @@ -XXX,XX +XXX,XX @@ bool blk_dev_is_tray_open(BlockBackend *blk); |
26 | bool blk_dev_is_tray_open(BlockBackend *blk); | ||
27 | bool blk_dev_is_medium_locked(BlockBackend *blk); | 15 | bool blk_dev_is_medium_locked(BlockBackend *blk); |
28 | 16 | ||
29 | -void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int64_t nr_sect); | 17 | void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); |
30 | +void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); | 18 | -bool bdrv_requests_pending(BlockDriverState *bs); |
31 | bool bdrv_requests_pending(BlockDriverState *bs); | ||
32 | 19 | ||
33 | void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); | 20 | void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); |
34 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | 21 | void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); |
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/block/dirty-bitmap.c | ||
37 | +++ b/block/dirty-bitmap.c | ||
38 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) | ||
39 | hbitmap_deserialize_finish(bitmap->bitmap); | ||
40 | } | ||
41 | |||
42 | -void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, | ||
43 | - int64_t nr_sectors) | ||
44 | +void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes) | ||
45 | { | ||
46 | BdrvDirtyBitmap *bitmap; | ||
47 | + int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
48 | |||
49 | if (QLIST_EMPTY(&bs->dirty_bitmaps)) { | ||
50 | return; | ||
51 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, | ||
52 | continue; | ||
53 | } | ||
54 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
55 | - hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); | ||
56 | + hbitmap_set(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
57 | + end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
58 | } | ||
59 | bdrv_dirty_bitmaps_unlock(bs); | ||
60 | } | ||
61 | diff --git a/block/io.c b/block/io.c | 22 | diff --git a/block/io.c b/block/io.c |
62 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
63 | --- a/block/io.c | 24 | --- a/block/io.c |
64 | +++ b/block/io.c | 25 | +++ b/block/io.c |
65 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, | 26 | @@ -XXX,XX +XXX,XX @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) |
66 | bool waited; | 27 | assert(old >= 1); |
67 | int ret; | 28 | } |
68 | 29 | ||
69 | - int64_t start_sector = offset >> BDRV_SECTOR_BITS; | 30 | -/* Check if any requests are in-flight (including throttled requests) */ |
70 | int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | 31 | -bool bdrv_requests_pending(BlockDriverState *bs) |
71 | uint64_t bytes_remaining = bytes; | 32 | -{ |
72 | int max_transfer; | 33 | - BdrvChild *child; |
73 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, | 34 | - |
74 | bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE); | 35 | - if (atomic_read(&bs->in_flight)) { |
75 | 36 | - return true; | |
76 | atomic_inc(&bs->write_gen); | 37 | - } |
77 | - bdrv_set_dirty(bs, start_sector, end_sector - start_sector); | 38 | - |
78 | + bdrv_set_dirty(bs, offset, bytes); | 39 | - QLIST_FOREACH(child, &bs->children, next) { |
79 | 40 | - if (bdrv_requests_pending(child->bs)) { | |
80 | stat64_max(&bs->wr_highest_offset, offset + bytes); | 41 | - return true; |
81 | 42 | - } | |
82 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *bs, int64_t offset, | 43 | - } |
83 | ret = 0; | 44 | - |
84 | out: | 45 | - return false; |
85 | atomic_inc(&bs->write_gen); | 46 | -} |
86 | - bdrv_set_dirty(bs, req.offset >> BDRV_SECTOR_BITS, | 47 | - |
87 | - req.bytes >> BDRV_SECTOR_BITS); | 48 | typedef struct { |
88 | + bdrv_set_dirty(bs, req.offset, req.bytes); | 49 | Coroutine *co; |
89 | tracked_request_end(&req); | 50 | BlockDriverState *bs; |
90 | bdrv_dec_in_flight(bs); | ||
91 | return ret; | ||
92 | -- | 51 | -- |
93 | 2.13.6 | 52 | 2.13.6 |
94 | 53 | ||
95 | 54 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | ||
---|---|---|---|
2 | |||
3 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
2 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
5 | --- | 3 | --- |
6 | block/io.c | 2 +- | 4 | block/io.c | 6 ++++++ |
7 | 1 file changed, 1 insertion(+), 1 deletion(-) | 5 | 1 file changed, 6 insertions(+) |
8 | 6 | ||
9 | diff --git a/block/io.c b/block/io.c | 7 | diff --git a/block/io.c b/block/io.c |
10 | index XXXXXXX..XXXXXXX 100644 | 8 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/block/io.c | 9 | --- a/block/io.c |
12 | +++ b/block/io.c | 10 | +++ b/block/io.c |
13 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, | 11 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
14 | /* FIXME We cannot require callers to have write permissions when all they | 12 | BdrvNextIterator it; |
15 | * are doing is a read request. If we did things right, write permissions | 13 | GSList *aio_ctxs = NULL, *ctx; |
16 | * would be obtained anyway, but internally by the copy-on-read code. As | 14 | |
17 | - * long as it is implemented here rather than in a separat filter driver, | 15 | + /* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread |
18 | + * long as it is implemented here rather than in a separate filter driver, | 16 | + * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on |
19 | * the copy-on-read code doesn't have its own BdrvChild, however, for which | 17 | + * nodes in several different AioContexts, so make sure we're in the main |
20 | * it could request permissions. Therefore we have to bypass the permission | 18 | + * context. */ |
21 | * system for the moment. */ | 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)) { | ||
22 | -- | 24 | -- |
23 | 2.13.6 | 25 | 2.13.6 |
24 | 26 | ||
25 | 27 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | When subdividing a bitmap serialization, the code in hbitmap.c | ||
4 | enforces that start/count parameters are aligned (except that | ||
5 | count can end early at end-of-bitmap). We exposed this required | ||
6 | alignment through bdrv_dirty_bitmap_serialization_align(), but | ||
7 | forgot to actually check that we comply with it. | ||
8 | |||
9 | Fortunately, qcow2 is never dividing bitmap serialization smaller | ||
10 | than one cluster (which is a minimum of 512 bytes); so we are | ||
11 | always compliant with the serialization alignment (which insists | ||
12 | that we partition at least 64 bits per chunk) because we are doing | ||
13 | at least 4k bits per chunk. | ||
14 | |||
15 | Still, it's safer to add an assertion (for the unlikely case that | ||
16 | we'd ever support a cluster smaller than 512 bytes, or if the | ||
17 | hbitmap implementation changes what it considers to be aligned), | ||
18 | rather than leaving bdrv_dirty_bitmap_serialization_align() | ||
19 | without a caller. | ||
20 | |||
21 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
22 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
23 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
24 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
25 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
26 | --- | ||
27 | block/qcow2-bitmap.c | 7 +++++-- | ||
28 | 1 file changed, 5 insertions(+), 2 deletions(-) | ||
29 | |||
30 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/block/qcow2-bitmap.c | ||
33 | +++ b/block/qcow2-bitmap.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb) | ||
35 | static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s, | ||
36 | const BdrvDirtyBitmap *bitmap) | ||
37 | { | ||
38 | - uint32_t sector_granularity = | ||
39 | + uint64_t sector_granularity = | ||
40 | bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; | ||
41 | + uint64_t sbc = sector_granularity * (s->cluster_size << 3); | ||
42 | |||
43 | - return (uint64_t)sector_granularity * (s->cluster_size << 3); | ||
44 | + assert(QEMU_IS_ALIGNED(sbc, | ||
45 | + bdrv_dirty_bitmap_serialization_align(bitmap))); | ||
46 | + return sbc; | ||
47 | } | ||
48 | |||
49 | /* load_bitmap_data | ||
50 | -- | ||
51 | 2.13.6 | ||
52 | |||
53 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 5 | ||
3 | Half the callers were already scaling bytes to sectors; the other | 6 | To keep things consistent, we also shouldn't call the block driver |
4 | half can eventually be simplified to use byte iteration. Both | 7 | callbacks recursively. |
5 | callers were already using the result as a bool, so make that | ||
6 | explicit. Making the change also makes it easier for a future | ||
7 | dirty-bitmap patch to offload scaling over to the internal hbitmap. | ||
8 | 8 | ||
9 | Remember, asking whether a byte is dirty is effectively asking | 9 | A proper recursive drain version that provides an actually working |
10 | whether the entire granularity containing the byte is dirty, since | 10 | drained section for child nodes will be introduced later. |
11 | we only track dirtiness by granularity. | ||
12 | 11 | ||
13 | Signed-off-by: Eric Blake <eblake@redhat.com> | 12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
14 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
15 | Reviewed-by: Juan Quintela <quintela@redhat.com> | ||
16 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
17 | Reviewed-by: Fam Zheng <famz@redhat.com> | 13 | Reviewed-by: Fam Zheng <famz@redhat.com> |
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | --- | 14 | --- |
20 | include/block/dirty-bitmap.h | 4 ++-- | 15 | block/io.c | 16 +++++++++------- |
21 | block/dirty-bitmap.c | 8 ++++---- | 16 | 1 file changed, 9 insertions(+), 7 deletions(-) |
22 | block/mirror.c | 3 +-- | ||
23 | migration/block.c | 3 ++- | ||
24 | 4 files changed, 9 insertions(+), 9 deletions(-) | ||
25 | 17 | ||
26 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | 18 | diff --git a/block/io.c b/block/io.c |
27 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/include/block/dirty-bitmap.h | 20 | --- a/block/io.c |
29 | +++ b/include/block/dirty-bitmap.h | 21 | +++ b/block/io.c |
30 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, | 22 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) |
31 | /* Functions that require manual locking. */ | ||
32 | void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); | ||
33 | void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); | ||
34 | -int bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | ||
35 | - int64_t sector); | ||
36 | +bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | ||
37 | + int64_t offset); | ||
38 | void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
39 | int64_t cur_sector, int64_t nr_sectors); | ||
40 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
41 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/block/dirty-bitmap.c | ||
44 | +++ b/block/dirty-bitmap.c | ||
45 | @@ -XXX,XX +XXX,XX @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs) | ||
46 | } | 23 | } |
47 | 24 | ||
48 | /* Called within bdrv_dirty_bitmap_lock..unlock */ | 25 | /* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ |
49 | -int bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | 26 | -static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) |
50 | - int64_t sector) | 27 | +static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, bool recursive) |
51 | +bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | ||
52 | + int64_t offset) | ||
53 | { | 28 | { |
54 | if (bitmap) { | 29 | BdrvChild *child, *tmp; |
55 | - return hbitmap_get(bitmap->bitmap, sector); | 30 | BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin}; |
56 | + return hbitmap_get(bitmap->bitmap, offset >> BDRV_SECTOR_BITS); | 31 | @@ -XXX,XX +XXX,XX @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) |
57 | } else { | 32 | bdrv_coroutine_enter(bs, data.co); |
58 | - return 0; | 33 | BDRV_POLL_WHILE(bs, !data.done); |
59 | + return false; | 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 | + } | ||
60 | } | 41 | } |
61 | } | 42 | } |
62 | 43 | ||
63 | diff --git a/block/mirror.c b/block/mirror.c | 44 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) |
64 | index XXXXXXX..XXXXXXX 100644 | 45 | bdrv_parent_drained_begin(bs); |
65 | --- a/block/mirror.c | 46 | } |
66 | +++ b/block/mirror.c | 47 | |
67 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | 48 | - bdrv_drain_invoke(bs, true); |
68 | int64_t next_offset = offset + nb_chunks * s->granularity; | 49 | + bdrv_drain_invoke(bs, true, false); |
69 | int64_t next_chunk = next_offset / s->granularity; | 50 | bdrv_drain_recurse(bs); |
70 | if (next_offset >= s->bdev_length || | 51 | } |
71 | - !bdrv_get_dirty_locked(source, s->dirty_bitmap, | 52 | |
72 | - next_offset >> BDRV_SECTOR_BITS)) { | 53 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
73 | + !bdrv_get_dirty_locked(source, s->dirty_bitmap, next_offset)) { | 54 | } |
74 | break; | 55 | |
75 | } | 56 | /* Re-enable things in child-to-parent order */ |
76 | if (test_bit(next_chunk, s->in_flight_bitmap)) { | 57 | - bdrv_drain_invoke(bs, false); |
77 | diff --git a/migration/block.c b/migration/block.c | 58 | + bdrv_drain_invoke(bs, false, false); |
78 | index XXXXXXX..XXXXXXX 100644 | 59 | bdrv_parent_drained_end(bs); |
79 | --- a/migration/block.c | 60 | aio_enable_external(bdrv_get_aio_context(bs)); |
80 | +++ b/migration/block.c | 61 | } |
81 | @@ -XXX,XX +XXX,XX @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds, | 62 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
82 | blk_mig_unlock(); | 63 | aio_context_acquire(aio_context); |
83 | } | 64 | aio_disable_external(aio_context); |
84 | bdrv_dirty_bitmap_lock(bmds->dirty_bitmap); | 65 | bdrv_parent_drained_begin(bs); |
85 | - if (bdrv_get_dirty_locked(bs, bmds->dirty_bitmap, sector)) { | 66 | - bdrv_drain_invoke(bs, true); |
86 | + if (bdrv_get_dirty_locked(bs, bmds->dirty_bitmap, | 67 | + bdrv_drain_invoke(bs, true, true); |
87 | + sector * BDRV_SECTOR_SIZE)) { | 68 | aio_context_release(aio_context); |
88 | if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) { | 69 | |
89 | nr_sectors = total_sectors - sector; | 70 | if (!g_slist_find(aio_ctxs, aio_context)) { |
90 | } else { | 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); | ||
91 | -- | 80 | -- |
92 | 2.13.6 | 81 | 2.13.6 |
93 | 82 | ||
94 | 83 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 5 | ||
3 | We had several functions that no one is currently using, and which | 6 | Also, add a backing file to the test node to test whether the operations |
4 | use sector-based interfaces. I'm trying to convert towards byte-based | 7 | work recursively. |
5 | interfaces, so it's easier to just drop the unused functions: | ||
6 | 8 | ||
7 | bdrv_dirty_bitmap_get_meta | ||
8 | bdrv_dirty_bitmap_get_meta_locked | ||
9 | bdrv_dirty_bitmap_reset_meta | ||
10 | bdrv_dirty_bitmap_meta_granularity | ||
11 | |||
12 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
13 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
14 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
15 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
16 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
17 | --- | 10 | --- |
18 | include/block/dirty-bitmap.h | 10 ---------- | 11 | tests/test-bdrv-drain.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----- |
19 | block/dirty-bitmap.c | 44 -------------------------------------------- | 12 | 1 file changed, 62 insertions(+), 7 deletions(-) |
20 | 2 files changed, 54 deletions(-) | ||
21 | 13 | ||
22 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | 14 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
23 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/block/dirty-bitmap.h | 16 | --- a/tests/test-bdrv-drain.c |
25 | +++ b/include/block/dirty-bitmap.h | 17 | +++ b/tests/test-bdrv-drain.c |
26 | @@ -XXX,XX +XXX,XX @@ void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); | 18 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_test = { |
27 | BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); | 19 | |
28 | uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); | 20 | .bdrv_co_drain_begin = bdrv_test_co_drain_begin, |
29 | uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap); | 21 | .bdrv_co_drain_end = bdrv_test_co_drain_end, |
30 | -uint32_t bdrv_dirty_bitmap_meta_granularity(BdrvDirtyBitmap *bitmap); | 22 | + |
31 | bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); | 23 | + .bdrv_child_perm = bdrv_format_default_perms, |
32 | bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap); | 24 | }; |
33 | const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); | 25 | |
34 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | 26 | static void aio_ret_cb(void *opaque, int ret) |
35 | int64_t cur_sector, int64_t nr_sectors); | 27 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
36 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, | 28 | *aio_ret = ret; |
37 | int64_t cur_sector, int64_t nr_sectors); | ||
38 | -int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, | ||
39 | - BdrvDirtyBitmap *bitmap, int64_t sector, | ||
40 | - int nb_sectors); | ||
41 | -int bdrv_dirty_bitmap_get_meta_locked(BlockDriverState *bs, | ||
42 | - BdrvDirtyBitmap *bitmap, int64_t sector, | ||
43 | - int nb_sectors); | ||
44 | -void bdrv_dirty_bitmap_reset_meta(BlockDriverState *bs, | ||
45 | - BdrvDirtyBitmap *bitmap, int64_t sector, | ||
46 | - int nb_sectors); | ||
47 | BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyBitmap *bitmap); | ||
48 | BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, | ||
49 | uint64_t first_sector); | ||
50 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/block/dirty-bitmap.c | ||
53 | +++ b/block/dirty-bitmap.c | ||
54 | @@ -XXX,XX +XXX,XX @@ void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap) | ||
55 | qemu_mutex_unlock(bitmap->mutex); | ||
56 | } | 29 | } |
57 | 30 | ||
58 | -int bdrv_dirty_bitmap_get_meta_locked(BlockDriverState *bs, | 31 | -static void test_drv_cb_drain_all(void) |
59 | - BdrvDirtyBitmap *bitmap, int64_t sector, | 32 | +enum drain_type { |
60 | - int nb_sectors) | 33 | + BDRV_DRAIN_ALL, |
61 | -{ | 34 | + BDRV_DRAIN, |
62 | - uint64_t i; | 35 | +}; |
63 | - int sectors_per_bit = 1 << hbitmap_granularity(bitmap->meta); | 36 | + |
64 | - | 37 | +static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs) |
65 | - /* To optimize: we can make hbitmap to internally check the range in a | 38 | +{ |
66 | - * coarse level, or at least do it word by word. */ | 39 | + switch (drain_type) { |
67 | - for (i = sector; i < sector + nb_sectors; i += sectors_per_bit) { | 40 | + case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; |
68 | - if (hbitmap_get(bitmap->meta, i)) { | 41 | + case BDRV_DRAIN: bdrv_drained_begin(bs); break; |
69 | - return true; | 42 | + default: g_assert_not_reached(); |
70 | - } | 43 | + } |
71 | - } | 44 | +} |
72 | - return false; | 45 | + |
73 | -} | 46 | +static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs) |
74 | - | 47 | +{ |
75 | -int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, | 48 | + switch (drain_type) { |
76 | - BdrvDirtyBitmap *bitmap, int64_t sector, | 49 | + case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; |
77 | - int nb_sectors) | 50 | + case BDRV_DRAIN: bdrv_drained_end(bs); break; |
78 | -{ | 51 | + default: g_assert_not_reached(); |
79 | - bool dirty; | 52 | + } |
80 | - | 53 | +} |
81 | - qemu_mutex_lock(bitmap->mutex); | 54 | + |
82 | - dirty = bdrv_dirty_bitmap_get_meta_locked(bs, bitmap, sector, nb_sectors); | 55 | +static void test_drv_cb_common(enum drain_type drain_type, bool recursive) |
83 | - qemu_mutex_unlock(bitmap->mutex); | ||
84 | - | ||
85 | - return dirty; | ||
86 | -} | ||
87 | - | ||
88 | -void bdrv_dirty_bitmap_reset_meta(BlockDriverState *bs, | ||
89 | - BdrvDirtyBitmap *bitmap, int64_t sector, | ||
90 | - int nb_sectors) | ||
91 | -{ | ||
92 | - qemu_mutex_lock(bitmap->mutex); | ||
93 | - hbitmap_reset(bitmap->meta, sector, nb_sectors); | ||
94 | - qemu_mutex_unlock(bitmap->mutex); | ||
95 | -} | ||
96 | - | ||
97 | int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap) | ||
98 | { | 56 | { |
99 | return bitmap->size; | 57 | BlockBackend *blk; |
100 | @@ -XXX,XX +XXX,XX @@ uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap) | 58 | - BlockDriverState *bs; |
101 | return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap); | 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); | ||
102 | } | 113 | } |
103 | 114 | ||
104 | -uint32_t bdrv_dirty_bitmap_meta_granularity(BdrvDirtyBitmap *bitmap) | 115 | +static void test_drv_cb_drain_all(void) |
105 | -{ | 116 | +{ |
106 | - return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->meta); | 117 | + test_drv_cb_common(BDRV_DRAIN_ALL, true); |
107 | -} | 118 | +} |
108 | - | 119 | + |
109 | BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, | 120 | +static void test_drv_cb_drain(void) |
110 | uint64_t first_sector) | 121 | +{ |
122 | + test_drv_cb_common(BDRV_DRAIN, false); | ||
123 | +} | ||
124 | + | ||
125 | int main(int argc, char **argv) | ||
111 | { | 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 | } | ||
112 | -- | 136 | -- |
113 | 2.13.6 | 137 | 2.13.6 |
114 | 138 | ||
115 | 139 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 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 | "check" is full of qemu-iotests--specific details. Separating it | ||
4 | from "common" does not make much sense anymore. | ||
5 | |||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | --- | 6 | --- |
10 | tests/qemu-iotests/check | 533 +++++++++++++++++++++++++++++++++++++++++++- | 7 | tests/test-bdrv-drain.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ |
11 | tests/qemu-iotests/common | 552 ---------------------------------------------- | 8 | 1 file changed, 45 insertions(+) |
12 | 2 files changed, 531 insertions(+), 554 deletions(-) | ||
13 | delete mode 100644 tests/qemu-iotests/common | ||
14 | 9 | ||
15 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 10 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
16 | index XXXXXXX..XXXXXXX 100755 | 11 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tests/qemu-iotests/check | 12 | --- a/tests/test-bdrv-drain.c |
18 | +++ b/tests/qemu-iotests/check | 13 | +++ b/tests/test-bdrv-drain.c |
19 | @@ -XXX,XX +XXX,XX @@ then | 14 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void) |
20 | _init_error "failed to source common.config" | 15 | test_drv_cb_common(BDRV_DRAIN, false); |
21 | fi | 16 | } |
22 | 17 | ||
23 | -# we need common | 18 | +static void test_quiesce_common(enum drain_type drain_type, bool recursive) |
24 | -. "$source_iotests/common" | ||
25 | +_full_imgfmt_details() | ||
26 | +{ | 19 | +{ |
27 | + if [ -n "$IMGOPTS" ]; then | 20 | + BlockBackend *blk; |
28 | + echo "$IMGFMT ($IMGOPTS)" | 21 | + BlockDriverState *bs, *backing; |
29 | + else | 22 | + |
30 | + echo "$IMGFMT" | 23 | + blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
31 | + fi | 24 | + bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, |
25 | + &error_abort); | ||
26 | + blk_insert_bs(blk, bs, &error_abort); | ||
27 | + | ||
28 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); | ||
29 | + bdrv_set_backing_hd(bs, backing, &error_abort); | ||
30 | + | ||
31 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); | ||
32 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); | ||
33 | + | ||
34 | + do_drain_begin(drain_type, bs); | ||
35 | + | ||
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); | ||
32 | +} | 47 | +} |
33 | + | 48 | + |
34 | +_full_platform_details() | 49 | +static void test_quiesce_drain_all(void) |
35 | +{ | 50 | +{ |
36 | + os=`uname -s` | 51 | + // XXX drain_all doesn't quiesce |
37 | + host=`hostname -s` | 52 | + //test_quiesce_common(BDRV_DRAIN_ALL, true); |
38 | + kernel=`uname -r` | ||
39 | + platform=`uname -m` | ||
40 | + echo "$os/$platform $host $kernel" | ||
41 | +} | 53 | +} |
42 | + | 54 | + |
43 | +# $1 = prog to look for | 55 | +static void test_quiesce_drain(void) |
44 | +set_prog_path() | ||
45 | +{ | 56 | +{ |
46 | + p=`command -v $1 2> /dev/null` | 57 | + test_quiesce_common(BDRV_DRAIN, false); |
47 | + if [ -n "$p" -a -x "$p" ]; then | ||
48 | + realpath -- "$(type -p "$p")" | ||
49 | + else | ||
50 | + return 1 | ||
51 | + fi | ||
52 | +} | 58 | +} |
53 | + | 59 | + |
54 | +if [ -z "$TEST_DIR" ]; then | 60 | int main(int argc, char **argv) |
55 | + TEST_DIR=`pwd`/scratch | 61 | { |
56 | +fi | 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); | ||
57 | + | 69 | + |
58 | +if [ ! -e "$TEST_DIR" ]; then | 70 | return g_test_run(); |
59 | + mkdir "$TEST_DIR" | 71 | } |
60 | +fi | ||
61 | + | ||
62 | +diff="diff -u" | ||
63 | +verbose=false | ||
64 | +debug=false | ||
65 | +group=false | ||
66 | +xgroup=false | ||
67 | +imgopts=false | ||
68 | +showme=false | ||
69 | +sortme=false | ||
70 | +expunge=true | ||
71 | +have_test_arg=false | ||
72 | +cachemode=false | ||
73 | + | ||
74 | +tmp="${TEST_DIR}"/$$ | ||
75 | +rm -f $tmp.list $tmp.tmp $tmp.sed | ||
76 | + | ||
77 | +export IMGFMT=raw | ||
78 | +export IMGFMT_GENERIC=true | ||
79 | +export IMGPROTO=file | ||
80 | +export IMGOPTS="" | ||
81 | +export CACHEMODE="writeback" | ||
82 | +export QEMU_IO_OPTIONS="" | ||
83 | +export QEMU_IO_OPTIONS_NO_FMT="" | ||
84 | +export CACHEMODE_IS_DEFAULT=true | ||
85 | +export QEMU_OPTIONS="-nodefaults -machine accel=qtest" | ||
86 | +export VALGRIND_QEMU= | ||
87 | +export IMGKEYSECRET= | ||
88 | +export IMGOPTSSYNTAX=false | ||
89 | + | ||
90 | +for r | ||
91 | +do | ||
92 | + | ||
93 | + if $group | ||
94 | + then | ||
95 | + # arg after -g | ||
96 | + group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | ||
97 | +s/ .*//p | ||
98 | +}'` | ||
99 | + if [ -z "$group_list" ] | ||
100 | + then | ||
101 | + echo "Group \"$r\" is empty or not defined?" | ||
102 | + exit 1 | ||
103 | + fi | ||
104 | + [ ! -s $tmp.list ] && touch $tmp.list | ||
105 | + for t in $group_list | ||
106 | + do | ||
107 | + if grep -s "^$t\$" $tmp.list >/dev/null | ||
108 | + then | ||
109 | + : | ||
110 | + else | ||
111 | + echo "$t" >>$tmp.list | ||
112 | + fi | ||
113 | + done | ||
114 | + group=false | ||
115 | + continue | ||
116 | + | ||
117 | + elif $xgroup | ||
118 | + then | ||
119 | + # arg after -x | ||
120 | + # Populate $tmp.list with all tests | ||
121 | + awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null | ||
122 | + group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | ||
123 | +s/ .*//p | ||
124 | +}'` | ||
125 | + if [ -z "$group_list" ] | ||
126 | + then | ||
127 | + echo "Group \"$r\" is empty or not defined?" | ||
128 | + exit 1 | ||
129 | + fi | ||
130 | + numsed=0 | ||
131 | + rm -f $tmp.sed | ||
132 | + for t in $group_list | ||
133 | + do | ||
134 | + if [ $numsed -gt 100 ] | ||
135 | + then | ||
136 | + sed -f $tmp.sed <$tmp.list >$tmp.tmp | ||
137 | + mv $tmp.tmp $tmp.list | ||
138 | + numsed=0 | ||
139 | + rm -f $tmp.sed | ||
140 | + fi | ||
141 | + echo "/^$t\$/d" >>$tmp.sed | ||
142 | + numsed=`expr $numsed + 1` | ||
143 | + done | ||
144 | + sed -f $tmp.sed <$tmp.list >$tmp.tmp | ||
145 | + mv $tmp.tmp $tmp.list | ||
146 | + xgroup=false | ||
147 | + continue | ||
148 | + | ||
149 | + elif $imgopts | ||
150 | + then | ||
151 | + IMGOPTS="$r" | ||
152 | + imgopts=false | ||
153 | + continue | ||
154 | + elif $cachemode | ||
155 | + then | ||
156 | + CACHEMODE="$r" | ||
157 | + CACHEMODE_IS_DEFAULT=false | ||
158 | + cachemode=false | ||
159 | + continue | ||
160 | + fi | ||
161 | + | ||
162 | + xpand=true | ||
163 | + case "$r" | ||
164 | + in | ||
165 | + | ||
166 | + -\? | -h | --help) # usage | ||
167 | + echo "Usage: $0 [options] [testlist]"' | ||
168 | + | ||
169 | +common options | ||
170 | + -v verbose | ||
171 | + -d debug | ||
172 | + | ||
173 | +image format options | ||
174 | + -raw test raw (default) | ||
175 | + -bochs test bochs | ||
176 | + -cloop test cloop | ||
177 | + -parallels test parallels | ||
178 | + -qcow test qcow | ||
179 | + -qcow2 test qcow2 | ||
180 | + -qed test qed | ||
181 | + -vdi test vdi | ||
182 | + -vpc test vpc | ||
183 | + -vhdx test vhdx | ||
184 | + -vmdk test vmdk | ||
185 | + -luks test luks | ||
186 | + | ||
187 | +image protocol options | ||
188 | + -file test file (default) | ||
189 | + -rbd test rbd | ||
190 | + -sheepdog test sheepdog | ||
191 | + -nbd test nbd | ||
192 | + -ssh test ssh | ||
193 | + -nfs test nfs | ||
194 | + -vxhs test vxhs | ||
195 | + | ||
196 | +other options | ||
197 | + -xdiff graphical mode diff | ||
198 | + -nocache use O_DIRECT on backing file | ||
199 | + -misalign misalign memory allocations | ||
200 | + -n show me, do not run tests | ||
201 | + -o options -o options to pass to qemu-img create/convert | ||
202 | + -T output timestamps | ||
203 | + -c mode cache mode | ||
204 | + | ||
205 | +testlist options | ||
206 | + -g group[,group...] include tests from these groups | ||
207 | + -x group[,group...] exclude tests from these groups | ||
208 | + NNN include test NNN | ||
209 | + NNN-NNN include test range (eg. 012-021) | ||
210 | +' | ||
211 | + exit 0 | ||
212 | + ;; | ||
213 | + | ||
214 | + -raw) | ||
215 | + IMGFMT=raw | ||
216 | + xpand=false | ||
217 | + ;; | ||
218 | + | ||
219 | + -bochs) | ||
220 | + IMGFMT=bochs | ||
221 | + IMGFMT_GENERIC=false | ||
222 | + xpand=false | ||
223 | + ;; | ||
224 | + | ||
225 | + -cloop) | ||
226 | + IMGFMT=cloop | ||
227 | + IMGFMT_GENERIC=false | ||
228 | + xpand=false | ||
229 | + ;; | ||
230 | + | ||
231 | + -parallels) | ||
232 | + IMGFMT=parallels | ||
233 | + IMGFMT_GENERIC=false | ||
234 | + xpand=false | ||
235 | + ;; | ||
236 | + | ||
237 | + -qcow) | ||
238 | + IMGFMT=qcow | ||
239 | + xpand=false | ||
240 | + ;; | ||
241 | + | ||
242 | + -qcow2) | ||
243 | + IMGFMT=qcow2 | ||
244 | + xpand=false | ||
245 | + ;; | ||
246 | + | ||
247 | + -luks) | ||
248 | + IMGOPTSSYNTAX=true | ||
249 | + IMGFMT=luks | ||
250 | + IMGKEYSECRET=123456 | ||
251 | + xpand=false | ||
252 | + ;; | ||
253 | + | ||
254 | + -qed) | ||
255 | + IMGFMT=qed | ||
256 | + xpand=false | ||
257 | + ;; | ||
258 | + | ||
259 | + -vdi) | ||
260 | + IMGFMT=vdi | ||
261 | + xpand=false | ||
262 | + ;; | ||
263 | + | ||
264 | + -vmdk) | ||
265 | + IMGFMT=vmdk | ||
266 | + xpand=false | ||
267 | + ;; | ||
268 | + | ||
269 | + -vpc) | ||
270 | + IMGFMT=vpc | ||
271 | + xpand=false | ||
272 | + ;; | ||
273 | + | ||
274 | + -vhdx) | ||
275 | + IMGFMT=vhdx | ||
276 | + xpand=false | ||
277 | + ;; | ||
278 | + | ||
279 | + -file) | ||
280 | + IMGPROTO=file | ||
281 | + xpand=false | ||
282 | + ;; | ||
283 | + | ||
284 | + -rbd) | ||
285 | + IMGPROTO=rbd | ||
286 | + xpand=false | ||
287 | + ;; | ||
288 | + | ||
289 | + -sheepdog) | ||
290 | + IMGPROTO=sheepdog | ||
291 | + xpand=false | ||
292 | + ;; | ||
293 | + | ||
294 | + -nbd) | ||
295 | + IMGPROTO=nbd | ||
296 | + xpand=false | ||
297 | + ;; | ||
298 | + | ||
299 | + -vxhs) | ||
300 | + IMGPROTO=vxhs | ||
301 | + xpand=false | ||
302 | + ;; | ||
303 | + | ||
304 | + -ssh) | ||
305 | + IMGPROTO=ssh | ||
306 | + xpand=false | ||
307 | + ;; | ||
308 | + | ||
309 | + -nfs) | ||
310 | + IMGPROTO=nfs | ||
311 | + xpand=false | ||
312 | + ;; | ||
313 | + | ||
314 | + -nocache) | ||
315 | + CACHEMODE="none" | ||
316 | + CACHEMODE_IS_DEFAULT=false | ||
317 | + xpand=false | ||
318 | + ;; | ||
319 | + | ||
320 | + -misalign) | ||
321 | + QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | ||
322 | + xpand=false | ||
323 | + ;; | ||
324 | + | ||
325 | + -valgrind) | ||
326 | + VALGRIND_QEMU='y' | ||
327 | + xpand=false | ||
328 | + ;; | ||
329 | + | ||
330 | + -g) # -g group ... pick from group file | ||
331 | + group=true | ||
332 | + xpand=false | ||
333 | + ;; | ||
334 | + | ||
335 | + -xdiff) # graphical diff mode | ||
336 | + xpand=false | ||
337 | + | ||
338 | + if [ ! -z "$DISPLAY" ] | ||
339 | + then | ||
340 | + command -v xdiff >/dev/null 2>&1 && diff=xdiff | ||
341 | + command -v gdiff >/dev/null 2>&1 && diff=gdiff | ||
342 | + command -v tkdiff >/dev/null 2>&1 && diff=tkdiff | ||
343 | + command -v xxdiff >/dev/null 2>&1 && diff=xxdiff | ||
344 | + fi | ||
345 | + ;; | ||
346 | + | ||
347 | + -n) # show me, don't do it | ||
348 | + showme=true | ||
349 | + xpand=false | ||
350 | + ;; | ||
351 | + -o) | ||
352 | + imgopts=true | ||
353 | + xpand=false | ||
354 | + ;; | ||
355 | + -c) | ||
356 | + cachemode=true | ||
357 | + xpand=false | ||
358 | + ;; | ||
359 | + -T) # turn on timestamp output | ||
360 | + timestamp=true | ||
361 | + xpand=false | ||
362 | + ;; | ||
363 | + | ||
364 | + -v) | ||
365 | + verbose=true | ||
366 | + xpand=false | ||
367 | + ;; | ||
368 | + -d) | ||
369 | + debug=true | ||
370 | + xpand=false | ||
371 | + ;; | ||
372 | + -x) # -x group ... exclude from group file | ||
373 | + xgroup=true | ||
374 | + xpand=false | ||
375 | + ;; | ||
376 | + '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') | ||
377 | + echo "No tests?" | ||
378 | + status=1 | ||
379 | + exit $status | ||
380 | + ;; | ||
381 | + | ||
382 | + [0-9]*-[0-9]*) | ||
383 | + eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | ||
384 | + ;; | ||
385 | + | ||
386 | + [0-9]*-) | ||
387 | + eval `echo $r | sed -e 's/^/start=/' -e 's/-//'` | ||
388 | + end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/ *$//' -e 's/.* //'` | ||
389 | + if [ -z "$end" ] | ||
390 | + then | ||
391 | + echo "No tests in range \"$r\"?" | ||
392 | + status=1 | ||
393 | + exit $status | ||
394 | + fi | ||
395 | + ;; | ||
396 | + | ||
397 | + *) | ||
398 | + start=$r | ||
399 | + end=$r | ||
400 | + ;; | ||
401 | + | ||
402 | + esac | ||
403 | + | ||
404 | + # get rid of leading 0s as can be interpreted as octal | ||
405 | + start=`echo $start | sed 's/^0*//'` | ||
406 | + end=`echo $end | sed 's/^0*//'` | ||
407 | + | ||
408 | + if $xpand | ||
409 | + then | ||
410 | + have_test_arg=true | ||
411 | + awk </dev/null ' | ||
412 | +BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | ||
413 | + | while read id | ||
414 | + do | ||
415 | + if grep -s "^$id " "$source_iotests/group" >/dev/null | ||
416 | + then | ||
417 | + # in group file ... OK | ||
418 | + echo $id >>$tmp.list | ||
419 | + else | ||
420 | + if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null | ||
421 | + then | ||
422 | + # expunged ... will be reported, but not run, later | ||
423 | + echo $id >>$tmp.list | ||
424 | + else | ||
425 | + # oops | ||
426 | + if [ "$start" == "$end" -a "$id" == "$end" ] | ||
427 | + then | ||
428 | + echo "$id - unknown test" | ||
429 | + exit 1 | ||
430 | + else | ||
431 | + echo "$id - unknown test, ignored" | ||
432 | + fi | ||
433 | + fi | ||
434 | + fi | ||
435 | + done || exit 1 | ||
436 | + fi | ||
437 | + | ||
438 | +done | ||
439 | + | ||
440 | +# Set qemu-io cache mode with $CACHEMODE we have | ||
441 | +QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE" | ||
442 | + | ||
443 | +QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS" | ||
444 | +if [ "$IMGOPTSSYNTAX" != "true" ]; then | ||
445 | + QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT" | ||
446 | +fi | ||
447 | + | ||
448 | +# Set default options for qemu-img create -o if they were not specified | ||
449 | +if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then | ||
450 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1") | ||
451 | +fi | ||
452 | +if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then | ||
453 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10") | ||
454 | +fi | ||
455 | + | ||
456 | +if [ -z "$SAMPLE_IMG_DIR" ]; then | ||
457 | + SAMPLE_IMG_DIR="$source_iotests/sample_images" | ||
458 | +fi | ||
459 | + | ||
460 | +export TEST_DIR | ||
461 | +export SAMPLE_IMG_DIR | ||
462 | + | ||
463 | +if [ -s $tmp.list ] | ||
464 | +then | ||
465 | + # found some valid test numbers ... this is good | ||
466 | + : | ||
467 | +else | ||
468 | + if $have_test_arg | ||
469 | + then | ||
470 | + # had test numbers, but none in group file ... do nothing | ||
471 | + touch $tmp.list | ||
472 | + else | ||
473 | + # no test numbers, do everything from group file | ||
474 | + sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list | ||
475 | + fi | ||
476 | +fi | ||
477 | + | ||
478 | +# should be sort -n, but this did not work for Linux when this | ||
479 | +# was ported from IRIX | ||
480 | +# | ||
481 | +list=`sort $tmp.list` | ||
482 | +rm -f $tmp.list $tmp.tmp $tmp.sed | ||
483 | + | ||
484 | +if [ -z "$QEMU_PROG" ] | ||
485 | +then | ||
486 | + if [ -x "$build_iotests/qemu" ]; then | ||
487 | + export QEMU_PROG="$build_iotests/qemu" | ||
488 | + elif [ -x "$build_root/$arch-softmmu/qemu-system-$arch" ]; then | ||
489 | + export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch" | ||
490 | + else | ||
491 | + pushd "$build_root" > /dev/null | ||
492 | + for binary in *-softmmu/qemu-system-* | ||
493 | + do | ||
494 | + if [ -x "$binary" ] | ||
495 | + then | ||
496 | + export QEMU_PROG="$build_root/$binary" | ||
497 | + break | ||
498 | + fi | ||
499 | + done | ||
500 | + popd > /dev/null | ||
501 | + [ "$QEMU_PROG" = "" ] && _init_error "qemu not found" | ||
502 | + fi | ||
503 | +fi | ||
504 | +export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")") | ||
505 | + | ||
506 | +if [ -z "$QEMU_IMG_PROG" ]; then | ||
507 | + if [ -x "$build_iotests/qemu-img" ]; then | ||
508 | + export QEMU_IMG_PROG="$build_iotests/qemu-img" | ||
509 | + elif [ -x "$build_root/qemu-img" ]; then | ||
510 | + export QEMU_IMG_PROG="$build_root/qemu-img" | ||
511 | + else | ||
512 | + _init_error "qemu-img not found" | ||
513 | + fi | ||
514 | +fi | ||
515 | +export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")") | ||
516 | + | ||
517 | +if [ -z "$QEMU_IO_PROG" ]; then | ||
518 | + if [ -x "$build_iotests/qemu-io" ]; then | ||
519 | + export QEMU_IO_PROG="$build_iotests/qemu-io" | ||
520 | + elif [ -x "$build_root/qemu-io" ]; then | ||
521 | + export QEMU_IO_PROG="$build_root/qemu-io" | ||
522 | + else | ||
523 | + _init_error "qemu-io not found" | ||
524 | + fi | ||
525 | +fi | ||
526 | +export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")") | ||
527 | + | ||
528 | +if [ -z $QEMU_NBD_PROG ]; then | ||
529 | + if [ -x "$build_iotests/qemu-nbd" ]; then | ||
530 | + export QEMU_NBD_PROG="$build_iotests/qemu-nbd" | ||
531 | + elif [ -x "$build_root/qemu-nbd" ]; then | ||
532 | + export QEMU_NBD_PROG="$build_root/qemu-nbd" | ||
533 | + else | ||
534 | + _init_error "qemu-nbd not found" | ||
535 | + fi | ||
536 | +fi | ||
537 | +export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")") | ||
538 | + | ||
539 | +if [ -z "$QEMU_VXHS_PROG" ]; then | ||
540 | + export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | ||
541 | +fi | ||
542 | + | ||
543 | +if [ -x "$build_iotests/socket_scm_helper" ] | ||
544 | +then | ||
545 | + export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | ||
546 | +fi | ||
547 | + | ||
548 | +default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p') | ||
549 | +default_alias_machine=$($QEMU_PROG -machine help | \ | ||
550 | + sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | ||
551 | +if [[ "$default_alias_machine" ]]; then | ||
552 | + default_machine="$default_alias_machine" | ||
553 | +fi | ||
554 | + | ||
555 | +export QEMU_DEFAULT_MACHINE="$default_machine" | ||
556 | |||
557 | TIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT | ||
558 | |||
559 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | ||
560 | deleted file mode 100644 | ||
561 | index XXXXXXX..XXXXXXX | ||
562 | --- a/tests/qemu-iotests/common | ||
563 | +++ /dev/null | ||
564 | @@ -XXX,XX +XXX,XX @@ | ||
565 | -#!/bin/bash | ||
566 | -# | ||
567 | -# Copyright (C) 2009 Red Hat, Inc. | ||
568 | -# Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved. | ||
569 | -# | ||
570 | -# This program is free software; you can redistribute it and/or | ||
571 | -# modify it under the terms of the GNU General Public License as | ||
572 | -# published by the Free Software Foundation. | ||
573 | -# | ||
574 | -# This program is distributed in the hope that it would be useful, | ||
575 | -# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
576 | -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
577 | -# GNU General Public License for more details. | ||
578 | -# | ||
579 | -# You should have received a copy of the GNU General Public License | ||
580 | -# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
581 | -# | ||
582 | -# | ||
583 | -# common procedures for QA scripts | ||
584 | -# | ||
585 | - | ||
586 | -_full_imgfmt_details() | ||
587 | -{ | ||
588 | - if [ -n "$IMGOPTS" ]; then | ||
589 | - echo "$IMGFMT ($IMGOPTS)" | ||
590 | - else | ||
591 | - echo "$IMGFMT" | ||
592 | - fi | ||
593 | -} | ||
594 | - | ||
595 | -_full_platform_details() | ||
596 | -{ | ||
597 | - os=`uname -s` | ||
598 | - host=`hostname -s` | ||
599 | - kernel=`uname -r` | ||
600 | - platform=`uname -m` | ||
601 | - echo "$os/$platform $host $kernel" | ||
602 | -} | ||
603 | - | ||
604 | -# $1 = prog to look for | ||
605 | -set_prog_path() | ||
606 | -{ | ||
607 | - p=`command -v $1 2> /dev/null` | ||
608 | - if [ -n "$p" -a -x "$p" ]; then | ||
609 | - realpath -- "$(type -p "$p")" | ||
610 | - else | ||
611 | - return 1 | ||
612 | - fi | ||
613 | -} | ||
614 | - | ||
615 | -if [ -z "$TEST_DIR" ]; then | ||
616 | - TEST_DIR=`pwd`/scratch | ||
617 | -fi | ||
618 | - | ||
619 | -if [ ! -e "$TEST_DIR" ]; then | ||
620 | - mkdir "$TEST_DIR" | ||
621 | -fi | ||
622 | - | ||
623 | -diff="diff -u" | ||
624 | -verbose=false | ||
625 | -debug=false | ||
626 | -group=false | ||
627 | -xgroup=false | ||
628 | -imgopts=false | ||
629 | -showme=false | ||
630 | -sortme=false | ||
631 | -expunge=true | ||
632 | -have_test_arg=false | ||
633 | -cachemode=false | ||
634 | - | ||
635 | -tmp="${TEST_DIR}"/$$ | ||
636 | -rm -f $tmp.list $tmp.tmp $tmp.sed | ||
637 | - | ||
638 | -export IMGFMT=raw | ||
639 | -export IMGFMT_GENERIC=true | ||
640 | -export IMGPROTO=file | ||
641 | -export IMGOPTS="" | ||
642 | -export CACHEMODE="writeback" | ||
643 | -export QEMU_IO_OPTIONS="" | ||
644 | -export QEMU_IO_OPTIONS_NO_FMT="" | ||
645 | -export CACHEMODE_IS_DEFAULT=true | ||
646 | -export QEMU_OPTIONS="-nodefaults -machine accel=qtest" | ||
647 | -export VALGRIND_QEMU= | ||
648 | -export IMGKEYSECRET= | ||
649 | -export IMGOPTSSYNTAX=false | ||
650 | - | ||
651 | -for r | ||
652 | -do | ||
653 | - | ||
654 | - if $group | ||
655 | - then | ||
656 | - # arg after -g | ||
657 | - group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | ||
658 | -s/ .*//p | ||
659 | -}'` | ||
660 | - if [ -z "$group_list" ] | ||
661 | - then | ||
662 | - echo "Group \"$r\" is empty or not defined?" | ||
663 | - exit 1 | ||
664 | - fi | ||
665 | - [ ! -s $tmp.list ] && touch $tmp.list | ||
666 | - for t in $group_list | ||
667 | - do | ||
668 | - if grep -s "^$t\$" $tmp.list >/dev/null | ||
669 | - then | ||
670 | - : | ||
671 | - else | ||
672 | - echo "$t" >>$tmp.list | ||
673 | - fi | ||
674 | - done | ||
675 | - group=false | ||
676 | - continue | ||
677 | - | ||
678 | - elif $xgroup | ||
679 | - then | ||
680 | - # arg after -x | ||
681 | - # Populate $tmp.list with all tests | ||
682 | - awk '/^[0-9]{3,}/ {print $1}' "${source_iotests}/group" > $tmp.list 2>/dev/null | ||
683 | - group_list=`sed -n <"$source_iotests/group" -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{ | ||
684 | -s/ .*//p | ||
685 | -}'` | ||
686 | - if [ -z "$group_list" ] | ||
687 | - then | ||
688 | - echo "Group \"$r\" is empty or not defined?" | ||
689 | - exit 1 | ||
690 | - fi | ||
691 | - numsed=0 | ||
692 | - rm -f $tmp.sed | ||
693 | - for t in $group_list | ||
694 | - do | ||
695 | - if [ $numsed -gt 100 ] | ||
696 | - then | ||
697 | - sed -f $tmp.sed <$tmp.list >$tmp.tmp | ||
698 | - mv $tmp.tmp $tmp.list | ||
699 | - numsed=0 | ||
700 | - rm -f $tmp.sed | ||
701 | - fi | ||
702 | - echo "/^$t\$/d" >>$tmp.sed | ||
703 | - numsed=`expr $numsed + 1` | ||
704 | - done | ||
705 | - sed -f $tmp.sed <$tmp.list >$tmp.tmp | ||
706 | - mv $tmp.tmp $tmp.list | ||
707 | - xgroup=false | ||
708 | - continue | ||
709 | - | ||
710 | - elif $imgopts | ||
711 | - then | ||
712 | - IMGOPTS="$r" | ||
713 | - imgopts=false | ||
714 | - continue | ||
715 | - elif $cachemode | ||
716 | - then | ||
717 | - CACHEMODE="$r" | ||
718 | - CACHEMODE_IS_DEFAULT=false | ||
719 | - cachemode=false | ||
720 | - continue | ||
721 | - fi | ||
722 | - | ||
723 | - xpand=true | ||
724 | - case "$r" | ||
725 | - in | ||
726 | - | ||
727 | - -\? | -h | --help) # usage | ||
728 | - echo "Usage: $0 [options] [testlist]"' | ||
729 | - | ||
730 | -common options | ||
731 | - -v verbose | ||
732 | - -d debug | ||
733 | - | ||
734 | -image format options | ||
735 | - -raw test raw (default) | ||
736 | - -bochs test bochs | ||
737 | - -cloop test cloop | ||
738 | - -parallels test parallels | ||
739 | - -qcow test qcow | ||
740 | - -qcow2 test qcow2 | ||
741 | - -qed test qed | ||
742 | - -vdi test vdi | ||
743 | - -vpc test vpc | ||
744 | - -vhdx test vhdx | ||
745 | - -vmdk test vmdk | ||
746 | - -luks test luks | ||
747 | - | ||
748 | -image protocol options | ||
749 | - -file test file (default) | ||
750 | - -rbd test rbd | ||
751 | - -sheepdog test sheepdog | ||
752 | - -nbd test nbd | ||
753 | - -ssh test ssh | ||
754 | - -nfs test nfs | ||
755 | - -vxhs test vxhs | ||
756 | - | ||
757 | -other options | ||
758 | - -xdiff graphical mode diff | ||
759 | - -nocache use O_DIRECT on backing file | ||
760 | - -misalign misalign memory allocations | ||
761 | - -n show me, do not run tests | ||
762 | - -o options -o options to pass to qemu-img create/convert | ||
763 | - -T output timestamps | ||
764 | - -c mode cache mode | ||
765 | - | ||
766 | -testlist options | ||
767 | - -g group[,group...] include tests from these groups | ||
768 | - -x group[,group...] exclude tests from these groups | ||
769 | - NNN include test NNN | ||
770 | - NNN-NNN include test range (eg. 012-021) | ||
771 | -' | ||
772 | - exit 0 | ||
773 | - ;; | ||
774 | - | ||
775 | - -raw) | ||
776 | - IMGFMT=raw | ||
777 | - xpand=false | ||
778 | - ;; | ||
779 | - | ||
780 | - -bochs) | ||
781 | - IMGFMT=bochs | ||
782 | - IMGFMT_GENERIC=false | ||
783 | - xpand=false | ||
784 | - ;; | ||
785 | - | ||
786 | - -cloop) | ||
787 | - IMGFMT=cloop | ||
788 | - IMGFMT_GENERIC=false | ||
789 | - xpand=false | ||
790 | - ;; | ||
791 | - | ||
792 | - -parallels) | ||
793 | - IMGFMT=parallels | ||
794 | - IMGFMT_GENERIC=false | ||
795 | - xpand=false | ||
796 | - ;; | ||
797 | - | ||
798 | - -qcow) | ||
799 | - IMGFMT=qcow | ||
800 | - xpand=false | ||
801 | - ;; | ||
802 | - | ||
803 | - -qcow2) | ||
804 | - IMGFMT=qcow2 | ||
805 | - xpand=false | ||
806 | - ;; | ||
807 | - | ||
808 | - -luks) | ||
809 | - IMGOPTSSYNTAX=true | ||
810 | - IMGFMT=luks | ||
811 | - IMGKEYSECRET=123456 | ||
812 | - xpand=false | ||
813 | - ;; | ||
814 | - | ||
815 | - -qed) | ||
816 | - IMGFMT=qed | ||
817 | - xpand=false | ||
818 | - ;; | ||
819 | - | ||
820 | - -vdi) | ||
821 | - IMGFMT=vdi | ||
822 | - xpand=false | ||
823 | - ;; | ||
824 | - | ||
825 | - -vmdk) | ||
826 | - IMGFMT=vmdk | ||
827 | - xpand=false | ||
828 | - ;; | ||
829 | - | ||
830 | - -vpc) | ||
831 | - IMGFMT=vpc | ||
832 | - xpand=false | ||
833 | - ;; | ||
834 | - | ||
835 | - -vhdx) | ||
836 | - IMGFMT=vhdx | ||
837 | - xpand=false | ||
838 | - ;; | ||
839 | - | ||
840 | - -file) | ||
841 | - IMGPROTO=file | ||
842 | - xpand=false | ||
843 | - ;; | ||
844 | - | ||
845 | - -rbd) | ||
846 | - IMGPROTO=rbd | ||
847 | - xpand=false | ||
848 | - ;; | ||
849 | - | ||
850 | - -sheepdog) | ||
851 | - IMGPROTO=sheepdog | ||
852 | - xpand=false | ||
853 | - ;; | ||
854 | - | ||
855 | - -nbd) | ||
856 | - IMGPROTO=nbd | ||
857 | - xpand=false | ||
858 | - ;; | ||
859 | - | ||
860 | - -vxhs) | ||
861 | - IMGPROTO=vxhs | ||
862 | - xpand=false | ||
863 | - ;; | ||
864 | - | ||
865 | - -ssh) | ||
866 | - IMGPROTO=ssh | ||
867 | - xpand=false | ||
868 | - ;; | ||
869 | - | ||
870 | - -nfs) | ||
871 | - IMGPROTO=nfs | ||
872 | - xpand=false | ||
873 | - ;; | ||
874 | - | ||
875 | - -nocache) | ||
876 | - CACHEMODE="none" | ||
877 | - CACHEMODE_IS_DEFAULT=false | ||
878 | - xpand=false | ||
879 | - ;; | ||
880 | - | ||
881 | - -misalign) | ||
882 | - QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --misalign" | ||
883 | - xpand=false | ||
884 | - ;; | ||
885 | - | ||
886 | - -valgrind) | ||
887 | - VALGRIND_QEMU='y' | ||
888 | - xpand=false | ||
889 | - ;; | ||
890 | - | ||
891 | - -g) # -g group ... pick from group file | ||
892 | - group=true | ||
893 | - xpand=false | ||
894 | - ;; | ||
895 | - | ||
896 | - -xdiff) # graphical diff mode | ||
897 | - xpand=false | ||
898 | - | ||
899 | - if [ ! -z "$DISPLAY" ] | ||
900 | - then | ||
901 | - command -v xdiff >/dev/null 2>&1 && diff=xdiff | ||
902 | - command -v gdiff >/dev/null 2>&1 && diff=gdiff | ||
903 | - command -v tkdiff >/dev/null 2>&1 && diff=tkdiff | ||
904 | - command -v xxdiff >/dev/null 2>&1 && diff=xxdiff | ||
905 | - fi | ||
906 | - ;; | ||
907 | - | ||
908 | - -n) # show me, don't do it | ||
909 | - showme=true | ||
910 | - xpand=false | ||
911 | - ;; | ||
912 | - -o) | ||
913 | - imgopts=true | ||
914 | - xpand=false | ||
915 | - ;; | ||
916 | - -c) | ||
917 | - cachemode=true | ||
918 | - xpand=false | ||
919 | - ;; | ||
920 | - -T) # turn on timestamp output | ||
921 | - timestamp=true | ||
922 | - xpand=false | ||
923 | - ;; | ||
924 | - | ||
925 | - -v) | ||
926 | - verbose=true | ||
927 | - xpand=false | ||
928 | - ;; | ||
929 | - -d) | ||
930 | - debug=true | ||
931 | - xpand=false | ||
932 | - ;; | ||
933 | - -x) # -x group ... exclude from group file | ||
934 | - xgroup=true | ||
935 | - xpand=false | ||
936 | - ;; | ||
937 | - '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]') | ||
938 | - echo "No tests?" | ||
939 | - status=1 | ||
940 | - exit $status | ||
941 | - ;; | ||
942 | - | ||
943 | - [0-9]*-[0-9]*) | ||
944 | - eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'` | ||
945 | - ;; | ||
946 | - | ||
947 | - [0-9]*-) | ||
948 | - eval `echo $r | sed -e 's/^/start=/' -e 's/-//'` | ||
949 | - end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/ *$//' -e 's/.* //'` | ||
950 | - if [ -z "$end" ] | ||
951 | - then | ||
952 | - echo "No tests in range \"$r\"?" | ||
953 | - status=1 | ||
954 | - exit $status | ||
955 | - fi | ||
956 | - ;; | ||
957 | - | ||
958 | - *) | ||
959 | - start=$r | ||
960 | - end=$r | ||
961 | - ;; | ||
962 | - | ||
963 | - esac | ||
964 | - | ||
965 | - # get rid of leading 0s as can be interpreted as octal | ||
966 | - start=`echo $start | sed 's/^0*//'` | ||
967 | - end=`echo $end | sed 's/^0*//'` | ||
968 | - | ||
969 | - if $xpand | ||
970 | - then | ||
971 | - have_test_arg=true | ||
972 | - awk </dev/null ' | ||
973 | -BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | ||
974 | - | while read id | ||
975 | - do | ||
976 | - if grep -s "^$id " "$source_iotests/group" >/dev/null | ||
977 | - then | ||
978 | - # in group file ... OK | ||
979 | - echo $id >>$tmp.list | ||
980 | - else | ||
981 | - if [ -f expunged ] && $expunge && egrep "^$id([ ]|\$)" expunged >/dev/null | ||
982 | - then | ||
983 | - # expunged ... will be reported, but not run, later | ||
984 | - echo $id >>$tmp.list | ||
985 | - else | ||
986 | - # oops | ||
987 | - if [ "$start" == "$end" -a "$id" == "$end" ] | ||
988 | - then | ||
989 | - echo "$id - unknown test" | ||
990 | - exit 1 | ||
991 | - else | ||
992 | - echo "$id - unknown test, ignored" | ||
993 | - fi | ||
994 | - fi | ||
995 | - fi | ||
996 | - done || exit 1 | ||
997 | - fi | ||
998 | - | ||
999 | -done | ||
1000 | - | ||
1001 | -# Set qemu-io cache mode with $CACHEMODE we have | ||
1002 | -QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS --cache $CACHEMODE" | ||
1003 | - | ||
1004 | -QEMU_IO_OPTIONS_NO_FMT="$QEMU_IO_OPTIONS" | ||
1005 | -if [ "$IMGOPTSSYNTAX" != "true" ]; then | ||
1006 | - QEMU_IO_OPTIONS="$QEMU_IO_OPTIONS -f $IMGFMT" | ||
1007 | -fi | ||
1008 | - | ||
1009 | -# Set default options for qemu-img create -o if they were not specified | ||
1010 | -if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then | ||
1011 | - IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1") | ||
1012 | -fi | ||
1013 | -if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then | ||
1014 | - IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10") | ||
1015 | -fi | ||
1016 | - | ||
1017 | -if [ -z "$SAMPLE_IMG_DIR" ]; then | ||
1018 | - SAMPLE_IMG_DIR="$source_iotests/sample_images" | ||
1019 | -fi | ||
1020 | - | ||
1021 | -export TEST_DIR | ||
1022 | -export SAMPLE_IMG_DIR | ||
1023 | - | ||
1024 | -if [ -s $tmp.list ] | ||
1025 | -then | ||
1026 | - # found some valid test numbers ... this is good | ||
1027 | - : | ||
1028 | -else | ||
1029 | - if $have_test_arg | ||
1030 | - then | ||
1031 | - # had test numbers, but none in group file ... do nothing | ||
1032 | - touch $tmp.list | ||
1033 | - else | ||
1034 | - # no test numbers, do everything from group file | ||
1035 | - sed -n -e '/^[0-9][0-9][0-9]*/s/[ ].*//p' <"$source_iotests/group" >$tmp.list | ||
1036 | - fi | ||
1037 | -fi | ||
1038 | - | ||
1039 | -# should be sort -n, but this did not work for Linux when this | ||
1040 | -# was ported from IRIX | ||
1041 | -# | ||
1042 | -list=`sort $tmp.list` | ||
1043 | -rm -f $tmp.list $tmp.tmp $tmp.sed | ||
1044 | - | ||
1045 | -if [ -z "$QEMU_PROG" ] | ||
1046 | -then | ||
1047 | - if [ -x "$build_iotests/qemu" ]; then | ||
1048 | - export QEMU_PROG="$build_iotests/qemu" | ||
1049 | - elif [ -x "$build_root/$arch-softmmu/qemu-system-$arch" ]; then | ||
1050 | - export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch" | ||
1051 | - else | ||
1052 | - pushd "$build_root" > /dev/null | ||
1053 | - for binary in *-softmmu/qemu-system-* | ||
1054 | - do | ||
1055 | - if [ -x "$binary" ] | ||
1056 | - then | ||
1057 | - export QEMU_PROG="$build_root/$binary" | ||
1058 | - break | ||
1059 | - fi | ||
1060 | - done | ||
1061 | - popd > /dev/null | ||
1062 | - [ "$QEMU_PROG" = "" ] && _init_error "qemu not found" | ||
1063 | - fi | ||
1064 | -fi | ||
1065 | -export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")") | ||
1066 | - | ||
1067 | -if [ -z "$QEMU_IMG_PROG" ]; then | ||
1068 | - if [ -x "$build_iotests/qemu-img" ]; then | ||
1069 | - export QEMU_IMG_PROG="$build_iotests/qemu-img" | ||
1070 | - elif [ -x "$build_root/qemu-img" ]; then | ||
1071 | - export QEMU_IMG_PROG="$build_root/qemu-img" | ||
1072 | - else | ||
1073 | - _init_error "qemu-img not found" | ||
1074 | - fi | ||
1075 | -fi | ||
1076 | -export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")") | ||
1077 | - | ||
1078 | -if [ -z "$QEMU_IO_PROG" ]; then | ||
1079 | - if [ -x "$build_iotests/qemu-io" ]; then | ||
1080 | - export QEMU_IO_PROG="$build_iotests/qemu-io" | ||
1081 | - elif [ -x "$build_root/qemu-io" ]; then | ||
1082 | - export QEMU_IO_PROG="$build_root/qemu-io" | ||
1083 | - else | ||
1084 | - _init_error "qemu-io not found" | ||
1085 | - fi | ||
1086 | -fi | ||
1087 | -export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")") | ||
1088 | - | ||
1089 | -if [ -z $QEMU_NBD_PROG ]; then | ||
1090 | - if [ -x "$build_iotests/qemu-nbd" ]; then | ||
1091 | - export QEMU_NBD_PROG="$build_iotests/qemu-nbd" | ||
1092 | - elif [ -x "$build_root/qemu-nbd" ]; then | ||
1093 | - export QEMU_NBD_PROG="$build_root/qemu-nbd" | ||
1094 | - else | ||
1095 | - _init_error "qemu-nbd not found" | ||
1096 | - fi | ||
1097 | -fi | ||
1098 | -export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")") | ||
1099 | - | ||
1100 | -if [ -z "$QEMU_VXHS_PROG" ]; then | ||
1101 | - export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | ||
1102 | -fi | ||
1103 | - | ||
1104 | -if [ -x "$build_iotests/socket_scm_helper" ] | ||
1105 | -then | ||
1106 | - export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | ||
1107 | -fi | ||
1108 | - | ||
1109 | -default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p') | ||
1110 | -default_alias_machine=$($QEMU_PROG -machine help | \ | ||
1111 | - sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | ||
1112 | -if [[ "$default_alias_machine" ]]; then | ||
1113 | - default_machine="$default_alias_machine" | ||
1114 | -fi | ||
1115 | - | ||
1116 | -export QEMU_DEFAULT_MACHINE="$default_machine" | ||
1117 | -- | 72 | -- |
1118 | 2.13.6 | 73 | 2.13.6 |
1119 | 74 | ||
1120 | 75 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@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 | This includes shell function, shell variables and command line options | 6 | This implements .drained_begin/end callbacks in child_job in order to |
4 | (randomize.awk does not exist). | 7 | consider all block nodes related to the job, and removes the |
8 | BlockBackend callbacks which are unnecessary now because the root of the | ||
9 | job main BlockBackend is always referenced with a child_job, too. | ||
5 | 10 | ||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
9 | --- | 12 | --- |
10 | tests/qemu-iotests/check | 28 ----------------- | 13 | blockjob.c | 22 +++++++++------------- |
11 | tests/qemu-iotests/common | 23 -------------- | 14 | 1 file changed, 9 insertions(+), 13 deletions(-) |
12 | tests/qemu-iotests/common.config | 26 --------------- | ||
13 | tests/qemu-iotests/common.rc | 68 ---------------------------------------- | ||
14 | 4 files changed, 145 deletions(-) | ||
15 | 15 | ||
16 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 16 | diff --git a/blockjob.c b/blockjob.c |
17 | index XXXXXXX..XXXXXXX 100755 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/qemu-iotests/check | 18 | --- a/blockjob.c |
19 | +++ b/tests/qemu-iotests/check | 19 | +++ b/blockjob.c |
20 | @@ -XXX,XX +XXX,XX @@ then | 20 | @@ -XXX,XX +XXX,XX @@ static char *child_job_get_parent_desc(BdrvChild *c) |
21 | export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | 21 | job->id); |
22 | fi | 22 | } |
23 | 23 | ||
24 | -# if ./qemu exists, it should be prioritized and will be chosen by common.config | 24 | -static const BdrvChildRole child_job = { |
25 | if [[ -z "$QEMU_PROG" && ! -x './qemu' ]] | 25 | - .get_parent_desc = child_job_get_parent_desc, |
26 | then | 26 | - .stay_at_node = true, |
27 | arch=$(uname -m 2> /dev/null) | 27 | -}; |
28 | @@ -XXX,XX +XXX,XX @@ _timestamp() | 28 | - |
29 | 29 | -static void block_job_drained_begin(void *opaque) | |
30 | _wrapup() | 30 | +static void child_job_drained_begin(BdrvChild *c) |
31 | { | 31 | { |
32 | - # for hangcheck ... | 32 | - BlockJob *job = opaque; |
33 | - # remove files that were used by hangcheck | 33 | + BlockJob *job = c->opaque; |
34 | - # | 34 | block_job_pause(job); |
35 | - [ -f "${TEST_DIR}"/check.pid ] && rm -rf "${TEST_DIR}"/check.pid | ||
36 | - [ -f "${TEST_DIR}"/check.sts ] && rm -rf "${TEST_DIR}"/check.sts | ||
37 | - | ||
38 | if $showme | ||
39 | then | ||
40 | : | ||
41 | @@ -XXX,XX +XXX,XX @@ END { if (NR > 0) { | ||
42 | |||
43 | trap "_wrapup; exit \$status" 0 1 2 3 15 | ||
44 | |||
45 | -# for hangcheck ... | ||
46 | -# Save pid of check in a well known place, so that hangcheck can be sure it | ||
47 | -# has the right pid (getting the pid from ps output is not reliable enough). | ||
48 | -# | ||
49 | -rm -rf "${TEST_DIR}"/check.pid | ||
50 | -echo $$ > "${TEST_DIR}"/check.pid | ||
51 | - | ||
52 | -# for hangcheck ... | ||
53 | -# Save the status of check in a well known place, so that hangcheck can be | ||
54 | -# sure to know where check is up to (getting test number from ps output is | ||
55 | -# not reliable enough since the trace stuff has been introduced). | ||
56 | -# | ||
57 | -rm -rf "${TEST_DIR}"/check.sts | ||
58 | -echo "preamble" > "${TEST_DIR}"/check.sts | ||
59 | - | ||
60 | -# don't leave old full output behind on a clean run | ||
61 | -rm -f check.full | ||
62 | - | ||
63 | [ -f $TIMESTAMP_FILE ] || touch $TIMESTAMP_FILE | ||
64 | |||
65 | FULL_IMGFMT_DETAILS=`_full_imgfmt_details` | ||
66 | @@ -XXX,XX +XXX,XX @@ do | ||
67 | fi | ||
68 | rm -f core $seq.notrun | ||
69 | |||
70 | - # for hangcheck ... | ||
71 | - echo "$seq" > "${TEST_DIR}"/check.sts | ||
72 | - | ||
73 | start=`_wallclock` | ||
74 | $timestamp && printf %s " [$(date "+%T")]" | ||
75 | |||
76 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/tests/qemu-iotests/common | ||
79 | +++ b/tests/qemu-iotests/common | ||
80 | @@ -XXX,XX +XXX,XX @@ | ||
81 | # common procedures for QA scripts | ||
82 | # | ||
83 | |||
84 | -_setenvironment() | ||
85 | -{ | ||
86 | - MSGVERB="text:action" | ||
87 | - export MSGVERB | ||
88 | -} | ||
89 | - | ||
90 | -rm -f "$OUTPUT_DIR/$iam.out" | ||
91 | -_setenvironment | ||
92 | - | ||
93 | -check=${check-true} | ||
94 | - | ||
95 | diff="diff -u" | ||
96 | verbose=false | ||
97 | debug=false | ||
98 | @@ -XXX,XX +XXX,XX @@ showme=false | ||
99 | sortme=false | ||
100 | expunge=true | ||
101 | have_test_arg=false | ||
102 | -randomize=false | ||
103 | cachemode=false | ||
104 | rm -f $tmp.list $tmp.tmp $tmp.sed | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ other options | ||
107 | -n show me, do not run tests | ||
108 | -o options -o options to pass to qemu-img create/convert | ||
109 | -T output timestamps | ||
110 | - -r randomize test order | ||
111 | -c mode cache mode | ||
112 | |||
113 | testlist options | ||
114 | @@ -XXX,XX +XXX,XX @@ testlist options | ||
115 | cachemode=true | ||
116 | xpand=false | ||
117 | ;; | ||
118 | - -r) # randomize test order | ||
119 | - randomize=true | ||
120 | - xpand=false | ||
121 | - ;; | ||
122 | - | ||
123 | -T) # turn on timestamp output | ||
124 | timestamp=true | ||
125 | xpand=false | ||
126 | @@ -XXX,XX +XXX,XX @@ fi | ||
127 | list=`sort $tmp.list` | ||
128 | rm -f $tmp.list $tmp.tmp $tmp.sed | ||
129 | |||
130 | -if $randomize | ||
131 | -then | ||
132 | - list=`echo $list | awk -f randomize.awk` | ||
133 | -fi | ||
134 | - | ||
135 | [ "$QEMU" = "" ] && _fatal "qemu not found" | ||
136 | [ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | ||
137 | [ "$QEMU_IO" = "" ] && _fatal "qemu-io not found" | ||
138 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
139 | index XXXXXXX..XXXXXXX 100644 | ||
140 | --- a/tests/qemu-iotests/common.config | ||
141 | +++ b/tests/qemu-iotests/common.config | ||
142 | @@ -XXX,XX +XXX,XX @@ | ||
143 | # You should have received a copy of the GNU General Public License | ||
144 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
145 | # | ||
146 | -# | ||
147 | -# setup and check for config parameters, and in particular | ||
148 | -# | ||
149 | -# EMAIL - email of the script runner. | ||
150 | -# TEST_DIR - scratch test directory | ||
151 | -# | ||
152 | -# - These can be added to $HOST_CONFIG_DIR (witch default to ./config) | ||
153 | -# below or a separate local configuration file can be used (using | ||
154 | -# the HOST_OPTIONS variable). | ||
155 | -# - This script is shared by the stress test system and the auto-qa | ||
156 | -# system (includes both regression test and benchmark components). | ||
157 | -# - this script shouldn't make any assertions about filesystem | ||
158 | -# validity or mountedness. | ||
159 | -# | ||
160 | - | ||
161 | # all tests should use a common language setting to prevent golden | ||
162 | # output mismatches. | ||
163 | export LANG=C | ||
164 | |||
165 | PATH=".:$PATH" | ||
166 | |||
167 | -HOST=`hostname -s 2> /dev/null` | ||
168 | HOSTOS=`uname -s` | ||
169 | |||
170 | -EMAIL=root@localhost # where auto-qa will send its status messages | ||
171 | -export HOST_OPTIONS=${HOST_OPTIONS:=local.config} | ||
172 | -export CHECK_OPTIONS=${CHECK_OPTIONS:="-g auto"} | ||
173 | export PWD=`pwd` | ||
174 | |||
175 | export _QEMU_HANDLE=0 | ||
176 | @@ -XXX,XX +XXX,XX @@ _fatal() | ||
177 | export AWK_PROG="`set_prog_path awk`" | ||
178 | [ "$AWK_PROG" = "" ] && _fatal "awk not found" | ||
179 | |||
180 | -export SED_PROG="`set_prog_path sed`" | ||
181 | -[ "$SED_PROG" = "" ] && _fatal "sed not found" | ||
182 | - | ||
183 | -export PS_ALL_FLAGS="-ef" | ||
184 | - | ||
185 | if [ -z "$QEMU_PROG" ]; then | ||
186 | export QEMU_PROG="`set_prog_path qemu`" | ||
187 | fi | ||
188 | @@ -XXX,XX +XXX,XX @@ fi | ||
189 | |||
190 | export QEMU_DEFAULT_MACHINE="$default_machine" | ||
191 | |||
192 | -[ -f /etc/qemu-iotest.config ] && . /etc/qemu-iotest.config | ||
193 | - | ||
194 | if [ -z "$TEST_DIR" ]; then | ||
195 | TEST_DIR=`pwd`/scratch | ||
196 | fi | ||
197 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/tests/qemu-iotests/common.rc | ||
200 | +++ b/tests/qemu-iotests/common.rc | ||
201 | @@ -XXX,XX +XXX,XX @@ _img_info() | ||
202 | done | ||
203 | } | 35 | } |
204 | 36 | ||
205 | -_get_pids_by_name() | 37 | -static void block_job_drained_end(void *opaque) |
206 | -{ | 38 | +static void child_job_drained_end(BdrvChild *c) |
207 | - if [ $# -ne 1 ] | 39 | { |
208 | - then | 40 | - BlockJob *job = opaque; |
209 | - echo "Usage: _get_pids_by_name process-name" 1>&2 | 41 | + BlockJob *job = c->opaque; |
210 | - exit 1 | 42 | block_job_resume(job); |
211 | - fi | ||
212 | - | ||
213 | - # Algorithm ... all ps(1) variants have a time of the form MM:SS or | ||
214 | - # HH:MM:SS before the psargs field, use this as the search anchor. | ||
215 | - # | ||
216 | - # Matches with $1 (process-name) occur if the first psarg is $1 | ||
217 | - # or ends in /$1 ... the matching uses sed's regular expressions, | ||
218 | - # so passing a regex into $1 will work. | ||
219 | - | ||
220 | - ps $PS_ALL_FLAGS \ | ||
221 | - | sed -n \ | ||
222 | - -e 's/$/ /' \ | ||
223 | - -e 's/[ ][ ]*/ /g' \ | ||
224 | - -e 's/^ //' \ | ||
225 | - -e 's/^[^ ]* //' \ | ||
226 | - -e "/[0-9]:[0-9][0-9] *[^ ]*\/$1 /s/ .*//p" \ | ||
227 | - -e "/[0-9]:[0-9][0-9] *$1 /s/ .*//p" | ||
228 | -} | ||
229 | - | ||
230 | -# fqdn for localhost | ||
231 | -# | ||
232 | -_get_fqdn() | ||
233 | -{ | ||
234 | - host=`hostname` | ||
235 | - $NSLOOKUP_PROG $host | $AWK_PROG '{ if ($1 == "Name:") print $2 }' | ||
236 | -} | ||
237 | - | ||
238 | -# check if run as root | ||
239 | -# | ||
240 | -_need_to_be_root() | ||
241 | -{ | ||
242 | - id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'` | ||
243 | - if [ "$id" -ne 0 ] | ||
244 | - then | ||
245 | - echo "Arrgh ... you need to be root (not uid=$id) to run this test" | ||
246 | - exit 1 | ||
247 | - fi | ||
248 | -} | ||
249 | - | ||
250 | # bail out, setting up .notrun file | ||
251 | # | ||
252 | _notrun() | ||
253 | @@ -XXX,XX +XXX,XX @@ _full_platform_details() | ||
254 | echo "$os/$platform $host $kernel" | ||
255 | } | 43 | } |
256 | 44 | ||
257 | -_link_out_file() | 45 | -static const BlockDevOps block_job_dev_ops = { |
258 | -{ | 46 | - .drained_begin = block_job_drained_begin, |
259 | - if [ -z "$1" ]; then | 47 | - .drained_end = block_job_drained_end, |
260 | - echo Error must pass \$seq. | 48 | +static const BdrvChildRole child_job = { |
261 | - exit | 49 | + .get_parent_desc = child_job_get_parent_desc, |
262 | - fi | 50 | + .drained_begin = child_job_drained_begin, |
263 | - rm -f $1 | 51 | + .drained_end = child_job_drained_end, |
264 | - if [ "`uname`" == "IRIX64" ] || [ "`uname`" == "IRIX" ]; then | 52 | + .stay_at_node = true, |
265 | - ln -s $1.irix $1 | 53 | }; |
266 | - elif [ "`uname`" == "Linux" ]; then | 54 | |
267 | - ln -s $1.linux $1 | 55 | void block_job_remove_all_bdrv(BlockJob *job) |
268 | - else | 56 | @@ -XXX,XX +XXX,XX @@ void *block_job_create(const char *job_id, const BlockJobDriver *driver, |
269 | - echo Error test $seq does not run on the operating system: `uname` | 57 | block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort); |
270 | - exit | 58 | bs->job = job; |
271 | - fi | 59 | |
272 | -} | 60 | - blk_set_dev_ops(blk, &block_job_dev_ops, job); |
273 | - | 61 | bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); |
274 | -_die() | 62 | |
275 | -{ | 63 | QLIST_INSERT_HEAD(&block_jobs, job, job_list); |
276 | - echo $@ | ||
277 | - exit 1 | ||
278 | -} | ||
279 | - | ||
280 | # make sure this script returns success | ||
281 | true | ||
282 | -- | 64 | -- |
283 | 2.13.6 | 65 | 2.13.6 |
284 | 66 | ||
285 | 67 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | Block jobs must be paused if any of the involved nodes are drained. |
---|---|---|---|
2 | 2 | ||
3 | These are never used by "check", with one exception that does not need | ||
4 | $QEMU_OPTIONS. Keep them in common.rc, which will be soon included only | ||
5 | by the tests. | ||
6 | |||
7 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | --- | 4 | --- |
11 | tests/qemu-iotests/039.out | 10 +++--- | 5 | tests/test-bdrv-drain.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ |
12 | tests/qemu-iotests/061.out | 4 +-- | 6 | 1 file changed, 121 insertions(+) |
13 | tests/qemu-iotests/137.out | 2 +- | ||
14 | tests/qemu-iotests/common.config | 69 ++-------------------------------------- | ||
15 | tests/qemu-iotests/common.rc | 65 +++++++++++++++++++++++++++++++++++++ | ||
16 | 5 files changed, 75 insertions(+), 75 deletions(-) | ||
17 | 7 | ||
18 | diff --git a/tests/qemu-iotests/039.out b/tests/qemu-iotests/039.out | 8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
19 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/qemu-iotests/039.out | 10 | --- a/tests/test-bdrv-drain.c |
21 | +++ b/tests/qemu-iotests/039.out | 11 | +++ b/tests/test-bdrv-drain.c |
22 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | 12 | @@ -XXX,XX +XXX,XX @@ |
23 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 | 13 | |
24 | wrote 512/512 bytes at offset 0 | 14 | #include "qemu/osdep.h" |
25 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | 15 | #include "block/block.h" |
26 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | 16 | +#include "block/blockjob_int.h" |
27 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | 17 | #include "sysemu/block-backend.h" |
28 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | 18 | #include "qapi/error.h" |
29 | else | 19 | |
30 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | 20 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void) |
31 | @@ -XXX,XX +XXX,XX @@ read 512/512 bytes at offset 0 | 21 | test_quiesce_common(BDRV_DRAIN, false); |
32 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 | ||
33 | wrote 512/512 bytes at offset 0 | ||
34 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
35 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
36 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
37 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
38 | else | ||
39 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
40 | @@ -XXX,XX +XXX,XX @@ incompatible_features 0x0 | ||
41 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 | ||
42 | wrote 512/512 bytes at offset 0 | ||
43 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
44 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
45 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
46 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
47 | else | ||
48 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
49 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
50 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 | ||
51 | wrote 512/512 bytes at offset 0 | ||
52 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
53 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
54 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
55 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
56 | else | ||
57 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
58 | @@ -XXX,XX +XXX,XX @@ Data may be corrupted, or further writes to the image may corrupt it. | ||
59 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 | ||
60 | wrote 512/512 bytes at offset 0 | ||
61 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
62 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
63 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
64 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
65 | else | ||
66 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
67 | diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/tests/qemu-iotests/061.out | ||
70 | +++ b/tests/qemu-iotests/061.out | ||
71 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
72 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
73 | wrote 131072/131072 bytes at offset 0 | ||
74 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
75 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
76 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
77 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
78 | else | ||
79 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
80 | @@ -XXX,XX +XXX,XX @@ No errors were found on the image. | ||
81 | Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
82 | wrote 131072/131072 bytes at offset 0 | ||
83 | 128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
84 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
85 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
86 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
87 | else | ||
88 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
89 | diff --git a/tests/qemu-iotests/137.out b/tests/qemu-iotests/137.out | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/tests/qemu-iotests/137.out | ||
92 | +++ b/tests/qemu-iotests/137.out | ||
93 | @@ -XXX,XX +XXX,XX @@ Cache clean interval too big | ||
94 | Unsupported value 'blubb' for qcow2 option 'overlap-check'. Allowed are any of the following: none, constant, cached, all | ||
95 | wrote 512/512 bytes at offset 0 | ||
96 | 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
97 | -./common.config: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
98 | +./common.rc: Killed ( if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
99 | exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
100 | else | ||
101 | exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@"; | ||
102 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/tests/qemu-iotests/common.config | ||
105 | +++ b/tests/qemu-iotests/common.config | ||
106 | @@ -XXX,XX +XXX,XX @@ _optstr_add() | ||
107 | fi | ||
108 | } | 22 | } |
109 | 23 | ||
110 | -_qemu_wrapper() | 24 | + |
111 | -{ | 25 | +typedef struct TestBlockJob { |
112 | - ( | 26 | + BlockJob common; |
113 | - if [ -n "${QEMU_NEED_PID}" ]; then | 27 | + bool should_complete; |
114 | - echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" | 28 | +} TestBlockJob; |
115 | - fi | 29 | + |
116 | - exec "$QEMU_PROG" $QEMU_OPTIONS "$@" | 30 | +static void test_job_completed(BlockJob *job, void *opaque) |
117 | - ) | ||
118 | -} | ||
119 | - | ||
120 | -_qemu_img_wrapper() | ||
121 | -{ | ||
122 | - (exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@") | ||
123 | -} | ||
124 | - | ||
125 | -_qemu_io_wrapper() | ||
126 | -{ | ||
127 | - local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind | ||
128 | - local QEMU_IO_ARGS="$QEMU_IO_OPTIONS" | ||
129 | - if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
130 | - QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS" | ||
131 | - if [ -n "$IMGKEYSECRET" ]; then | ||
132 | - QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS" | ||
133 | - fi | ||
134 | - fi | ||
135 | - local RETVAL | ||
136 | - ( | ||
137 | - if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
138 | - exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" | ||
139 | - else | ||
140 | - exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" | ||
141 | - fi | ||
142 | - ) | ||
143 | - RETVAL=$? | ||
144 | - if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
145 | - if [ $RETVAL == 99 ]; then | ||
146 | - cat "${VALGRIND_LOGFILE}" | ||
147 | - fi | ||
148 | - rm -f "${VALGRIND_LOGFILE}" | ||
149 | - fi | ||
150 | - (exit $RETVAL) | ||
151 | -} | ||
152 | - | ||
153 | -_qemu_nbd_wrapper() | ||
154 | -{ | ||
155 | - ( | ||
156 | - echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid" | ||
157 | - exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@" | ||
158 | - ) | ||
159 | -} | ||
160 | - | ||
161 | -_qemu_vxhs_wrapper() | ||
162 | -{ | ||
163 | - ( | ||
164 | - echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" | ||
165 | - exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" | ||
166 | - ) | ||
167 | -} | ||
168 | - | ||
169 | -export QEMU=_qemu_wrapper | ||
170 | -export QEMU_IMG=_qemu_img_wrapper | ||
171 | -export QEMU_IO=_qemu_io_wrapper | ||
172 | -export QEMU_NBD=_qemu_nbd_wrapper | ||
173 | -export QEMU_VXHS=_qemu_vxhs_wrapper | ||
174 | - | ||
175 | QEMU_IMG_EXTRA_ARGS= | ||
176 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
177 | QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS" | ||
178 | @@ -XXX,XX +XXX,XX @@ fi | ||
179 | export QEMU_IMG_EXTRA_ARGS | ||
180 | |||
181 | |||
182 | -default_machine=$($QEMU -machine help | sed -n '/(default)/ s/ .*//p') | ||
183 | -default_alias_machine=$($QEMU -machine help | \ | ||
184 | +default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p') | ||
185 | +default_alias_machine=$($QEMU_PROG -machine help | \ | ||
186 | sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | ||
187 | if [[ "$default_alias_machine" ]]; then | ||
188 | default_machine="$default_alias_machine" | ||
189 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/tests/qemu-iotests/common.rc | ||
192 | +++ b/tests/qemu-iotests/common.rc | ||
193 | @@ -XXX,XX +XXX,XX @@ then | ||
194 | fi | ||
195 | fi | ||
196 | |||
197 | +_qemu_wrapper() | ||
198 | +{ | 31 | +{ |
199 | + ( | 32 | + block_job_completed(job, 0); |
200 | + if [ -n "${QEMU_NEED_PID}" ]; then | ||
201 | + echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" | ||
202 | + fi | ||
203 | + exec "$QEMU_PROG" $QEMU_OPTIONS "$@" | ||
204 | + ) | ||
205 | +} | 33 | +} |
206 | + | 34 | + |
207 | +_qemu_img_wrapper() | 35 | +static void coroutine_fn test_job_start(void *opaque) |
208 | +{ | 36 | +{ |
209 | + (exec "$QEMU_IMG_PROG" $QEMU_IMG_OPTIONS "$@") | 37 | + TestBlockJob *s = opaque; |
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); | ||
210 | +} | 44 | +} |
211 | + | 45 | + |
212 | +_qemu_io_wrapper() | 46 | +static void test_job_complete(BlockJob *job, Error **errp) |
213 | +{ | 47 | +{ |
214 | + local VALGRIND_LOGFILE="${TEST_DIR}"/$$.valgrind | 48 | + TestBlockJob *s = container_of(job, TestBlockJob, common); |
215 | + local QEMU_IO_ARGS="$QEMU_IO_OPTIONS" | 49 | + s->should_complete = true; |
216 | + if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
217 | + QEMU_IO_ARGS="--image-opts $QEMU_IO_ARGS" | ||
218 | + if [ -n "$IMGKEYSECRET" ]; then | ||
219 | + QEMU_IO_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IO_ARGS" | ||
220 | + fi | ||
221 | + fi | ||
222 | + local RETVAL | ||
223 | + ( | ||
224 | + if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
225 | + exec valgrind --log-file="${VALGRIND_LOGFILE}" --error-exitcode=99 "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" | ||
226 | + else | ||
227 | + exec "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" | ||
228 | + fi | ||
229 | + ) | ||
230 | + RETVAL=$? | ||
231 | + if [ "${VALGRIND_QEMU}" == "y" ]; then | ||
232 | + if [ $RETVAL == 99 ]; then | ||
233 | + cat "${VALGRIND_LOGFILE}" | ||
234 | + fi | ||
235 | + rm -f "${VALGRIND_LOGFILE}" | ||
236 | + fi | ||
237 | + (exit $RETVAL) | ||
238 | +} | 50 | +} |
239 | + | 51 | + |
240 | +_qemu_nbd_wrapper() | 52 | +BlockJobDriver test_job_driver = { |
53 | + .instance_size = sizeof(TestBlockJob), | ||
54 | + .start = test_job_start, | ||
55 | + .complete = test_job_complete, | ||
56 | +}; | ||
57 | + | ||
58 | +static void test_blockjob_common(enum drain_type drain_type) | ||
241 | +{ | 59 | +{ |
242 | + ( | 60 | + BlockBackend *blk_src, *blk_target; |
243 | + echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid" | 61 | + BlockDriverState *src, *target; |
244 | + exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@" | 62 | + BlockJob *job; |
245 | + ) | 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); | ||
92 | + } | ||
93 | + /* XXX We don't wait until the job is actually paused. Is this okay? */ | ||
94 | + /* g_assert_true(job->paused); */ | ||
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); | ||
111 | + } | ||
112 | + /* XXX We don't wait until the job is actually paused. Is this okay? */ | ||
113 | + /* g_assert_true(job->paused); */ | ||
114 | + g_assert_false(job->busy); /* The job is paused */ | ||
115 | + | ||
116 | + do_drain_end(drain_type, target); | ||
117 | + | ||
118 | + g_assert_cmpint(job->pause_count, ==, 0); | ||
119 | + g_assert_false(job->paused); | ||
120 | + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ | ||
121 | + | ||
122 | + ret = block_job_complete_sync(job, &error_abort); | ||
123 | + g_assert_cmpint(ret, ==, 0); | ||
124 | + | ||
125 | + blk_unref(blk_src); | ||
126 | + blk_unref(blk_target); | ||
127 | + bdrv_unref(src); | ||
128 | + bdrv_unref(target); | ||
246 | +} | 129 | +} |
247 | + | 130 | + |
248 | +_qemu_vxhs_wrapper() | 131 | +static void test_blockjob_drain_all(void) |
249 | +{ | 132 | +{ |
250 | + ( | 133 | + test_blockjob_common(BDRV_DRAIN_ALL); |
251 | + echo $BASHPID > "${TEST_DIR}/qemu-vxhs.pid" | ||
252 | + exec "$QEMU_VXHS_PROG" $QEMU_VXHS_OPTIONS "$@" | ||
253 | + ) | ||
254 | +} | 134 | +} |
255 | + | 135 | + |
256 | +export QEMU=_qemu_wrapper | 136 | +static void test_blockjob_drain(void) |
257 | +export QEMU_IMG=_qemu_img_wrapper | 137 | +{ |
258 | +export QEMU_IO=_qemu_io_wrapper | 138 | + test_blockjob_common(BDRV_DRAIN); |
259 | +export QEMU_NBD=_qemu_nbd_wrapper | 139 | +} |
260 | +export QEMU_VXHS=_qemu_vxhs_wrapper | ||
261 | + | 140 | + |
262 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | 141 | int main(int argc, char **argv) |
263 | DRIVER="driver=$IMGFMT" | 142 | { |
264 | if [ "$IMGFMT" = "luks" ]; then | 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); | ||
150 | + | ||
151 | return g_test_run(); | ||
152 | } | ||
265 | -- | 153 | -- |
266 | 2.13.6 | 154 | 2.13.6 |
267 | 155 | ||
268 | 156 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | Block jobs are already paused using the BdrvChildRole drain callbacks, |
---|---|---|---|
2 | so we don't need an additional block_job_pause_all() call. | ||
2 | 3 | ||
3 | Split "check" parts from tests part. | ||
4 | |||
5 | For the directory setup, the actual computation of directories goes | ||
6 | in "check", while the sanity checks go in the tests. | ||
7 | |||
8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 4 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | --- | 5 | --- |
12 | tests/qemu-iotests/common | 24 ++++++++++++++++++++ | 6 | block/io.c | 4 ---- |
13 | tests/qemu-iotests/common.config | 49 ---------------------------------------- | 7 | tests/test-bdrv-drain.c | 10 ++++------ |
14 | tests/qemu-iotests/common.qemu | 1 + | 8 | 2 files changed, 4 insertions(+), 10 deletions(-) |
15 | tests/qemu-iotests/common.rc | 25 ++++++++++++++++++++ | ||
16 | 4 files changed, 50 insertions(+), 49 deletions(-) | ||
17 | 9 | ||
18 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | 10 | diff --git a/block/io.c b/block/io.c |
19 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/qemu-iotests/common | 12 | --- a/block/io.c |
21 | +++ b/tests/qemu-iotests/common | 13 | +++ b/block/io.c |
22 | @@ -XXX,XX +XXX,XX @@ set_prog_path() | 14 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
23 | fi | 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(); | ||
24 | } | 29 | } |
25 | 30 | ||
26 | +if [ -z "$TEST_DIR" ]; then | 31 | void bdrv_drain_all(void) |
27 | + TEST_DIR=`pwd`/scratch | 32 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
28 | +fi | ||
29 | + | ||
30 | +if [ ! -e "$TEST_DIR" ]; then | ||
31 | + mkdir "$TEST_DIR" | ||
32 | +fi | ||
33 | + | ||
34 | diff="diff -u" | ||
35 | verbose=false | ||
36 | debug=false | ||
37 | @@ -XXX,XX +XXX,XX @@ if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null | ||
38 | IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10") | ||
39 | fi | ||
40 | |||
41 | +if [ -z "$SAMPLE_IMG_DIR" ]; then | ||
42 | + SAMPLE_IMG_DIR="$source_iotests/sample_images" | ||
43 | +fi | ||
44 | + | ||
45 | +export TEST_DIR | ||
46 | +export SAMPLE_IMG_DIR | ||
47 | + | ||
48 | if [ -s $tmp.list ] | ||
49 | then | ||
50 | # found some valid test numbers ... this is good | ||
51 | @@ -XXX,XX +XXX,XX @@ if [ -x "$build_iotests/socket_scm_helper" ] | ||
52 | then | ||
53 | export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | ||
54 | fi | ||
55 | + | ||
56 | +default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p') | ||
57 | +default_alias_machine=$($QEMU_PROG -machine help | \ | ||
58 | + sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | ||
59 | +if [[ "$default_alias_machine" ]]; then | ||
60 | + default_machine="$default_alias_machine" | ||
61 | +fi | ||
62 | + | ||
63 | +export QEMU_DEFAULT_MACHINE="$default_machine" | ||
64 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
65 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
66 | --- a/tests/qemu-iotests/common.config | 34 | --- a/tests/test-bdrv-drain.c |
67 | +++ b/tests/qemu-iotests/common.config | 35 | +++ b/tests/test-bdrv-drain.c |
68 | @@ -XXX,XX +XXX,XX @@ arch=`uname -m` | 36 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type) |
69 | 37 | do_drain_begin(drain_type, src); | |
70 | export PWD=`pwd` | 38 | |
71 | 39 | if (drain_type == BDRV_DRAIN_ALL) { | |
72 | -export _QEMU_HANDLE=0 | 40 | - /* bdrv_drain_all() drains both src and target, and involves an |
73 | - | 41 | - * additional block_job_pause_all() */ |
74 | # make sure we have a standard umask | 42 | - g_assert_cmpint(job->pause_count, ==, 3); |
75 | umask 022 | 43 | + /* bdrv_drain_all() drains both src and target */ |
76 | 44 | + g_assert_cmpint(job->pause_count, ==, 2); | |
77 | @@ -XXX,XX +XXX,XX @@ _optstr_add() | 45 | } else { |
78 | fi | 46 | g_assert_cmpint(job->pause_count, ==, 1); |
79 | } | 47 | } |
80 | 48 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_common(enum drain_type drain_type) | |
81 | -QEMU_IMG_EXTRA_ARGS= | 49 | do_drain_begin(drain_type, target); |
82 | -if [ "$IMGOPTSSYNTAX" = "true" ]; then | 50 | |
83 | - QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS" | 51 | if (drain_type == BDRV_DRAIN_ALL) { |
84 | - if [ -n "$IMGKEYSECRET" ]; then | 52 | - /* bdrv_drain_all() drains both src and target, and involves an |
85 | - QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS" | 53 | - * additional block_job_pause_all() */ |
86 | - fi | 54 | - g_assert_cmpint(job->pause_count, ==, 3); |
87 | -fi | 55 | + /* bdrv_drain_all() drains both src and target */ |
88 | -export QEMU_IMG_EXTRA_ARGS | 56 | + g_assert_cmpint(job->pause_count, ==, 2); |
89 | - | 57 | } else { |
90 | - | 58 | g_assert_cmpint(job->pause_count, ==, 1); |
91 | -default_machine=$($QEMU_PROG -machine help | sed -n '/(default)/ s/ .*//p') | 59 | } |
92 | -default_alias_machine=$($QEMU_PROG -machine help | \ | ||
93 | - sed -n "/(alias of $default_machine)/ { s/ .*//p; q; }") | ||
94 | -if [[ "$default_alias_machine" ]]; then | ||
95 | - default_machine="$default_alias_machine" | ||
96 | -fi | ||
97 | - | ||
98 | -export QEMU_DEFAULT_MACHINE="$default_machine" | ||
99 | - | ||
100 | -if [ -z "$TEST_DIR" ]; then | ||
101 | - TEST_DIR=`pwd`/scratch | ||
102 | -fi | ||
103 | - | ||
104 | -QEMU_TEST_DIR="${TEST_DIR}" | ||
105 | - | ||
106 | -if [ ! -e "$TEST_DIR" ]; then | ||
107 | - mkdir "$TEST_DIR" | ||
108 | -fi | ||
109 | - | ||
110 | -if [ ! -d "$TEST_DIR" ]; then | ||
111 | - echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory" | ||
112 | - exit 1 | ||
113 | -fi | ||
114 | - | ||
115 | -export TEST_DIR | ||
116 | - | ||
117 | -if [ -z "$SAMPLE_IMG_DIR" ]; then | ||
118 | - SAMPLE_IMG_DIR="$source_iotests/sample_images" | ||
119 | -fi | ||
120 | - | ||
121 | -if [ ! -d "$SAMPLE_IMG_DIR" ]; then | ||
122 | - echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory" | ||
123 | - exit 1 | ||
124 | -fi | ||
125 | - | ||
126 | -export SAMPLE_IMG_DIR | ||
127 | - | ||
128 | # make sure this script returns success | ||
129 | true | ||
130 | diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/tests/qemu-iotests/common.qemu | ||
133 | +++ b/tests/qemu-iotests/common.qemu | ||
134 | @@ -XXX,XX +XXX,XX @@ QEMU_FIFO_IN="${QEMU_TEST_DIR}/qmp-in-$$" | ||
135 | QEMU_FIFO_OUT="${QEMU_TEST_DIR}/qmp-out-$$" | ||
136 | |||
137 | QEMU_HANDLE=0 | ||
138 | +export _QEMU_HANDLE=0 | ||
139 | |||
140 | # If bash version is >= 4.1, these will be overwritten and dynamic | ||
141 | # file descriptor values assigned. | ||
142 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
143 | index XXXXXXX..XXXXXXX 100644 | ||
144 | --- a/tests/qemu-iotests/common.rc | ||
145 | +++ b/tests/qemu-iotests/common.rc | ||
146 | @@ -XXX,XX +XXX,XX @@ export QEMU_VXHS=_qemu_vxhs_wrapper | ||
147 | |||
148 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
149 | DRIVER="driver=$IMGFMT" | ||
150 | + QEMU_IMG_EXTRA_ARGS="--image-opts $QEMU_IMG_EXTRA_ARGS" | ||
151 | + if [ -n "$IMGKEYSECRET" ]; then | ||
152 | + QEMU_IMG_EXTRA_ARGS="--object secret,id=keysec0,data=$IMGKEYSECRET $QEMU_IMG_EXTRA_ARGS" | ||
153 | + fi | ||
154 | if [ "$IMGFMT" = "luks" ]; then | ||
155 | DRIVER="$DRIVER,key-secret=keysec0" | ||
156 | fi | ||
157 | @@ -XXX,XX +XXX,XX @@ if [ "$IMGOPTSSYNTAX" = "true" ]; then | ||
158 | TEST_IMG="$DRIVER,file.driver=$IMGPROTO,file.filename=$TEST_DIR/t.$IMGFMT" | ||
159 | fi | ||
160 | else | ||
161 | + QEMU_IMG_EXTRA_ARGS= | ||
162 | if [ "$IMGPROTO" = "file" ]; then | ||
163 | TEST_IMG=$TEST_DIR/t.$IMGFMT | ||
164 | elif [ "$IMGPROTO" = "nbd" ]; then | ||
165 | @@ -XXX,XX +XXX,XX @@ else | ||
166 | fi | ||
167 | ORIG_TEST_IMG="$TEST_IMG" | ||
168 | |||
169 | +if [ -z "$TEST_DIR" ]; then | ||
170 | + TEST_DIR=`pwd`/scratch | ||
171 | +fi | ||
172 | + | ||
173 | +QEMU_TEST_DIR="${TEST_DIR}" | ||
174 | + | ||
175 | +if [ ! -e "$TEST_DIR" ]; then | ||
176 | + mkdir "$TEST_DIR" | ||
177 | +fi | ||
178 | + | ||
179 | +if [ ! -d "$TEST_DIR" ]; then | ||
180 | + echo "common.config: Error: \$TEST_DIR ($TEST_DIR) is not a directory" | ||
181 | + exit 1 | ||
182 | +fi | ||
183 | + | ||
184 | +if [ ! -d "$SAMPLE_IMG_DIR" ]; then | ||
185 | + echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory" | ||
186 | + exit 1 | ||
187 | +fi | ||
188 | + | ||
189 | _use_sample_img() | ||
190 | { | ||
191 | SAMPLE_IMG_FILE="${1%\.bz2}" | ||
192 | -- | 60 | -- |
193 | 2.13.6 | 61 | 2.13.6 |
194 | 62 | ||
195 | 63 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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. | ||
2 | 6 | ||
3 | Improve our braindead copy-on-read implementation. Pre-patch, | ||
4 | we have multiple issues: | ||
5 | - we create a bounce buffer and perform a write for the entire | ||
6 | request, even if the active image already has 99% of the | ||
7 | clusters occupied, and really only needs to copy-on-read the | ||
8 | remaining 1% of the clusters | ||
9 | - our bounce buffer was as large as the read request, and can | ||
10 | needlessly exhaust our memory by using double the memory of | ||
11 | the request size (the original request plus our bounce buffer), | ||
12 | rather than a capped maximum overhead beyond the original | ||
13 | - if a driver has a max_transfer limit, we are bypassing the | ||
14 | normal code in bdrv_aligned_preadv() that fragments to that | ||
15 | limit, and instead attempt to read the entire buffer from the | ||
16 | driver in one go, which some drivers may assert on | ||
17 | - a client can request a large request of nearly 2G such that | ||
18 | rounding the request out to cluster boundaries results in a | ||
19 | byte count larger than 2G. While this cannot exceed 32 bits, | ||
20 | it DOES have some follow-on problems: | ||
21 | -- the call to bdrv_driver_pread() can assert for exceeding | ||
22 | BDRV_REQUEST_MAX_BYTES, if the driver is old and lacks | ||
23 | .bdrv_co_preadv | ||
24 | -- if the buffer is all zeroes, the subsequent call to | ||
25 | bdrv_co_do_pwrite_zeroes is a no-op due to a negative size, | ||
26 | which means we did not actually copy on read | ||
27 | |||
28 | Fix all of these issues by breaking up the action into a loop, | ||
29 | where each iteration is capped to sane limits. Also, querying | ||
30 | the allocation status allows us to optimize: when data is | ||
31 | already present in the active layer, we don't need to bounce. | ||
32 | |||
33 | Note that the code has a telling comment that copy-on-read | ||
34 | should probably be a filter driver rather than a bolt-on hack | ||
35 | in io.c; but that remains a task for another day. | ||
36 | |||
37 | CC: qemu-stable@nongnu.org | ||
38 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
39 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
40 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
41 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
42 | --- | 8 | --- |
43 | block/io.c | 120 +++++++++++++++++++++++++++++++++++++++++-------------------- | 9 | block/io.c | 12 +++++++----- |
44 | 1 file changed, 82 insertions(+), 38 deletions(-) | 10 | 1 file changed, 7 insertions(+), 5 deletions(-) |
45 | 11 | ||
46 | diff --git a/block/io.c b/block/io.c | 12 | diff --git a/block/io.c b/block/io.c |
47 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/block/io.c | 14 | --- a/block/io.c |
49 | +++ b/block/io.c | 15 | +++ b/block/io.c |
50 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs) |
51 | 17 | ||
52 | #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */ | 18 | void bdrv_drained_end(BlockDriverState *bs) |
53 | 19 | { | |
54 | +/* Maximum bounce buffer for copy-on-read and write zeroes, in bytes */ | 20 | + int old_quiesce_counter; |
55 | +#define MAX_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS) | ||
56 | + | 21 | + |
57 | static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, | 22 | if (qemu_in_coroutine()) { |
58 | int64_t offset, int bytes, BdrvRequestFlags flags); | 23 | bdrv_co_yield_to_drain(bs, false); |
59 | 24 | return; | |
60 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, | ||
61 | |||
62 | BlockDriver *drv = bs->drv; | ||
63 | struct iovec iov; | ||
64 | - QEMUIOVector bounce_qiov; | ||
65 | + QEMUIOVector local_qiov; | ||
66 | int64_t cluster_offset; | ||
67 | unsigned int cluster_bytes; | ||
68 | size_t skip_bytes; | ||
69 | int ret; | ||
70 | + int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, | ||
71 | + BDRV_REQUEST_MAX_BYTES); | ||
72 | + unsigned int progress = 0; | ||
73 | |||
74 | /* FIXME We cannot require callers to have write permissions when all they | ||
75 | * are doing is a read request. If we did things right, write permissions | ||
76 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, | ||
77 | // assert(child->perm & (BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE)); | ||
78 | |||
79 | /* Cover entire cluster so no additional backing file I/O is required when | ||
80 | - * allocating cluster in the image file. | ||
81 | + * allocating cluster in the image file. Note that this value may exceed | ||
82 | + * BDRV_REQUEST_MAX_BYTES (even when the original read did not), which | ||
83 | + * is one reason we loop rather than doing it all at once. | ||
84 | */ | ||
85 | bdrv_round_to_clusters(bs, offset, bytes, &cluster_offset, &cluster_bytes); | ||
86 | + skip_bytes = offset - cluster_offset; | ||
87 | |||
88 | trace_bdrv_co_do_copy_on_readv(bs, offset, bytes, | ||
89 | cluster_offset, cluster_bytes); | ||
90 | |||
91 | - iov.iov_len = cluster_bytes; | ||
92 | - iov.iov_base = bounce_buffer = qemu_try_blockalign(bs, iov.iov_len); | ||
93 | + bounce_buffer = qemu_try_blockalign(bs, | ||
94 | + MIN(MIN(max_transfer, cluster_bytes), | ||
95 | + MAX_BOUNCE_BUFFER)); | ||
96 | if (bounce_buffer == NULL) { | ||
97 | ret = -ENOMEM; | ||
98 | goto err; | ||
99 | } | 25 | } |
100 | 26 | assert(bs->quiesce_counter > 0); | |
101 | - qemu_iovec_init_external(&bounce_qiov, &iov, 1); | 27 | - if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { |
102 | + while (cluster_bytes) { | 28 | - return; |
103 | + int64_t pnum; | ||
104 | |||
105 | - ret = bdrv_driver_preadv(bs, cluster_offset, cluster_bytes, | ||
106 | - &bounce_qiov, 0); | ||
107 | - if (ret < 0) { | ||
108 | - goto err; | ||
109 | - } | 29 | - } |
110 | + ret = bdrv_is_allocated(bs, cluster_offset, | 30 | + old_quiesce_counter = atomic_fetch_dec(&bs->quiesce_counter); |
111 | + MIN(cluster_bytes, max_transfer), &pnum); | 31 | |
112 | + if (ret < 0) { | 32 | /* Re-enable things in child-to-parent order */ |
113 | + /* Safe to treat errors in querying allocation as if | 33 | bdrv_drain_invoke(bs, false, false); |
114 | + * unallocated; we'll probably fail again soon on the | 34 | - bdrv_parent_drained_end(bs); |
115 | + * read, but at least that will set a decent errno. | 35 | - aio_enable_external(bdrv_get_aio_context(bs)); |
116 | + */ | 36 | + if (old_quiesce_counter == 1) { |
117 | + pnum = MIN(cluster_bytes, max_transfer); | 37 | + bdrv_parent_drained_end(bs); |
118 | + } | 38 | + aio_enable_external(bdrv_get_aio_context(bs)); |
119 | |||
120 | - bdrv_debug_event(bs, BLKDBG_COR_WRITE); | ||
121 | - if (drv->bdrv_co_pwrite_zeroes && | ||
122 | - buffer_is_zero(bounce_buffer, iov.iov_len)) { | ||
123 | - /* FIXME: Should we (perhaps conditionally) be setting | ||
124 | - * BDRV_REQ_MAY_UNMAP, if it will allow for a sparser copy | ||
125 | - * that still correctly reads as zero? */ | ||
126 | - ret = bdrv_co_do_pwrite_zeroes(bs, cluster_offset, cluster_bytes, 0); | ||
127 | - } else { | ||
128 | - /* This does not change the data on the disk, it is not necessary | ||
129 | - * to flush even in cache=writethrough mode. | ||
130 | - */ | ||
131 | - ret = bdrv_driver_pwritev(bs, cluster_offset, cluster_bytes, | ||
132 | - &bounce_qiov, 0); | ||
133 | - } | ||
134 | + assert(skip_bytes < pnum); | ||
135 | |||
136 | - if (ret < 0) { | ||
137 | - /* It might be okay to ignore write errors for guest requests. If this | ||
138 | - * is a deliberate copy-on-read then we don't want to ignore the error. | ||
139 | - * Simply report it in all cases. | ||
140 | - */ | ||
141 | - goto err; | ||
142 | - } | ||
143 | + if (ret <= 0) { | ||
144 | + /* Must copy-on-read; use the bounce buffer */ | ||
145 | + iov.iov_base = bounce_buffer; | ||
146 | + iov.iov_len = pnum = MIN(pnum, MAX_BOUNCE_BUFFER); | ||
147 | + qemu_iovec_init_external(&local_qiov, &iov, 1); | ||
148 | |||
149 | - skip_bytes = offset - cluster_offset; | ||
150 | - qemu_iovec_from_buf(qiov, 0, bounce_buffer + skip_bytes, bytes); | ||
151 | + ret = bdrv_driver_preadv(bs, cluster_offset, pnum, | ||
152 | + &local_qiov, 0); | ||
153 | + if (ret < 0) { | ||
154 | + goto err; | ||
155 | + } | ||
156 | + | ||
157 | + bdrv_debug_event(bs, BLKDBG_COR_WRITE); | ||
158 | + if (drv->bdrv_co_pwrite_zeroes && | ||
159 | + buffer_is_zero(bounce_buffer, pnum)) { | ||
160 | + /* FIXME: Should we (perhaps conditionally) be setting | ||
161 | + * BDRV_REQ_MAY_UNMAP, if it will allow for a sparser copy | ||
162 | + * that still correctly reads as zero? */ | ||
163 | + ret = bdrv_co_do_pwrite_zeroes(bs, cluster_offset, pnum, 0); | ||
164 | + } else { | ||
165 | + /* This does not change the data on the disk, it is not | ||
166 | + * necessary to flush even in cache=writethrough mode. | ||
167 | + */ | ||
168 | + ret = bdrv_driver_pwritev(bs, cluster_offset, pnum, | ||
169 | + &local_qiov, 0); | ||
170 | + } | ||
171 | + | ||
172 | + if (ret < 0) { | ||
173 | + /* It might be okay to ignore write errors for guest | ||
174 | + * requests. If this is a deliberate copy-on-read | ||
175 | + * then we don't want to ignore the error. Simply | ||
176 | + * report it in all cases. | ||
177 | + */ | ||
178 | + goto err; | ||
179 | + } | ||
180 | + | ||
181 | + qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes, | ||
182 | + pnum - skip_bytes); | ||
183 | + } else { | ||
184 | + /* Read directly into the destination */ | ||
185 | + qemu_iovec_init(&local_qiov, qiov->niov); | ||
186 | + qemu_iovec_concat(&local_qiov, qiov, progress, pnum - skip_bytes); | ||
187 | + ret = bdrv_driver_preadv(bs, offset + progress, local_qiov.size, | ||
188 | + &local_qiov, 0); | ||
189 | + qemu_iovec_destroy(&local_qiov); | ||
190 | + if (ret < 0) { | ||
191 | + goto err; | ||
192 | + } | ||
193 | + } | ||
194 | + | ||
195 | + cluster_offset += pnum; | ||
196 | + cluster_bytes -= pnum; | ||
197 | + progress += pnum - skip_bytes; | ||
198 | + skip_bytes = 0; | ||
199 | + } | 39 | + } |
200 | + ret = 0; | ||
201 | |||
202 | err: | ||
203 | qemu_vfree(bounce_buffer); | ||
204 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num, | ||
205 | return bdrv_co_do_readv(child, sector_num, nb_sectors, qiov, 0); | ||
206 | } | 40 | } |
207 | 41 | ||
208 | -/* Maximum buffer for write zeroes fallback, in bytes */ | 42 | /* |
209 | -#define MAX_WRITE_ZEROES_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS) | ||
210 | - | ||
211 | static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, | ||
212 | int64_t offset, int bytes, BdrvRequestFlags flags) | ||
213 | { | ||
214 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, | ||
215 | int max_write_zeroes = MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT_MAX); | ||
216 | int alignment = MAX(bs->bl.pwrite_zeroes_alignment, | ||
217 | bs->bl.request_alignment); | ||
218 | - int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, | ||
219 | - MAX_WRITE_ZEROES_BOUNCE_BUFFER); | ||
220 | + int max_transfer = MIN_NON_ZERO(bs->bl.max_transfer, MAX_BOUNCE_BUFFER); | ||
221 | |||
222 | assert(alignment % bs->bl.request_alignment == 0); | ||
223 | head = offset % alignment; | ||
224 | -- | 43 | -- |
225 | 2.13.6 | 44 | 2.13.6 |
226 | 45 | ||
227 | 46 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | ||
---|---|---|---|
2 | |||
3 | We're already reporting bytes for bdrv_dirty_bitmap_granularity(); | ||
4 | mixing bytes and sectors in our return values is a recipe for | ||
5 | confusion. A later cleanup will convert dirty bitmap internals | ||
6 | to be entirely byte-based, but in the meantime, we should report | ||
7 | the bitmap size in bytes. | ||
8 | |||
9 | The only external caller in qcow2-bitmap.c is temporarily more verbose | ||
10 | (because it is still using sector-based math), but will later be | ||
11 | switched to track progress by bytes instead of sectors. | ||
12 | |||
13 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
14 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
15 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
18 | --- | 2 | --- |
19 | block/dirty-bitmap.c | 2 +- | 3 | tests/test-bdrv-drain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | block/qcow2-bitmap.c | 14 ++++++++------ | 4 | 1 file changed, 57 insertions(+) |
21 | 2 files changed, 9 insertions(+), 7 deletions(-) | ||
22 | 5 | ||
23 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | 6 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
24 | index XXXXXXX..XXXXXXX 100644 | 7 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/block/dirty-bitmap.c | 8 | --- a/tests/test-bdrv-drain.c |
26 | +++ b/block/dirty-bitmap.c | 9 | +++ b/tests/test-bdrv-drain.c |
27 | @@ -XXX,XX +XXX,XX @@ void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap) | 10 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
28 | 11 | enum drain_type { | |
29 | int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap) | 12 | BDRV_DRAIN_ALL, |
30 | { | 13 | BDRV_DRAIN, |
31 | - return bitmap->size; | 14 | + DRAIN_TYPE_MAX, |
32 | + return bitmap->size * BDRV_SECTOR_SIZE; | 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); | ||
33 | } | 20 | } |
34 | 21 | ||
35 | const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap) | 22 | +static void test_nested(void) |
36 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | 23 | +{ |
37 | index XXXXXXX..XXXXXXX 100644 | 24 | + BlockBackend *blk; |
38 | --- a/block/qcow2-bitmap.c | 25 | + BlockDriverState *bs, *backing; |
39 | +++ b/block/qcow2-bitmap.c | 26 | + BDRVTestState *s, *backing_s; |
40 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | 27 | + enum drain_type outer, inner; |
41 | BDRVQcow2State *s = bs->opaque; | 28 | + |
42 | uint64_t sector, sbc; | 29 | + blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
43 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | 30 | + bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, |
44 | + uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | 31 | + &error_abort); |
45 | uint8_t *buf = NULL; | 32 | + s = bs->opaque; |
46 | uint64_t i, tab_size = | 33 | + blk_insert_bs(blk, bs, &error_abort); |
47 | size_to_clusters(s, | 34 | + |
48 | - bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); | 35 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); |
49 | + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_sectors)); | 36 | + backing_s = backing->opaque; |
50 | 37 | + bdrv_set_backing_hd(bs, backing, &error_abort); | |
51 | if (tab_size != bitmap_table_size || tab_size > BME_MAX_TABLE_SIZE) { | 38 | + |
52 | return -EINVAL; | 39 | + for (outer = 0; outer < DRAIN_TYPE_MAX; outer++) { |
53 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | 40 | + for (inner = 0; inner < DRAIN_TYPE_MAX; inner++) { |
54 | buf = g_malloc(s->cluster_size); | 41 | + /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ |
55 | sbc = sectors_covered_by_bitmap_cluster(s, bitmap); | 42 | + int bs_quiesce = (outer != BDRV_DRAIN_ALL) + |
56 | for (i = 0, sector = 0; i < tab_size; ++i, sector += sbc) { | 43 | + (inner != BDRV_DRAIN_ALL); |
57 | - uint64_t count = MIN(bm_size - sector, sbc); | 44 | + int backing_quiesce = 0; |
58 | + uint64_t count = MIN(bm_sectors - sector, sbc); | 45 | + int backing_cb_cnt = (outer != BDRV_DRAIN) + |
59 | uint64_t entry = bitmap_table[i]; | 46 | + (inner != BDRV_DRAIN); |
60 | uint64_t offset = entry & BME_TABLE_ENTRY_OFFSET_MASK; | 47 | + |
61 | 48 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); | |
62 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 49 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); |
63 | int64_t sector; | 50 | + g_assert_cmpint(s->drain_count, ==, 0); |
64 | uint64_t sbc; | 51 | + g_assert_cmpint(backing_s->drain_count, ==, 0); |
65 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | 52 | + |
66 | + uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | 53 | + do_drain_begin(outer, bs); |
67 | const char *bm_name = bdrv_dirty_bitmap_name(bitmap); | 54 | + do_drain_begin(inner, bs); |
68 | uint8_t *buf = NULL; | 55 | + |
69 | BdrvDirtyBitmapIter *dbi; | 56 | + g_assert_cmpint(bs->quiesce_counter, ==, bs_quiesce); |
70 | uint64_t *tb; | 57 | + g_assert_cmpint(backing->quiesce_counter, ==, backing_quiesce); |
71 | uint64_t tb_size = | 58 | + g_assert_cmpint(s->drain_count, ==, 2); |
72 | size_to_clusters(s, | 59 | + g_assert_cmpint(backing_s->drain_count, ==, backing_cb_cnt); |
73 | - bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); | 60 | + |
74 | + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_sectors)); | 61 | + do_drain_end(inner, bs); |
75 | 62 | + do_drain_end(outer, bs); | |
76 | if (tb_size > BME_MAX_TABLE_SIZE || | 63 | + |
77 | tb_size * s->cluster_size > BME_MAX_PHYS_SIZE) | 64 | + g_assert_cmpint(bs->quiesce_counter, ==, 0); |
78 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 65 | + g_assert_cmpint(backing->quiesce_counter, ==, 0); |
79 | dbi = bdrv_dirty_iter_new(bitmap, 0); | 66 | + g_assert_cmpint(s->drain_count, ==, 0); |
80 | buf = g_malloc(s->cluster_size); | 67 | + g_assert_cmpint(backing_s->drain_count, ==, 0); |
81 | sbc = sectors_covered_by_bitmap_cluster(s, bitmap); | 68 | + } |
82 | - assert(DIV_ROUND_UP(bm_size, sbc) == tb_size); | 69 | + } |
83 | + assert(DIV_ROUND_UP(bm_sectors, sbc) == tb_size); | 70 | + |
84 | 71 | + bdrv_unref(backing); | |
85 | while ((sector = bdrv_dirty_iter_next(dbi)) != -1) { | 72 | + bdrv_unref(bs); |
86 | uint64_t cluster = sector / sbc; | 73 | + blk_unref(blk); |
87 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 74 | +} |
88 | int64_t off; | 75 | + |
89 | 76 | ||
90 | sector = cluster * sbc; | 77 | typedef struct TestBlockJob { |
91 | - end = MIN(bm_size, sector + sbc); | 78 | BlockJob common; |
92 | + end = MIN(bm_sectors, sector + sbc); | 79 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
93 | write_size = | 80 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); |
94 | bdrv_dirty_bitmap_serialization_size(bitmap, sector, end - sector); | 81 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); |
95 | assert(write_size <= s->cluster_size); | 82 | |
96 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | 83 | + g_test_add_func("/bdrv-drain/nested", test_nested); |
97 | goto fail; | 84 | + |
98 | } | 85 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); |
99 | 86 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); | |
100 | - if (end >= bm_size) { | ||
101 | + if (end >= bm_sectors) { | ||
102 | break; | ||
103 | } | ||
104 | 87 | ||
105 | -- | 88 | -- |
106 | 2.13.6 | 89 | 2.13.6 |
107 | 90 | ||
108 | 91 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | We are still using an internal hbitmap that tracks a size in sectors, | ||
4 | with the granularity scaled down accordingly, because it lets us | ||
5 | use a shortcut for our iterators which are currently sector-based. | ||
6 | But there's no reason we can't track the dirty bitmap size in bytes, | ||
7 | since it is (mostly) an internal-only variable (remember, the size | ||
8 | is how many bytes are covered by the bitmap, not how many bytes the | ||
9 | bitmap occupies). A later cleanup will convert dirty bitmap | ||
10 | internals to be entirely byte-based, eliminating the intermediate | ||
11 | sector rounding added here; and technically, since bdrv_getlength() | ||
12 | already rounds up to sectors, our use of DIV_ROUND_UP is more for | ||
13 | theoretical completeness than for any actual rounding. | ||
14 | |||
15 | Use is_power_of_2() while at it, instead of open-coding that. | ||
16 | |||
17 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
18 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
19 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
20 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
21 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
22 | --- | ||
23 | block/dirty-bitmap.c | 26 ++++++++++++++------------ | ||
24 | 1 file changed, 14 insertions(+), 12 deletions(-) | ||
25 | |||
26 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/block/dirty-bitmap.c | ||
29 | +++ b/block/dirty-bitmap.c | ||
30 | @@ -XXX,XX +XXX,XX @@ struct BdrvDirtyBitmap { | ||
31 | HBitmap *meta; /* Meta dirty bitmap */ | ||
32 | BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status */ | ||
33 | char *name; /* Optional non-empty unique ID */ | ||
34 | - int64_t size; /* Size of the bitmap (Number of sectors) */ | ||
35 | + int64_t size; /* Size of the bitmap, in bytes */ | ||
36 | bool disabled; /* Bitmap is disabled. It ignores all writes to | ||
37 | the device */ | ||
38 | int active_iterators; /* How many iterators are active */ | ||
39 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, | ||
40 | { | ||
41 | int64_t bitmap_size; | ||
42 | BdrvDirtyBitmap *bitmap; | ||
43 | - uint32_t sector_granularity; | ||
44 | |||
45 | - assert((granularity & (granularity - 1)) == 0); | ||
46 | + assert(is_power_of_2(granularity) && granularity >= BDRV_SECTOR_SIZE); | ||
47 | |||
48 | if (name && bdrv_find_dirty_bitmap(bs, name)) { | ||
49 | error_setg(errp, "Bitmap already exists: %s", name); | ||
50 | return NULL; | ||
51 | } | ||
52 | - sector_granularity = granularity >> BDRV_SECTOR_BITS; | ||
53 | - assert(sector_granularity); | ||
54 | - bitmap_size = bdrv_nb_sectors(bs); | ||
55 | + bitmap_size = bdrv_getlength(bs); | ||
56 | if (bitmap_size < 0) { | ||
57 | error_setg_errno(errp, -bitmap_size, "could not get length of device"); | ||
58 | errno = -bitmap_size; | ||
59 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, | ||
60 | } | ||
61 | bitmap = g_new0(BdrvDirtyBitmap, 1); | ||
62 | bitmap->mutex = &bs->dirty_bitmap_mutex; | ||
63 | - bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(sector_granularity)); | ||
64 | + /* | ||
65 | + * TODO - let hbitmap track full granularity. For now, it is tracking | ||
66 | + * only sector granularity, as a shortcut for our iterators. | ||
67 | + */ | ||
68 | + bitmap->bitmap = hbitmap_alloc(DIV_ROUND_UP(bitmap_size, BDRV_SECTOR_SIZE), | ||
69 | + ctz32(granularity) - BDRV_SECTOR_BITS); | ||
70 | bitmap->size = bitmap_size; | ||
71 | bitmap->name = g_strdup(name); | ||
72 | bitmap->disabled = false; | ||
73 | @@ -XXX,XX +XXX,XX @@ void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap) | ||
74 | |||
75 | int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap) | ||
76 | { | ||
77 | - return bitmap->size * BDRV_SECTOR_SIZE; | ||
78 | + return bitmap->size; | ||
79 | } | ||
80 | |||
81 | const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap) | ||
82 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, | ||
83 | void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes) | ||
84 | { | ||
85 | BdrvDirtyBitmap *bitmap; | ||
86 | - int64_t size = DIV_ROUND_UP(bytes, BDRV_SECTOR_SIZE); | ||
87 | |||
88 | bdrv_dirty_bitmaps_lock(bs); | ||
89 | QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { | ||
90 | assert(!bdrv_dirty_bitmap_frozen(bitmap)); | ||
91 | assert(!bitmap->active_iterators); | ||
92 | - hbitmap_truncate(bitmap->bitmap, size); | ||
93 | - bitmap->size = size; | ||
94 | + hbitmap_truncate(bitmap->bitmap, DIV_ROUND_UP(bytes, BDRV_SECTOR_SIZE)); | ||
95 | + bitmap->size = bytes; | ||
96 | } | ||
97 | bdrv_dirty_bitmaps_unlock(bs); | ||
98 | } | ||
99 | @@ -XXX,XX +XXX,XX @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out) | ||
100 | hbitmap_reset_all(bitmap->bitmap); | ||
101 | } else { | ||
102 | HBitmap *backup = bitmap->bitmap; | ||
103 | - bitmap->bitmap = hbitmap_alloc(bitmap->size, | ||
104 | + bitmap->bitmap = hbitmap_alloc(DIV_ROUND_UP(bitmap->size, | ||
105 | + BDRV_SECTOR_SIZE), | ||
106 | hbitmap_granularity(backup)); | ||
107 | *out = backup; | ||
108 | } | ||
109 | -- | ||
110 | 2.13.6 | ||
111 | |||
112 | diff view generated by jsdifflib |
1 | We don't need to make any assumptions about the graph layout above the | 1 | This is in preparation for subtree drains, i.e. drained sections that |
---|---|---|---|
2 | top node of the commit operation any more. Remove the use of | 2 | affect not only a single node, but recursively all child nodes, too. |
3 | bdrv_find_overlay() and related variables from the commit job code. | 3 | |
4 | 4 | Calling the parent callbacks for drain is pointless when we just came | |
5 | bdrv_drop_intermediate() doesn't use the 'active' parameter any more, so | 5 | from that parent node recursively and leads to multiple increases of |
6 | we can just drop it. | 6 | bs->quiesce_counter in a single drain call. Don't do it. |
7 | 7 | ||
8 | The overlay node was previously added to the block job to get a | 8 | In order for this to work correctly, the parent callback must be called |
9 | BLK_PERM_GRAPH_MOD. We really need to respect those permissions in | 9 | for every bdrv_drain_begin/end() call, not only for the outermost one: |
10 | bdrv_drop_intermediate() now, but as long as we haven't figured out yet | 10 | |
11 | how BLK_PERM_GRAPH_MOD is actually supposed to work, just leave a TODO | 11 | If we have a node N with two parents A and B, recursive draining of A |
12 | comment there. | 12 | should cause the quiesce_counter of B to increase because its child N is |
13 | 13 | drained independently of B. If now B is recursively drained, too, A must | |
14 | With this change, it is now possible to perform another block job on an | 14 | increase its quiesce_counter because N is drained independently of A |
15 | overlay node without conflicts. qemu-iotests 030 is changed accordingly. | 15 | only now, even if N is going from quiesce_counter 1 to 2. |
16 | 16 | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
19 | --- | 18 | --- |
20 | include/block/block.h | 3 +-- | 19 | include/block/block.h | 4 ++-- |
21 | block.c | 6 +++-- | 20 | block.c | 13 +++++++++---- |
22 | block/commit.c | 62 ++++++++++++-------------------------------------- | 21 | block/io.c | 47 ++++++++++++++++++++++++++++++++++------------- |
23 | tests/qemu-iotests/030 | 4 ---- | 22 | 3 files changed, 45 insertions(+), 19 deletions(-) |
24 | 4 files changed, 20 insertions(+), 55 deletions(-) | ||
25 | 23 | ||
26 | diff --git a/include/block/block.h b/include/block/block.h | 24 | diff --git a/include/block/block.h b/include/block/block.h |
27 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/include/block/block.h | 26 | --- a/include/block/block.h |
29 | +++ b/include/block/block.h | 27 | +++ b/include/block/block.h |
30 | @@ -XXX,XX +XXX,XX @@ int bdrv_commit(BlockDriverState *bs); | 28 | @@ -XXX,XX +XXX,XX @@ void bdrv_io_unplug(BlockDriverState *bs); |
31 | int bdrv_change_backing_file(BlockDriverState *bs, | 29 | * Begin a quiesced section of all users of @bs. This is part of |
32 | const char *backing_file, const char *backing_fmt); | 30 | * bdrv_drained_begin. |
33 | void bdrv_register(BlockDriver *bdrv); | 31 | */ |
34 | -int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 32 | -void bdrv_parent_drained_begin(BlockDriverState *bs); |
35 | - BlockDriverState *base, | 33 | +void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore); |
36 | +int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, | 34 | |
37 | const char *backing_file_str); | 35 | /** |
38 | BlockDriverState *bdrv_find_overlay(BlockDriverState *active, | 36 | * bdrv_parent_drained_end: |
39 | BlockDriverState *bs); | 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: | ||
40 | diff --git a/block.c b/block.c | 46 | diff --git a/block.c b/block.c |
41 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/block.c | 48 | --- a/block.c |
43 | +++ b/block.c | 49 | +++ b/block.c |
44 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_find_base(BlockDriverState *bs) | 50 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, |
45 | * if active == top, that is considered an error | 51 | BlockDriverState *new_bs) |
46 | * | 52 | { |
47 | */ | 53 | BlockDriverState *old_bs = child->bs; |
48 | -int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 54 | + int i; |
49 | - BlockDriverState *base, const char *backing_file_str) | 55 | |
50 | +int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, | 56 | if (old_bs && new_bs) { |
51 | + const char *backing_file_str) | 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) | ||
52 | { | 107 | { |
53 | BdrvChild *c, *next; | 108 | BdrvChild *c, *next; |
54 | Error *local_err = NULL; | 109 | |
55 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 110 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { |
56 | } | 111 | + if (c == ignore) { |
57 | 112 | + continue; | |
58 | /* success - we can delete the intermediate states, and link top->base */ | 113 | + } |
59 | + /* TODO Check graph modification op blockers (BLK_PERM_GRAPH_MOD) once | 114 | if (c->role->drained_begin) { |
60 | + * we've figured out how they should work. */ | 115 | c->role->drained_begin(c); |
61 | backing_file_str = backing_file_str ? backing_file_str : base->filename; | 116 | } |
62 | 117 | } | |
63 | QLIST_FOREACH_SAFE(c, &top->parents, next_parent, next) { | 118 | } |
64 | diff --git a/block/commit.c b/block/commit.c | 119 | |
65 | index XXXXXXX..XXXXXXX 100644 | 120 | -void bdrv_parent_drained_end(BlockDriverState *bs) |
66 | --- a/block/commit.c | 121 | +void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore) |
67 | +++ b/block/commit.c | 122 | { |
68 | @@ -XXX,XX +XXX,XX @@ enum { | 123 | BdrvChild *c, *next; |
69 | typedef struct CommitBlockJob { | 124 | |
70 | BlockJob common; | 125 | QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { |
71 | RateLimit limit; | 126 | + if (c == ignore) { |
72 | - BlockDriverState *active; | 127 | + continue; |
73 | BlockDriverState *commit_top_bs; | 128 | + } |
74 | BlockBackend *top; | 129 | if (c->role->drained_end) { |
75 | BlockBackend *base; | 130 | c->role->drained_end(c); |
76 | BlockdevOnError on_error; | 131 | } |
77 | int base_flags; | 132 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
78 | - int orig_overlay_flags; | 133 | BlockDriverState *bs; |
79 | char *backing_file_str; | 134 | bool done; |
80 | } CommitBlockJob; | 135 | bool begin; |
81 | 136 | + BdrvChild *parent; | |
82 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 137 | } BdrvCoDrainData; |
83 | { | 138 | |
84 | CommitBlockJob *s = container_of(job, CommitBlockJob, common); | 139 | static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) |
85 | CommitCompleteData *data = opaque; | 140 | @@ -XXX,XX +XXX,XX @@ static bool bdrv_drain_recurse(BlockDriverState *bs) |
86 | - BlockDriverState *active = s->active; | 141 | return waited; |
87 | BlockDriverState *top = blk_bs(s->top); | 142 | } |
88 | BlockDriverState *base = blk_bs(s->base); | 143 | |
89 | - BlockDriverState *overlay_bs = bdrv_find_overlay(active, s->commit_top_bs); | 144 | +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); |
90 | + BlockDriverState *commit_top_bs = s->commit_top_bs; | 145 | +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); |
91 | int ret = data->ret; | 146 | + |
92 | bool remove_commit_top_bs = false; | 147 | static void bdrv_co_drain_bh_cb(void *opaque) |
93 | 148 | { | |
94 | - /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd() */ | 149 | BdrvCoDrainData *data = opaque; |
95 | + /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */ | 150 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) |
96 | bdrv_ref(top); | 151 | |
97 | - if (overlay_bs) { | 152 | bdrv_dec_in_flight(bs); |
98 | - bdrv_ref(overlay_bs); | 153 | if (data->begin) { |
99 | - } | 154 | - bdrv_drained_begin(bs); |
100 | + bdrv_ref(commit_top_bs); | 155 | + bdrv_do_drained_begin(bs, data->parent); |
101 | 156 | } else { | |
102 | /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before | 157 | - bdrv_drained_end(bs); |
103 | * the normal backing chain can be restored. */ | 158 | + bdrv_do_drained_end(bs, data->parent); |
104 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 159 | } |
105 | 160 | ||
106 | if (!block_job_is_cancelled(&s->common) && ret == 0) { | 161 | data->done = true; |
107 | /* success */ | 162 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) |
108 | - ret = bdrv_drop_intermediate(active, s->commit_top_bs, base, | 163 | } |
109 | + ret = bdrv_drop_intermediate(s->commit_top_bs, base, | 164 | |
110 | s->backing_file_str); | 165 | static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
111 | - } else if (overlay_bs) { | 166 | - bool begin) |
112 | + } else { | 167 | + bool begin, BdrvChild *parent) |
113 | /* XXX Can (or should) we somehow keep 'consistent read' blocked even | 168 | { |
114 | * after the failed/cancelled commit job is gone? If we already wrote | 169 | BdrvCoDrainData data; |
115 | * something to base, the intermediate images aren't valid any more. */ | 170 | |
116 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 171 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
117 | if (s->base_flags != bdrv_get_flags(base)) { | 172 | .bs = bs, |
118 | bdrv_reopen(base, s->base_flags, NULL); | 173 | .done = false, |
119 | } | 174 | .begin = begin, |
120 | - if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) { | 175 | + .parent = parent, |
121 | - bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL); | 176 | }; |
122 | - } | 177 | bdrv_inc_in_flight(bs); |
123 | g_free(s->backing_file_str); | 178 | aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), |
124 | blk_unref(s->top); | 179 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
125 | 180 | assert(data.done); | |
126 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(BlockJob *job, void *opaque) | 181 | } |
127 | * filter driver from the backing chain. Do this as the final step so that | 182 | |
128 | * the 'consistent read' permission can be granted. */ | 183 | -void bdrv_drained_begin(BlockDriverState *bs) |
129 | if (remove_commit_top_bs) { | 184 | +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) |
130 | - bdrv_set_backing_hd(overlay_bs, top, &error_abort); | 185 | { |
131 | + bdrv_child_try_set_perm(commit_top_bs->backing, 0, BLK_PERM_ALL, | 186 | if (qemu_in_coroutine()) { |
132 | + &error_abort); | 187 | - bdrv_co_yield_to_drain(bs, true); |
133 | + bdrv_replace_node(commit_top_bs, backing_bs(commit_top_bs), | 188 | + bdrv_co_yield_to_drain(bs, true, parent); |
134 | + &error_abort); | ||
135 | } | ||
136 | |||
137 | - bdrv_unref(overlay_bs); | ||
138 | + bdrv_unref(commit_top_bs); | ||
139 | bdrv_unref(top); | ||
140 | } | ||
141 | |||
142 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
143 | { | ||
144 | CommitBlockJob *s; | ||
145 | BlockReopenQueue *reopen_queue = NULL; | ||
146 | - int orig_overlay_flags; | ||
147 | int orig_base_flags; | ||
148 | BlockDriverState *iter; | ||
149 | - BlockDriverState *overlay_bs; | ||
150 | BlockDriverState *commit_top_bs = NULL; | ||
151 | Error *local_err = NULL; | ||
152 | int ret; | ||
153 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
154 | return; | 189 | return; |
155 | } | 190 | } |
156 | 191 | ||
157 | - overlay_bs = bdrv_find_overlay(bs, top); | 192 | /* Stop things in parent-to-child order */ |
158 | - | 193 | if (atomic_fetch_inc(&bs->quiesce_counter) == 0) { |
159 | - if (overlay_bs == NULL) { | 194 | aio_disable_external(bdrv_get_aio_context(bs)); |
160 | - error_setg(errp, "Could not find overlay image for %s:", top->filename); | 195 | - bdrv_parent_drained_begin(bs); |
161 | - return; | 196 | } |
162 | - } | 197 | |
163 | - | 198 | + bdrv_parent_drained_begin(bs, parent); |
164 | s = block_job_create(job_id, &commit_job_driver, bs, 0, BLK_PERM_ALL, | 199 | bdrv_drain_invoke(bs, true, false); |
165 | speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp); | 200 | bdrv_drain_recurse(bs); |
166 | if (!s) { | 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); | ||
167 | return; | 216 | return; |
168 | } | 217 | } |
169 | 218 | assert(bs->quiesce_counter > 0); | |
170 | - orig_base_flags = bdrv_get_flags(base); | 219 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_end(BlockDriverState *bs) |
171 | - orig_overlay_flags = bdrv_get_flags(overlay_bs); | 220 | |
172 | - | 221 | /* Re-enable things in child-to-parent order */ |
173 | - /* convert base & overlay_bs to r/w, if necessary */ | 222 | bdrv_drain_invoke(bs, false, false); |
174 | + /* convert base to r/w, if necessary */ | 223 | + bdrv_parent_drained_end(bs, parent); |
175 | + orig_base_flags = bdrv_get_flags(base); | 224 | if (old_quiesce_counter == 1) { |
176 | if (!(orig_base_flags & BDRV_O_RDWR)) { | 225 | - bdrv_parent_drained_end(bs); |
177 | reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL, | 226 | aio_enable_external(bdrv_get_aio_context(bs)); |
178 | orig_base_flags | BDRV_O_RDWR); | 227 | } |
179 | } | 228 | } |
180 | - if (!(orig_overlay_flags & BDRV_O_RDWR)) { | 229 | |
181 | - reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs, NULL, | 230 | +void bdrv_drained_end(BlockDriverState *bs) |
182 | - orig_overlay_flags | BDRV_O_RDWR); | 231 | +{ |
183 | - } | 232 | + bdrv_do_drained_end(bs, NULL); |
233 | +} | ||
184 | + | 234 | + |
185 | if (reopen_queue) { | 235 | /* |
186 | bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &local_err); | 236 | * Wait for pending requests to complete on a single BlockDriverState subtree, |
187 | if (local_err != NULL) { | 237 | * and suspend block driver's internal I/O until next request arrives. |
188 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | 238 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_begin(void) |
189 | goto fail; | 239 | /* Stop things in parent-to-child order */ |
190 | } | 240 | aio_context_acquire(aio_context); |
191 | 241 | aio_disable_external(aio_context); | |
192 | - /* overlay_bs must be blocked because it needs to be modified to | 242 | - bdrv_parent_drained_begin(bs); |
193 | - * update the backing image string. */ | 243 | + bdrv_parent_drained_begin(bs, NULL); |
194 | - ret = block_job_add_bdrv(&s->common, "overlay of top", overlay_bs, | 244 | bdrv_drain_invoke(bs, true, true); |
195 | - BLK_PERM_GRAPH_MOD, BLK_PERM_ALL, errp); | 245 | aio_context_release(aio_context); |
196 | - if (ret < 0) { | 246 | |
197 | - goto fail; | 247 | @@ -XXX,XX +XXX,XX @@ void bdrv_drain_all_end(void) |
198 | - } | 248 | /* Re-enable things in child-to-parent order */ |
199 | - | 249 | aio_context_acquire(aio_context); |
200 | s->base = blk_new(BLK_PERM_CONSISTENT_READ | 250 | bdrv_drain_invoke(bs, false, true); |
201 | | BLK_PERM_WRITE | 251 | - bdrv_parent_drained_end(bs); |
202 | | BLK_PERM_RESIZE, | 252 | + bdrv_parent_drained_end(bs, NULL); |
203 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | 253 | aio_enable_external(aio_context); |
204 | goto fail; | 254 | aio_context_release(aio_context); |
205 | } | 255 | } |
206 | |||
207 | - s->active = bs; | ||
208 | - | ||
209 | - s->base_flags = orig_base_flags; | ||
210 | - s->orig_overlay_flags = orig_overlay_flags; | ||
211 | - | ||
212 | + s->base_flags = orig_base_flags; | ||
213 | s->backing_file_str = g_strdup(backing_file_str); | ||
214 | - | ||
215 | s->on_error = on_error; | ||
216 | |||
217 | trace_commit_start(bs, base, top, s); | ||
218 | @@ -XXX,XX +XXX,XX @@ fail: | ||
219 | blk_unref(s->top); | ||
220 | } | ||
221 | if (commit_top_bs) { | ||
222 | - bdrv_set_backing_hd(overlay_bs, top, &error_abort); | ||
223 | + bdrv_replace_node(commit_top_bs, top, &error_abort); | ||
224 | } | ||
225 | block_job_early_fail(&s->common); | ||
226 | } | ||
227 | diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 | ||
228 | index XXXXXXX..XXXXXXX 100755 | ||
229 | --- a/tests/qemu-iotests/030 | ||
230 | +++ b/tests/qemu-iotests/030 | ||
231 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
232 | result = self.vm.qmp('block-stream', device='node6', base=self.imgs[4], job_id='stream-node6-v2') | ||
233 | self.assert_qmp(result, 'error/class', 'GenericError') | ||
234 | |||
235 | - # This fails because block-commit needs to block node6, the overlay of the 'top' image | ||
236 | - result = self.vm.qmp('block-stream', device='node7', base=self.imgs[5], job_id='stream-node6-v3') | ||
237 | - self.assert_qmp(result, 'error/class', 'GenericError') | ||
238 | - | ||
239 | # This fails because block-commit currently blocks the active layer even if it's not used | ||
240 | result = self.vm.qmp('block-stream', device='drive0', base=self.imgs[5], job_id='stream-drive0') | ||
241 | self.assert_qmp(result, 'error/class', 'GenericError') | ||
242 | -- | 256 | -- |
243 | 2.13.6 | 257 | 2.13.6 |
244 | 258 | ||
245 | 259 | diff view generated by jsdifflib |
1 | From: Eric Blake <eblake@redhat.com> | 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 | Right now, the dirty-bitmap code exposes the fact that we use | 5 | Add a version that keeps the whole subtree drained. As of this commit, |
4 | a scale of sector granularity in the underlying hbitmap to anything | 6 | graph changes cannot be allowed during a subtree drained section, but |
5 | that wants to serialize a dirty bitmap. It's nicer to uniformly | 7 | this will be fixed soon. |
6 | expose bytes as our dirty-bitmap interface, matching the previous | ||
7 | change to bitmap size. The only caller to serialization is currently | ||
8 | qcow2-cluster.c, which becomes a bit more verbose because it is still | ||
9 | tracking sectors for other reasons, but a later patch will fix that | ||
10 | to more uniformly use byte offsets everywhere. Likewise, within | ||
11 | dirty-bitmap, we have to add more assertions that we are not | ||
12 | truncating incorrectly, which can go away once the internal hbitmap | ||
13 | is byte-based rather than sector-based. | ||
14 | 8 | ||
15 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
16 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
17 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
19 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
20 | --- | 10 | --- |
21 | include/block/dirty-bitmap.h | 14 +++++++------- | 11 | include/block/block.h | 13 +++++++++++++ |
22 | block/dirty-bitmap.c | 37 ++++++++++++++++++++++++------------- | 12 | block/io.c | 54 ++++++++++++++++++++++++++++++++++++++++----------- |
23 | block/qcow2-bitmap.c | 22 ++++++++++++++-------- | 13 | 2 files changed, 56 insertions(+), 11 deletions(-) |
24 | 3 files changed, 45 insertions(+), 28 deletions(-) | ||
25 | 14 | ||
26 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | 15 | diff --git a/include/block/block.h b/include/block/block.h |
27 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/include/block/dirty-bitmap.h | 17 | --- a/include/block/block.h |
29 | +++ b/include/block/dirty-bitmap.h | 18 | +++ b/include/block/block.h |
30 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, | 19 | @@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore); |
31 | void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); | 20 | void bdrv_drained_begin(BlockDriverState *bs); |
32 | 21 | ||
33 | uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, | 22 | /** |
34 | - uint64_t start, uint64_t count); | 23 | + * Like bdrv_drained_begin, but recursively begins a quiesced section for |
35 | + uint64_t offset, uint64_t bytes); | 24 | + * exclusive access to all child nodes as well. |
36 | uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap); | 25 | + * |
37 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, | 26 | + * Graph changes are not allowed during a subtree drain section. |
38 | - uint8_t *buf, uint64_t start, | 27 | + */ |
39 | - uint64_t count); | 28 | +void bdrv_subtree_drained_begin(BlockDriverState *bs); |
40 | + uint8_t *buf, uint64_t offset, | 29 | + |
41 | + uint64_t bytes); | 30 | +/** |
42 | void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, | 31 | * bdrv_drained_end: |
43 | - uint8_t *buf, uint64_t start, | 32 | * |
44 | - uint64_t count, bool finish); | 33 | * End a quiescent section started by bdrv_drained_begin(). |
45 | + uint8_t *buf, uint64_t offset, | 34 | */ |
46 | + uint64_t bytes, bool finish); | 35 | void bdrv_drained_end(BlockDriverState *bs); |
47 | void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, | 36 | |
48 | - uint64_t start, uint64_t count, | 37 | +/** |
49 | + uint64_t offset, uint64_t bytes, | 38 | + * End a quiescent section started by bdrv_subtree_drained_begin(). |
50 | bool finish); | 39 | + */ |
51 | void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, | 40 | +void bdrv_subtree_drained_end(BlockDriverState *bs); |
52 | - uint64_t start, uint64_t count, | 41 | + |
53 | + uint64_t offset, uint64_t bytes, | 42 | void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child, |
54 | bool finish); | 43 | Error **errp); |
55 | void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); | 44 | void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **errp); |
56 | 45 | diff --git a/block/io.c b/block/io.c | |
57 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
59 | --- a/block/dirty-bitmap.c | 47 | --- a/block/io.c |
60 | +++ b/block/dirty-bitmap.c | 48 | +++ b/block/io.c |
61 | @@ -XXX,XX +XXX,XX @@ void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in) | 49 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
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; | ||
62 | } | 59 | } |
63 | 60 | ||
64 | uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, | 61 | -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); |
65 | - uint64_t start, uint64_t count) | 62 | -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); |
66 | + uint64_t offset, uint64_t bytes) | 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) | ||
67 | { | 69 | { |
68 | - return hbitmap_serialization_size(bitmap->bitmap, start, count); | 70 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) |
69 | + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | 71 | |
70 | + return hbitmap_serialization_size(bitmap->bitmap, | 72 | bdrv_dec_in_flight(bs); |
71 | + offset >> BDRV_SECTOR_BITS, | 73 | if (data->begin) { |
72 | + bytes >> BDRV_SECTOR_BITS); | 74 | - bdrv_do_drained_begin(bs, data->parent); |
75 | + bdrv_do_drained_begin(bs, data->recursive, data->parent); | ||
76 | } else { | ||
77 | - bdrv_do_drained_end(bs, data->parent); | ||
78 | + bdrv_do_drained_end(bs, data->recursive, data->parent); | ||
79 | } | ||
80 | |||
81 | data->done = true; | ||
82 | @@ -XXX,XX +XXX,XX @@ static void bdrv_co_drain_bh_cb(void *opaque) | ||
73 | } | 83 | } |
74 | 84 | ||
75 | uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap) | 85 | static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, |
86 | - bool begin, BdrvChild *parent) | ||
87 | + bool begin, bool recursive, | ||
88 | + BdrvChild *parent) | ||
76 | { | 89 | { |
77 | - return hbitmap_serialization_align(bitmap->bitmap); | 90 | BdrvCoDrainData data; |
78 | + return hbitmap_serialization_align(bitmap->bitmap) * BDRV_SECTOR_SIZE; | 91 | |
92 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, | ||
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); | ||
79 | } | 102 | } |
80 | 103 | ||
81 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, | 104 | -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) |
82 | - uint8_t *buf, uint64_t start, | 105 | +static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, |
83 | - uint64_t count) | 106 | + BdrvChild *parent) |
84 | + uint8_t *buf, uint64_t offset, | ||
85 | + uint64_t bytes) | ||
86 | { | 107 | { |
87 | - hbitmap_serialize_part(bitmap->bitmap, buf, start, count); | 108 | + BdrvChild *child, *next; |
88 | + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | 109 | + |
89 | + hbitmap_serialize_part(bitmap->bitmap, buf, offset >> BDRV_SECTOR_BITS, | 110 | if (qemu_in_coroutine()) { |
90 | + bytes >> BDRV_SECTOR_BITS); | 111 | - bdrv_co_yield_to_drain(bs, true, parent); |
112 | + bdrv_co_yield_to_drain(bs, true, recursive, parent); | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | @@ -XXX,XX +XXX,XX @@ static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) | ||
117 | bdrv_parent_drained_begin(bs, parent); | ||
118 | bdrv_drain_invoke(bs, true, false); | ||
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 | + } | ||
91 | } | 126 | } |
92 | 127 | ||
93 | void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, | 128 | void bdrv_drained_begin(BlockDriverState *bs) |
94 | - uint8_t *buf, uint64_t start, | ||
95 | - uint64_t count, bool finish) | ||
96 | + uint8_t *buf, uint64_t offset, | ||
97 | + uint64_t bytes, bool finish) | ||
98 | { | 129 | { |
99 | - hbitmap_deserialize_part(bitmap->bitmap, buf, start, count, finish); | 130 | - bdrv_do_drained_begin(bs, NULL); |
100 | + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | 131 | + bdrv_do_drained_begin(bs, false, NULL); |
101 | + hbitmap_deserialize_part(bitmap->bitmap, buf, offset >> BDRV_SECTOR_BITS, | 132 | +} |
102 | + bytes >> BDRV_SECTOR_BITS, finish); | 133 | + |
134 | +void bdrv_subtree_drained_begin(BlockDriverState *bs) | ||
135 | +{ | ||
136 | + bdrv_do_drained_begin(bs, true, NULL); | ||
103 | } | 137 | } |
104 | 138 | ||
105 | void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, | 139 | -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) |
106 | - uint64_t start, uint64_t count, | 140 | +static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, |
107 | + uint64_t offset, uint64_t bytes, | 141 | + BdrvChild *parent) |
108 | bool finish) | ||
109 | { | 142 | { |
110 | - hbitmap_deserialize_zeroes(bitmap->bitmap, start, count, finish); | 143 | + BdrvChild *child, *next; |
111 | + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | 144 | int old_quiesce_counter; |
112 | + hbitmap_deserialize_zeroes(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | 145 | |
113 | + bytes >> BDRV_SECTOR_BITS, finish); | 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 | + } | ||
114 | } | 162 | } |
115 | 163 | ||
116 | void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, | 164 | void bdrv_drained_end(BlockDriverState *bs) |
117 | - uint64_t start, uint64_t count, | ||
118 | + uint64_t offset, uint64_t bytes, | ||
119 | bool finish) | ||
120 | { | 165 | { |
121 | - hbitmap_deserialize_ones(bitmap->bitmap, start, count, finish); | 166 | - bdrv_do_drained_end(bs, NULL); |
122 | + assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | 167 | + bdrv_do_drained_end(bs, false, NULL); |
123 | + hbitmap_deserialize_ones(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | 168 | +} |
124 | + bytes >> BDRV_SECTOR_BITS, finish); | 169 | + |
170 | +void bdrv_subtree_drained_end(BlockDriverState *bs) | ||
171 | +{ | ||
172 | + bdrv_do_drained_end(bs, true, NULL); | ||
125 | } | 173 | } |
126 | 174 | ||
127 | void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) | 175 | /* |
128 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
129 | index XXXXXXX..XXXXXXX 100644 | ||
130 | --- a/block/qcow2-bitmap.c | ||
131 | +++ b/block/qcow2-bitmap.c | ||
132 | @@ -XXX,XX +XXX,XX @@ static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s, | ||
133 | bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; | ||
134 | uint64_t sbc = sector_granularity * (s->cluster_size << 3); | ||
135 | |||
136 | - assert(QEMU_IS_ALIGNED(sbc, | ||
137 | + assert(QEMU_IS_ALIGNED(sbc << BDRV_SECTOR_BITS, | ||
138 | bdrv_dirty_bitmap_serialization_align(bitmap))); | ||
139 | return sbc; | ||
140 | } | ||
141 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
142 | uint8_t *buf = NULL; | ||
143 | uint64_t i, tab_size = | ||
144 | size_to_clusters(s, | ||
145 | - bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_sectors)); | ||
146 | + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); | ||
147 | |||
148 | if (tab_size != bitmap_table_size || tab_size > BME_MAX_TABLE_SIZE) { | ||
149 | return -EINVAL; | ||
150 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
151 | |||
152 | if (offset == 0) { | ||
153 | if (entry & BME_TABLE_ENTRY_FLAG_ALL_ONES) { | ||
154 | - bdrv_dirty_bitmap_deserialize_ones(bitmap, sector, count, | ||
155 | + bdrv_dirty_bitmap_deserialize_ones(bitmap, | ||
156 | + sector * BDRV_SECTOR_SIZE, | ||
157 | + count * BDRV_SECTOR_SIZE, | ||
158 | false); | ||
159 | } else { | ||
160 | /* No need to deserialize zeros because the dirty bitmap is | ||
161 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
162 | if (ret < 0) { | ||
163 | goto finish; | ||
164 | } | ||
165 | - bdrv_dirty_bitmap_deserialize_part(bitmap, buf, sector, count, | ||
166 | + bdrv_dirty_bitmap_deserialize_part(bitmap, buf, | ||
167 | + sector * BDRV_SECTOR_SIZE, | ||
168 | + count * BDRV_SECTOR_SIZE, | ||
169 | false); | ||
170 | } | ||
171 | } | ||
172 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
173 | uint64_t *tb; | ||
174 | uint64_t tb_size = | ||
175 | size_to_clusters(s, | ||
176 | - bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_sectors)); | ||
177 | + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); | ||
178 | |||
179 | if (tb_size > BME_MAX_TABLE_SIZE || | ||
180 | tb_size * s->cluster_size > BME_MAX_PHYS_SIZE) | ||
181 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
182 | |||
183 | sector = cluster * sbc; | ||
184 | end = MIN(bm_sectors, sector + sbc); | ||
185 | - write_size = | ||
186 | - bdrv_dirty_bitmap_serialization_size(bitmap, sector, end - sector); | ||
187 | + write_size = bdrv_dirty_bitmap_serialization_size(bitmap, | ||
188 | + sector * BDRV_SECTOR_SIZE, (end - sector) * BDRV_SECTOR_SIZE); | ||
189 | assert(write_size <= s->cluster_size); | ||
190 | |||
191 | off = qcow2_alloc_clusters(bs, s->cluster_size); | ||
192 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
193 | } | ||
194 | tb[cluster] = off; | ||
195 | |||
196 | - bdrv_dirty_bitmap_serialize_part(bitmap, buf, sector, end - sector); | ||
197 | + bdrv_dirty_bitmap_serialize_part(bitmap, buf, | ||
198 | + sector * BDRV_SECTOR_SIZE, | ||
199 | + (end - sector) * BDRV_SECTOR_SIZE); | ||
200 | if (write_size < s->cluster_size) { | ||
201 | memset(buf + write_size, 0, s->cluster_size - write_size); | ||
202 | } | ||
203 | -- | 176 | -- |
204 | 2.13.6 | 177 | 2.13.6 |
205 | 178 | ||
206 | 179 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Thanks to recent cleanups, most callers were scaling a return value | ||
4 | of sectors into bytes (the exception, in qcow2-bitmap, will be | ||
5 | converted to byte-based iteration later). Update the interface to | ||
6 | do the scaling internally instead. | ||
7 | |||
8 | In qcow2-bitmap, the code was specifically checking for an error | ||
9 | return of -1. To avoid a regression, we either have to make sure | ||
10 | we continue to return -1 (rather than a scaled -512) on error, or | ||
11 | we have to fix the caller to treat all negative values as error | ||
12 | rather than just one magic value. It's easy enough to make both | ||
13 | changes at the same time, even though either one in isolation | ||
14 | would work. | ||
15 | |||
16 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
17 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
18 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
19 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
20 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
21 | --- | ||
22 | block/backup.c | 2 +- | ||
23 | block/dirty-bitmap.c | 3 ++- | ||
24 | block/mirror.c | 8 ++++---- | ||
25 | block/qcow2-bitmap.c | 2 +- | ||
26 | 4 files changed, 8 insertions(+), 7 deletions(-) | ||
27 | |||
28 | diff --git a/block/backup.c b/block/backup.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/block/backup.c | ||
31 | +++ b/block/backup.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run_incremental(BackupBlockJob *job) | ||
33 | dbi = bdrv_dirty_iter_new(job->sync_bitmap); | ||
34 | |||
35 | /* Find the next dirty sector(s) */ | ||
36 | - while ((offset = bdrv_dirty_iter_next(dbi) * BDRV_SECTOR_SIZE) >= 0) { | ||
37 | + while ((offset = bdrv_dirty_iter_next(dbi)) >= 0) { | ||
38 | cluster = offset / job->cluster_size; | ||
39 | |||
40 | /* Fake progress updates for any clusters we skipped */ | ||
41 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/block/dirty-bitmap.c | ||
44 | +++ b/block/dirty-bitmap.c | ||
45 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter) | ||
46 | |||
47 | int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) | ||
48 | { | ||
49 | - return hbitmap_iter_next(&iter->hbi); | ||
50 | + int64_t ret = hbitmap_iter_next(&iter->hbi); | ||
51 | + return ret < 0 ? -1 : ret * BDRV_SECTOR_SIZE; | ||
52 | } | ||
53 | |||
54 | /* Called within bdrv_dirty_bitmap_lock..unlock */ | ||
55 | diff --git a/block/mirror.c b/block/mirror.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/block/mirror.c | ||
58 | +++ b/block/mirror.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | ||
60 | int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); | ||
61 | |||
62 | bdrv_dirty_bitmap_lock(s->dirty_bitmap); | ||
63 | - offset = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | ||
64 | + offset = bdrv_dirty_iter_next(s->dbi); | ||
65 | if (offset < 0) { | ||
66 | bdrv_set_dirty_iter(s->dbi, 0); | ||
67 | - offset = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | ||
68 | + offset = bdrv_dirty_iter_next(s->dbi); | ||
69 | trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap) * | ||
70 | BDRV_SECTOR_SIZE); | ||
71 | assert(offset >= 0); | ||
72 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | - next_dirty = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | ||
77 | + next_dirty = bdrv_dirty_iter_next(s->dbi); | ||
78 | if (next_dirty > next_offset || next_dirty < 0) { | ||
79 | /* The bitmap iterator's cache is stale, refresh it */ | ||
80 | bdrv_set_dirty_iter(s->dbi, next_offset); | ||
81 | - next_dirty = bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; | ||
82 | + next_dirty = bdrv_dirty_iter_next(s->dbi); | ||
83 | } | ||
84 | assert(next_dirty == next_offset); | ||
85 | nb_chunks++; | ||
86 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/block/qcow2-bitmap.c | ||
89 | +++ b/block/qcow2-bitmap.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
91 | sbc = limit >> BDRV_SECTOR_BITS; | ||
92 | assert(DIV_ROUND_UP(bm_size, limit) == tb_size); | ||
93 | |||
94 | - while ((sector = bdrv_dirty_iter_next(dbi)) != -1) { | ||
95 | + while ((sector = bdrv_dirty_iter_next(dbi) >> BDRV_SECTOR_BITS) >= 0) { | ||
96 | uint64_t cluster = sector / sbc; | ||
97 | uint64_t end, write_size; | ||
98 | int64_t off; | ||
99 | -- | ||
100 | 2.13.6 | ||
101 | |||
102 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Thanks to recent cleanups, all callers were scaling a return value | ||
4 | of sectors into bytes; do the scaling internally instead. | ||
5 | |||
6 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | --- | ||
12 | block/dirty-bitmap.c | 4 ++-- | ||
13 | block/mirror.c | 16 ++++++---------- | ||
14 | migration/block.c | 2 +- | ||
15 | 3 files changed, 9 insertions(+), 13 deletions(-) | ||
16 | |||
17 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/dirty-bitmap.c | ||
20 | +++ b/block/dirty-bitmap.c | ||
21 | @@ -XXX,XX +XXX,XX @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs) | ||
22 | QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { | ||
23 | BlockDirtyInfo *info = g_new0(BlockDirtyInfo, 1); | ||
24 | BlockDirtyInfoList *entry = g_new0(BlockDirtyInfoList, 1); | ||
25 | - info->count = bdrv_get_dirty_count(bm) << BDRV_SECTOR_BITS; | ||
26 | + info->count = bdrv_get_dirty_count(bm); | ||
27 | info->granularity = bdrv_dirty_bitmap_granularity(bm); | ||
28 | info->has_name = !!bm->name; | ||
29 | info->name = g_strdup(bm->name); | ||
30 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *iter, int64_t offset) | ||
31 | |||
32 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap) | ||
33 | { | ||
34 | - return hbitmap_count(bitmap->bitmap); | ||
35 | + return hbitmap_count(bitmap->bitmap) << BDRV_SECTOR_BITS; | ||
36 | } | ||
37 | |||
38 | int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap) | ||
39 | diff --git a/block/mirror.c b/block/mirror.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/block/mirror.c | ||
42 | +++ b/block/mirror.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | ||
44 | if (offset < 0) { | ||
45 | bdrv_set_dirty_iter(s->dbi, 0); | ||
46 | offset = bdrv_dirty_iter_next(s->dbi); | ||
47 | - trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap) * | ||
48 | - BDRV_SECTOR_SIZE); | ||
49 | + trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap)); | ||
50 | assert(offset >= 0); | ||
51 | } | ||
52 | bdrv_dirty_bitmap_unlock(s->dirty_bitmap); | ||
53 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn mirror_run(void *opaque) | ||
54 | |||
55 | cnt = bdrv_get_dirty_count(s->dirty_bitmap); | ||
56 | /* s->common.offset contains the number of bytes already processed so | ||
57 | - * far, cnt is the number of dirty sectors remaining and | ||
58 | + * far, cnt is the number of dirty bytes remaining and | ||
59 | * s->bytes_in_flight is the number of bytes currently being | ||
60 | * processed; together those are the current total operation length */ | ||
61 | - s->common.len = s->common.offset + s->bytes_in_flight + | ||
62 | - cnt * BDRV_SECTOR_SIZE; | ||
63 | + s->common.len = s->common.offset + s->bytes_in_flight + cnt; | ||
64 | |||
65 | /* Note that even when no rate limit is applied we need to yield | ||
66 | * periodically with no pending I/O so that bdrv_drain_all() returns. | ||
67 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn mirror_run(void *opaque) | ||
68 | s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) { | ||
69 | if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 || | ||
70 | (cnt == 0 && s->in_flight > 0)) { | ||
71 | - trace_mirror_yield(s, cnt * BDRV_SECTOR_SIZE, | ||
72 | - s->buf_free_count, s->in_flight); | ||
73 | + trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight); | ||
74 | mirror_wait_for_io(s); | ||
75 | continue; | ||
76 | } else if (cnt != 0) { | ||
77 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn mirror_run(void *opaque) | ||
78 | * whether to switch to target check one last time if I/O has | ||
79 | * come in the meanwhile, and if not flush the data to disk. | ||
80 | */ | ||
81 | - trace_mirror_before_drain(s, cnt * BDRV_SECTOR_SIZE); | ||
82 | + trace_mirror_before_drain(s, cnt); | ||
83 | |||
84 | bdrv_drained_begin(bs); | ||
85 | cnt = bdrv_get_dirty_count(s->dirty_bitmap); | ||
86 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn mirror_run(void *opaque) | ||
87 | } | ||
88 | |||
89 | ret = 0; | ||
90 | - trace_mirror_before_sleep(s, cnt * BDRV_SECTOR_SIZE, | ||
91 | - s->synced, delay_ns); | ||
92 | + trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); | ||
93 | if (!s->synced) { | ||
94 | block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, delay_ns); | ||
95 | if (block_job_is_cancelled(&s->common)) { | ||
96 | diff --git a/migration/block.c b/migration/block.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/migration/block.c | ||
99 | +++ b/migration/block.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static int64_t get_remaining_dirty(void) | ||
101 | aio_context_release(blk_get_aio_context(bmds->blk)); | ||
102 | } | ||
103 | |||
104 | - return dirty << BDRV_SECTOR_BITS; | ||
105 | + return dirty; | ||
106 | } | ||
107 | |||
108 | |||
109 | -- | ||
110 | 2.13.6 | ||
111 | |||
112 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Some of the callers were already scaling bytes to sectors; others | ||
4 | can be easily converted to pass byte offsets, all in our shift | ||
5 | towards a consistent byte interface everywhere. Making the change | ||
6 | will also make it easier to write the hold-out callers to use byte | ||
7 | rather than sectors for their iterations; it also makes it easier | ||
8 | for a future dirty-bitmap patch to offload scaling over to the | ||
9 | internal hbitmap. Although all callers happen to pass | ||
10 | sector-aligned values, make the internal scaling robust to any | ||
11 | sub-sector requests. | ||
12 | |||
13 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
14 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
15 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
16 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
17 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
18 | --- | ||
19 | include/block/dirty-bitmap.h | 8 ++++---- | ||
20 | block/dirty-bitmap.c | 22 ++++++++++++++-------- | ||
21 | block/mirror.c | 16 ++++++++-------- | ||
22 | migration/block.c | 7 +++++-- | ||
23 | 4 files changed, 31 insertions(+), 22 deletions(-) | ||
24 | |||
25 | diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/block/dirty-bitmap.h | ||
28 | +++ b/include/block/dirty-bitmap.h | ||
29 | @@ -XXX,XX +XXX,XX @@ const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); | ||
30 | int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap); | ||
31 | DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); | ||
32 | void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
33 | - int64_t cur_sector, int64_t nr_sectors); | ||
34 | + int64_t offset, int64_t bytes); | ||
35 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
36 | - int64_t cur_sector, int64_t nr_sectors); | ||
37 | + int64_t offset, int64_t bytes); | ||
38 | BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyBitmap *bitmap); | ||
39 | BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap); | ||
40 | void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); | ||
41 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); | ||
42 | bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | ||
43 | int64_t offset); | ||
44 | void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
45 | - int64_t cur_sector, int64_t nr_sectors); | ||
46 | + int64_t offset, int64_t bytes); | ||
47 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
48 | - int64_t cur_sector, int64_t nr_sectors); | ||
49 | + int64_t offset, int64_t bytes); | ||
50 | int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); | ||
51 | void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); | ||
52 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); | ||
53 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/block/dirty-bitmap.c | ||
56 | +++ b/block/dirty-bitmap.c | ||
57 | @@ -XXX,XX +XXX,XX @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) | ||
58 | |||
59 | /* Called within bdrv_dirty_bitmap_lock..unlock */ | ||
60 | void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
61 | - int64_t cur_sector, int64_t nr_sectors) | ||
62 | + int64_t offset, int64_t bytes) | ||
63 | { | ||
64 | + int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
65 | + | ||
66 | assert(bdrv_dirty_bitmap_enabled(bitmap)); | ||
67 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
68 | - hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); | ||
69 | + hbitmap_set(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
70 | + end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
71 | } | ||
72 | |||
73 | void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
74 | - int64_t cur_sector, int64_t nr_sectors) | ||
75 | + int64_t offset, int64_t bytes) | ||
76 | { | ||
77 | bdrv_dirty_bitmap_lock(bitmap); | ||
78 | - bdrv_set_dirty_bitmap_locked(bitmap, cur_sector, nr_sectors); | ||
79 | + bdrv_set_dirty_bitmap_locked(bitmap, offset, bytes); | ||
80 | bdrv_dirty_bitmap_unlock(bitmap); | ||
81 | } | ||
82 | |||
83 | /* Called within bdrv_dirty_bitmap_lock..unlock */ | ||
84 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
85 | - int64_t cur_sector, int64_t nr_sectors) | ||
86 | + int64_t offset, int64_t bytes) | ||
87 | { | ||
88 | + int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
89 | + | ||
90 | assert(bdrv_dirty_bitmap_enabled(bitmap)); | ||
91 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
92 | - hbitmap_reset(bitmap->bitmap, cur_sector, nr_sectors); | ||
93 | + hbitmap_reset(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
94 | + end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
95 | } | ||
96 | |||
97 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
98 | - int64_t cur_sector, int64_t nr_sectors) | ||
99 | + int64_t offset, int64_t bytes) | ||
100 | { | ||
101 | bdrv_dirty_bitmap_lock(bitmap); | ||
102 | - bdrv_reset_dirty_bitmap_locked(bitmap, cur_sector, nr_sectors); | ||
103 | + bdrv_reset_dirty_bitmap_locked(bitmap, offset, bytes); | ||
104 | bdrv_dirty_bitmap_unlock(bitmap); | ||
105 | } | ||
106 | |||
107 | diff --git a/block/mirror.c b/block/mirror.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/block/mirror.c | ||
110 | +++ b/block/mirror.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static void mirror_write_complete(void *opaque, int ret) | ||
112 | if (ret < 0) { | ||
113 | BlockErrorAction action; | ||
114 | |||
115 | - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset >> BDRV_SECTOR_BITS, | ||
116 | - op->bytes >> BDRV_SECTOR_BITS); | ||
117 | + bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes); | ||
118 | action = mirror_error_action(s, false, -ret); | ||
119 | if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) { | ||
120 | s->ret = ret; | ||
121 | @@ -XXX,XX +XXX,XX @@ static void mirror_read_complete(void *opaque, int ret) | ||
122 | if (ret < 0) { | ||
123 | BlockErrorAction action; | ||
124 | |||
125 | - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset >> BDRV_SECTOR_BITS, | ||
126 | - op->bytes >> BDRV_SECTOR_BITS); | ||
127 | + bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset, op->bytes); | ||
128 | action = mirror_error_action(s, true, -ret); | ||
129 | if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) { | ||
130 | s->ret = ret; | ||
131 | @@ -XXX,XX +XXX,XX @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) | ||
132 | * calling bdrv_get_block_status_above could yield - if some blocks are | ||
133 | * marked dirty in this window, we need to know. | ||
134 | */ | ||
135 | - bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset >> BDRV_SECTOR_BITS, | ||
136 | - nb_chunks * sectors_per_chunk); | ||
137 | + bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset, | ||
138 | + nb_chunks * s->granularity); | ||
139 | bdrv_dirty_bitmap_unlock(s->dirty_bitmap); | ||
140 | |||
141 | bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks); | ||
142 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
143 | |||
144 | if (base == NULL && !bdrv_has_zero_init(target_bs)) { | ||
145 | if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { | ||
146 | - bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, end); | ||
147 | + bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); | ||
148 | return 0; | ||
149 | } | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
152 | n = count >> BDRV_SECTOR_BITS; | ||
153 | assert(n > 0); | ||
154 | if (ret == 1) { | ||
155 | - bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n); | ||
156 | + bdrv_set_dirty_bitmap(s->dirty_bitmap, | ||
157 | + sector_num * BDRV_SECTOR_SIZE, | ||
158 | + n * BDRV_SECTOR_SIZE); | ||
159 | } | ||
160 | sector_num += n; | ||
161 | } | ||
162 | diff --git a/migration/block.c b/migration/block.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/migration/block.c | ||
165 | +++ b/migration/block.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds) | ||
167 | blk->aiocb = blk_aio_preadv(bb, cur_sector * BDRV_SECTOR_SIZE, &blk->qiov, | ||
168 | 0, blk_mig_read_cb, blk); | ||
169 | |||
170 | - bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, cur_sector, nr_sectors); | ||
171 | + bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, cur_sector * BDRV_SECTOR_SIZE, | ||
172 | + nr_sectors * BDRV_SECTOR_SIZE); | ||
173 | aio_context_release(blk_get_aio_context(bmds->blk)); | ||
174 | qemu_mutex_unlock_iothread(); | ||
175 | |||
176 | @@ -XXX,XX +XXX,XX @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds, | ||
177 | } else { | ||
178 | nr_sectors = BDRV_SECTORS_PER_DIRTY_CHUNK; | ||
179 | } | ||
180 | - bdrv_reset_dirty_bitmap_locked(bmds->dirty_bitmap, sector, nr_sectors); | ||
181 | + bdrv_reset_dirty_bitmap_locked(bmds->dirty_bitmap, | ||
182 | + sector * BDRV_SECTOR_SIZE, | ||
183 | + nr_sectors * BDRV_SECTOR_SIZE); | ||
184 | bdrv_dirty_bitmap_unlock(bmds->dirty_bitmap); | ||
185 | |||
186 | blk = g_new(BlkMigBlock, 1); | ||
187 | -- | ||
188 | 2.13.6 | ||
189 | |||
190 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Now that we have adjusted the majority of the calls this function | ||
4 | makes to be byte-based, it is easier to read the code if it makes | ||
5 | passes over the image using bytes rather than sectors. | ||
6 | |||
7 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block/mirror.c | 38 ++++++++++++++------------------------ | ||
14 | 1 file changed, 14 insertions(+), 24 deletions(-) | ||
15 | |||
16 | diff --git a/block/mirror.c b/block/mirror.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/mirror.c | ||
19 | +++ b/block/mirror.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void mirror_throttle(MirrorBlockJob *s) | ||
21 | |||
22 | static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
23 | { | ||
24 | - int64_t sector_num, end; | ||
25 | + int64_t offset; | ||
26 | BlockDriverState *base = s->base; | ||
27 | BlockDriverState *bs = s->source; | ||
28 | BlockDriverState *target_bs = blk_bs(s->target); | ||
29 | - int ret, n; | ||
30 | + int ret; | ||
31 | int64_t count; | ||
32 | |||
33 | - end = s->bdev_length / BDRV_SECTOR_SIZE; | ||
34 | - | ||
35 | if (base == NULL && !bdrv_has_zero_init(target_bs)) { | ||
36 | if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { | ||
37 | bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); | ||
38 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
39 | } | ||
40 | |||
41 | s->initial_zeroing_ongoing = true; | ||
42 | - for (sector_num = 0; sector_num < end; ) { | ||
43 | - int nb_sectors = MIN(end - sector_num, | ||
44 | - QEMU_ALIGN_DOWN(INT_MAX, s->granularity) >> BDRV_SECTOR_BITS); | ||
45 | + for (offset = 0; offset < s->bdev_length; ) { | ||
46 | + int bytes = MIN(s->bdev_length - offset, | ||
47 | + QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); | ||
48 | |||
49 | mirror_throttle(s); | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
52 | continue; | ||
53 | } | ||
54 | |||
55 | - mirror_do_zero_or_discard(s, sector_num * BDRV_SECTOR_SIZE, | ||
56 | - nb_sectors * BDRV_SECTOR_SIZE, false); | ||
57 | - sector_num += nb_sectors; | ||
58 | + mirror_do_zero_or_discard(s, offset, bytes, false); | ||
59 | + offset += bytes; | ||
60 | } | ||
61 | |||
62 | mirror_wait_for_all_io(s); | ||
63 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
64 | } | ||
65 | |||
66 | /* First part, loop on the sectors and initialize the dirty bitmap. */ | ||
67 | - for (sector_num = 0; sector_num < end; ) { | ||
68 | + for (offset = 0; offset < s->bdev_length; ) { | ||
69 | /* Just to make sure we are not exceeding int limit. */ | ||
70 | - int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS, | ||
71 | - end - sector_num); | ||
72 | + int bytes = MIN(s->bdev_length - offset, | ||
73 | + QEMU_ALIGN_DOWN(INT_MAX, s->granularity)); | ||
74 | |||
75 | mirror_throttle(s); | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | - ret = bdrv_is_allocated_above(bs, base, sector_num * BDRV_SECTOR_SIZE, | ||
82 | - nb_sectors * BDRV_SECTOR_SIZE, &count); | ||
83 | + ret = bdrv_is_allocated_above(bs, base, offset, bytes, &count); | ||
84 | if (ret < 0) { | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | - /* TODO: Relax this once bdrv_is_allocated_above and dirty | ||
89 | - * bitmaps no longer require sector alignment. */ | ||
90 | - assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); | ||
91 | - n = count >> BDRV_SECTOR_BITS; | ||
92 | - assert(n > 0); | ||
93 | + assert(count); | ||
94 | if (ret == 1) { | ||
95 | - bdrv_set_dirty_bitmap(s->dirty_bitmap, | ||
96 | - sector_num * BDRV_SECTOR_SIZE, | ||
97 | - n * BDRV_SECTOR_SIZE); | ||
98 | + bdrv_set_dirty_bitmap(s->dirty_bitmap, offset, count); | ||
99 | } | ||
100 | - sector_num += n; | ||
101 | + offset += count; | ||
102 | } | ||
103 | return 0; | ||
104 | } | ||
105 | -- | ||
106 | 2.13.6 | ||
107 | |||
108 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | This is new code, but it is easier to read if it makes passes over | ||
4 | the image using bytes rather than sectors (and will get easier in | ||
5 | the future when bdrv_get_block_status is converted to byte-based). | ||
6 | |||
7 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
10 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
11 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | --- | ||
13 | block/qcow2.c | 22 ++++++++++------------ | ||
14 | 1 file changed, 10 insertions(+), 12 deletions(-) | ||
15 | |||
16 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/block/qcow2.c | ||
19 | +++ b/block/qcow2.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs, | ||
21 | */ | ||
22 | required = virtual_size; | ||
23 | } else { | ||
24 | - int cluster_sectors = cluster_size / BDRV_SECTOR_SIZE; | ||
25 | - int64_t sector_num; | ||
26 | + int64_t offset; | ||
27 | int pnum = 0; | ||
28 | |||
29 | - for (sector_num = 0; | ||
30 | - sector_num < ssize / BDRV_SECTOR_SIZE; | ||
31 | - sector_num += pnum) { | ||
32 | - int nb_sectors = MIN(ssize / BDRV_SECTOR_SIZE - sector_num, | ||
33 | - BDRV_REQUEST_MAX_SECTORS); | ||
34 | + for (offset = 0; offset < ssize; | ||
35 | + offset += pnum * BDRV_SECTOR_SIZE) { | ||
36 | + int nb_sectors = MIN(ssize - offset, | ||
37 | + BDRV_REQUEST_MAX_BYTES) / BDRV_SECTOR_SIZE; | ||
38 | BlockDriverState *file; | ||
39 | int64_t ret; | ||
40 | |||
41 | ret = bdrv_get_block_status_above(in_bs, NULL, | ||
42 | - sector_num, nb_sectors, | ||
43 | + offset >> BDRV_SECTOR_BITS, | ||
44 | + nb_sectors, | ||
45 | &pnum, &file); | ||
46 | if (ret < 0) { | ||
47 | error_setg_errno(&local_err, -ret, | ||
48 | @@ -XXX,XX +XXX,XX @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs, | ||
49 | } else if ((ret & (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) == | ||
50 | (BDRV_BLOCK_DATA | BDRV_BLOCK_ALLOCATED)) { | ||
51 | /* Extend pnum to end of cluster for next iteration */ | ||
52 | - pnum = ROUND_UP(sector_num + pnum, cluster_sectors) - | ||
53 | - sector_num; | ||
54 | + pnum = (ROUND_UP(offset + pnum * BDRV_SECTOR_SIZE, | ||
55 | + cluster_size) - offset) >> BDRV_SECTOR_BITS; | ||
56 | |||
57 | /* Count clusters we've seen */ | ||
58 | - required += (sector_num % cluster_sectors + pnum) * | ||
59 | - BDRV_SECTOR_SIZE; | ||
60 | + required += offset % cluster_size + pnum * BDRV_SECTOR_SIZE; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | -- | ||
65 | 2.13.6 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Now that we have adjusted the majority of the calls this function | ||
4 | makes to be byte-based, it is easier to read the code if it makes | ||
5 | passes over the image using bytes rather than sectors. | ||
6 | |||
7 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
10 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
11 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | --- | ||
14 | block/qcow2-bitmap.c | 22 ++++++++-------------- | ||
15 | 1 file changed, 8 insertions(+), 14 deletions(-) | ||
16 | |||
17 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/qcow2-bitmap.c | ||
20 | +++ b/block/qcow2-bitmap.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
22 | { | ||
23 | int ret = 0; | ||
24 | BDRVQcow2State *s = bs->opaque; | ||
25 | - uint64_t sector, limit, sbc; | ||
26 | + uint64_t offset, limit; | ||
27 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | ||
28 | - uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | ||
29 | uint8_t *buf = NULL; | ||
30 | uint64_t i, tab_size = | ||
31 | size_to_clusters(s, | ||
32 | @@ -XXX,XX +XXX,XX @@ static int load_bitmap_data(BlockDriverState *bs, | ||
33 | |||
34 | buf = g_malloc(s->cluster_size); | ||
35 | limit = bytes_covered_by_bitmap_cluster(s, bitmap); | ||
36 | - sbc = limit >> BDRV_SECTOR_BITS; | ||
37 | - for (i = 0, sector = 0; i < tab_size; ++i, sector += sbc) { | ||
38 | - uint64_t count = MIN(bm_sectors - sector, sbc); | ||
39 | + for (i = 0, offset = 0; i < tab_size; ++i, offset += limit) { | ||
40 | + uint64_t count = MIN(bm_size - offset, limit); | ||
41 | uint64_t entry = bitmap_table[i]; | ||
42 | - uint64_t offset = entry & BME_TABLE_ENTRY_OFFSET_MASK; | ||
43 | + uint64_t data_offset = entry & BME_TABLE_ENTRY_OFFSET_MASK; | ||
44 | |||
45 | assert(check_table_entry(entry, s->cluster_size) == 0); | ||
46 | |||
47 | - if (offset == 0) { | ||
48 | + if (data_offset == 0) { | ||
49 | if (entry & BME_TABLE_ENTRY_FLAG_ALL_ONES) { | ||
50 | - bdrv_dirty_bitmap_deserialize_ones(bitmap, | ||
51 | - sector * BDRV_SECTOR_SIZE, | ||
52 | - count * BDRV_SECTOR_SIZE, | ||
53 | + bdrv_dirty_bitmap_deserialize_ones(bitmap, offset, count, | ||
54 | false); | ||
55 | } else { | ||
56 | /* No need to deserialize zeros because the dirty bitmap is | ||
57 | * already cleared */ | ||
58 | } | ||
59 | } else { | ||
60 | - ret = bdrv_pread(bs->file, offset, buf, s->cluster_size); | ||
61 | + ret = bdrv_pread(bs->file, data_offset, buf, s->cluster_size); | ||
62 | if (ret < 0) { | ||
63 | goto finish; | ||
64 | } | ||
65 | - bdrv_dirty_bitmap_deserialize_part(bitmap, buf, | ||
66 | - sector * BDRV_SECTOR_SIZE, | ||
67 | - count * BDRV_SECTOR_SIZE, | ||
68 | + bdrv_dirty_bitmap_deserialize_part(bitmap, buf, offset, count, | ||
69 | false); | ||
70 | } | ||
71 | } | ||
72 | -- | ||
73 | 2.13.6 | ||
74 | |||
75 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Now that we have adjusted the majority of the calls this function | ||
4 | makes to be byte-based, it is easier to read the code if it makes | ||
5 | passes over the image using bytes rather than sectors. | ||
6 | |||
7 | iotests 165 was rather weak - on a default 64k-cluster image, where | ||
8 | bitmap granularity also defaults to 64k bytes, a single cluster of | ||
9 | the bitmap table thus covers (64*1024*8) bits which each cover 64k | ||
10 | bytes, or 32G of image space. But the test only uses a 1G image, | ||
11 | so it cannot trigger any more than one loop of the code in | ||
12 | store_bitmap_data(); and it was writing to the first cluster. In | ||
13 | order to test that we are properly aligning which portions of the | ||
14 | bitmap are being written to the file, we really want to test a case | ||
15 | where the first dirty bit returned by bdrv_dirty_iter_next() is not | ||
16 | aligned to the start of a cluster, which we can do by modifying the | ||
17 | test to write data that doesn't happen to fall in the first cluster | ||
18 | of the image. | ||
19 | |||
20 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
21 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
22 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
23 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
24 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
25 | --- | ||
26 | block/qcow2-bitmap.c | 31 ++++++++++++++++--------------- | ||
27 | tests/qemu-iotests/165 | 2 +- | ||
28 | 2 files changed, 17 insertions(+), 16 deletions(-) | ||
29 | |||
30 | diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/block/qcow2-bitmap.c | ||
33 | +++ b/block/qcow2-bitmap.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
35 | { | ||
36 | int ret; | ||
37 | BDRVQcow2State *s = bs->opaque; | ||
38 | - int64_t sector; | ||
39 | - uint64_t limit, sbc; | ||
40 | + int64_t offset; | ||
41 | + uint64_t limit; | ||
42 | uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap); | ||
43 | - uint64_t bm_sectors = DIV_ROUND_UP(bm_size, BDRV_SECTOR_SIZE); | ||
44 | const char *bm_name = bdrv_dirty_bitmap_name(bitmap); | ||
45 | uint8_t *buf = NULL; | ||
46 | BdrvDirtyBitmapIter *dbi; | ||
47 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
48 | dbi = bdrv_dirty_iter_new(bitmap); | ||
49 | buf = g_malloc(s->cluster_size); | ||
50 | limit = bytes_covered_by_bitmap_cluster(s, bitmap); | ||
51 | - sbc = limit >> BDRV_SECTOR_BITS; | ||
52 | assert(DIV_ROUND_UP(bm_size, limit) == tb_size); | ||
53 | |||
54 | - while ((sector = bdrv_dirty_iter_next(dbi) >> BDRV_SECTOR_BITS) >= 0) { | ||
55 | - uint64_t cluster = sector / sbc; | ||
56 | + while ((offset = bdrv_dirty_iter_next(dbi)) >= 0) { | ||
57 | + uint64_t cluster = offset / limit; | ||
58 | uint64_t end, write_size; | ||
59 | int64_t off; | ||
60 | |||
61 | - sector = cluster * sbc; | ||
62 | - end = MIN(bm_sectors, sector + sbc); | ||
63 | - write_size = bdrv_dirty_bitmap_serialization_size(bitmap, | ||
64 | - sector * BDRV_SECTOR_SIZE, (end - sector) * BDRV_SECTOR_SIZE); | ||
65 | + /* | ||
66 | + * We found the first dirty offset, but want to write out the | ||
67 | + * entire cluster of the bitmap that includes that offset, | ||
68 | + * including any leading zero bits. | ||
69 | + */ | ||
70 | + offset = QEMU_ALIGN_DOWN(offset, limit); | ||
71 | + end = MIN(bm_size, offset + limit); | ||
72 | + write_size = bdrv_dirty_bitmap_serialization_size(bitmap, offset, | ||
73 | + end - offset); | ||
74 | assert(write_size <= s->cluster_size); | ||
75 | |||
76 | off = qcow2_alloc_clusters(bs, s->cluster_size); | ||
77 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
78 | } | ||
79 | tb[cluster] = off; | ||
80 | |||
81 | - bdrv_dirty_bitmap_serialize_part(bitmap, buf, | ||
82 | - sector * BDRV_SECTOR_SIZE, | ||
83 | - (end - sector) * BDRV_SECTOR_SIZE); | ||
84 | + bdrv_dirty_bitmap_serialize_part(bitmap, buf, offset, end - offset); | ||
85 | if (write_size < s->cluster_size) { | ||
86 | memset(buf + write_size, 0, s->cluster_size - write_size); | ||
87 | } | ||
88 | @@ -XXX,XX +XXX,XX @@ static uint64_t *store_bitmap_data(BlockDriverState *bs, | ||
89 | goto fail; | ||
90 | } | ||
91 | |||
92 | - if (end >= bm_sectors) { | ||
93 | + if (end >= bm_size) { | ||
94 | break; | ||
95 | } | ||
96 | |||
97 | - bdrv_set_dirty_iter(dbi, end * BDRV_SECTOR_SIZE); | ||
98 | + bdrv_set_dirty_iter(dbi, end); | ||
99 | } | ||
100 | |||
101 | *bitmap_table_size = tb_size; | ||
102 | diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 | ||
103 | index XXXXXXX..XXXXXXX 100755 | ||
104 | --- a/tests/qemu-iotests/165 | ||
105 | +++ b/tests/qemu-iotests/165 | ||
106 | @@ -XXX,XX +XXX,XX @@ disk = os.path.join(iotests.test_dir, 'disk') | ||
107 | disk_size = 0x40000000 # 1G | ||
108 | |||
109 | # regions for qemu_io: (start, count) in bytes | ||
110 | -regions1 = ((0, 0x100000), | ||
111 | +regions1 = ((0x0fff00, 0x10000), | ||
112 | (0x200000, 0x100000)) | ||
113 | |||
114 | regions2 = ((0x10000000, 0x20000), | ||
115 | -- | ||
116 | 2.13.6 | ||
117 | |||
118 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Eric Blake <eblake@redhat.com> | ||
2 | 1 | ||
3 | Now that all callers are using byte-based interfaces, there's no | ||
4 | reason for our internal hbitmap to remain with sector-based | ||
5 | granularity. It also simplifies our internal scaling, since we | ||
6 | already know that hbitmap widens requests out to granularity | ||
7 | boundaries. | ||
8 | |||
9 | Signed-off-by: Eric Blake <eblake@redhat.com> | ||
10 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
11 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | --- | ||
15 | block/dirty-bitmap.c | 62 +++++++++++++++------------------------------------- | ||
16 | 1 file changed, 18 insertions(+), 44 deletions(-) | ||
17 | |||
18 | diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/block/dirty-bitmap.c | ||
21 | +++ b/block/dirty-bitmap.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | */ | ||
24 | struct BdrvDirtyBitmap { | ||
25 | QemuMutex *mutex; | ||
26 | - HBitmap *bitmap; /* Dirty sector bitmap implementation */ | ||
27 | + HBitmap *bitmap; /* Dirty bitmap implementation */ | ||
28 | HBitmap *meta; /* Meta dirty bitmap */ | ||
29 | BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status */ | ||
30 | char *name; /* Optional non-empty unique ID */ | ||
31 | @@ -XXX,XX +XXX,XX @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, | ||
32 | } | ||
33 | bitmap = g_new0(BdrvDirtyBitmap, 1); | ||
34 | bitmap->mutex = &bs->dirty_bitmap_mutex; | ||
35 | - /* | ||
36 | - * TODO - let hbitmap track full granularity. For now, it is tracking | ||
37 | - * only sector granularity, as a shortcut for our iterators. | ||
38 | - */ | ||
39 | - bitmap->bitmap = hbitmap_alloc(DIV_ROUND_UP(bitmap_size, BDRV_SECTOR_SIZE), | ||
40 | - ctz32(granularity) - BDRV_SECTOR_BITS); | ||
41 | + bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(granularity)); | ||
42 | bitmap->size = bitmap_size; | ||
43 | bitmap->name = g_strdup(name); | ||
44 | bitmap->disabled = false; | ||
45 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes) | ||
46 | QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { | ||
47 | assert(!bdrv_dirty_bitmap_frozen(bitmap)); | ||
48 | assert(!bitmap->active_iterators); | ||
49 | - hbitmap_truncate(bitmap->bitmap, DIV_ROUND_UP(bytes, BDRV_SECTOR_SIZE)); | ||
50 | + hbitmap_truncate(bitmap->bitmap, bytes); | ||
51 | bitmap->size = bytes; | ||
52 | } | ||
53 | bdrv_dirty_bitmaps_unlock(bs); | ||
54 | @@ -XXX,XX +XXX,XX @@ bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, | ||
55 | int64_t offset) | ||
56 | { | ||
57 | if (bitmap) { | ||
58 | - return hbitmap_get(bitmap->bitmap, offset >> BDRV_SECTOR_BITS); | ||
59 | + return hbitmap_get(bitmap->bitmap, offset); | ||
60 | } else { | ||
61 | return false; | ||
62 | } | ||
63 | @@ -XXX,XX +XXX,XX @@ uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs) | ||
64 | |||
65 | uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap) | ||
66 | { | ||
67 | - return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap); | ||
68 | + return 1U << hbitmap_granularity(bitmap->bitmap); | ||
69 | } | ||
70 | |||
71 | BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap) | ||
72 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter) | ||
73 | |||
74 | int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter) | ||
75 | { | ||
76 | - int64_t ret = hbitmap_iter_next(&iter->hbi); | ||
77 | - return ret < 0 ? -1 : ret * BDRV_SECTOR_SIZE; | ||
78 | + return hbitmap_iter_next(&iter->hbi); | ||
79 | } | ||
80 | |||
81 | /* Called within bdrv_dirty_bitmap_lock..unlock */ | ||
82 | void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
83 | int64_t offset, int64_t bytes) | ||
84 | { | ||
85 | - int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
86 | - | ||
87 | assert(bdrv_dirty_bitmap_enabled(bitmap)); | ||
88 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
89 | - hbitmap_set(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
90 | - end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
91 | + hbitmap_set(bitmap->bitmap, offset, bytes); | ||
92 | } | ||
93 | |||
94 | void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
95 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
96 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, | ||
97 | int64_t offset, int64_t bytes) | ||
98 | { | ||
99 | - int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
100 | - | ||
101 | assert(bdrv_dirty_bitmap_enabled(bitmap)); | ||
102 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
103 | - hbitmap_reset(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
104 | - end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
105 | + hbitmap_reset(bitmap->bitmap, offset, bytes); | ||
106 | } | ||
107 | |||
108 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, | ||
109 | @@ -XXX,XX +XXX,XX @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out) | ||
110 | hbitmap_reset_all(bitmap->bitmap); | ||
111 | } else { | ||
112 | HBitmap *backup = bitmap->bitmap; | ||
113 | - bitmap->bitmap = hbitmap_alloc(DIV_ROUND_UP(bitmap->size, | ||
114 | - BDRV_SECTOR_SIZE), | ||
115 | + bitmap->bitmap = hbitmap_alloc(bitmap->size, | ||
116 | hbitmap_granularity(backup)); | ||
117 | *out = backup; | ||
118 | } | ||
119 | @@ -XXX,XX +XXX,XX @@ void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in) | ||
120 | uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, | ||
121 | uint64_t offset, uint64_t bytes) | ||
122 | { | ||
123 | - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | ||
124 | - return hbitmap_serialization_size(bitmap->bitmap, | ||
125 | - offset >> BDRV_SECTOR_BITS, | ||
126 | - bytes >> BDRV_SECTOR_BITS); | ||
127 | + return hbitmap_serialization_size(bitmap->bitmap, offset, bytes); | ||
128 | } | ||
129 | |||
130 | uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap) | ||
131 | { | ||
132 | - return hbitmap_serialization_align(bitmap->bitmap) * BDRV_SECTOR_SIZE; | ||
133 | + return hbitmap_serialization_align(bitmap->bitmap); | ||
134 | } | ||
135 | |||
136 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, | ||
137 | uint8_t *buf, uint64_t offset, | ||
138 | uint64_t bytes) | ||
139 | { | ||
140 | - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | ||
141 | - hbitmap_serialize_part(bitmap->bitmap, buf, offset >> BDRV_SECTOR_BITS, | ||
142 | - bytes >> BDRV_SECTOR_BITS); | ||
143 | + hbitmap_serialize_part(bitmap->bitmap, buf, offset, bytes); | ||
144 | } | ||
145 | |||
146 | void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, | ||
147 | uint8_t *buf, uint64_t offset, | ||
148 | uint64_t bytes, bool finish) | ||
149 | { | ||
150 | - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | ||
151 | - hbitmap_deserialize_part(bitmap->bitmap, buf, offset >> BDRV_SECTOR_BITS, | ||
152 | - bytes >> BDRV_SECTOR_BITS, finish); | ||
153 | + hbitmap_deserialize_part(bitmap->bitmap, buf, offset, bytes, finish); | ||
154 | } | ||
155 | |||
156 | void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, | ||
157 | uint64_t offset, uint64_t bytes, | ||
158 | bool finish) | ||
159 | { | ||
160 | - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | ||
161 | - hbitmap_deserialize_zeroes(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
162 | - bytes >> BDRV_SECTOR_BITS, finish); | ||
163 | + hbitmap_deserialize_zeroes(bitmap->bitmap, offset, bytes, finish); | ||
164 | } | ||
165 | |||
166 | void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, | ||
167 | uint64_t offset, uint64_t bytes, | ||
168 | bool finish) | ||
169 | { | ||
170 | - assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE)); | ||
171 | - hbitmap_deserialize_ones(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
172 | - bytes >> BDRV_SECTOR_BITS, finish); | ||
173 | + hbitmap_deserialize_ones(bitmap->bitmap, offset, bytes, finish); | ||
174 | } | ||
175 | |||
176 | void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) | ||
177 | @@ -XXX,XX +XXX,XX @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) | ||
178 | void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes) | ||
179 | { | ||
180 | BdrvDirtyBitmap *bitmap; | ||
181 | - int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); | ||
182 | |||
183 | if (QLIST_EMPTY(&bs->dirty_bitmaps)) { | ||
184 | return; | ||
185 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes) | ||
186 | continue; | ||
187 | } | ||
188 | assert(!bdrv_dirty_bitmap_readonly(bitmap)); | ||
189 | - hbitmap_set(bitmap->bitmap, offset >> BDRV_SECTOR_BITS, | ||
190 | - end_sector - (offset >> BDRV_SECTOR_BITS)); | ||
191 | + hbitmap_set(bitmap->bitmap, offset, bytes); | ||
192 | } | ||
193 | bdrv_dirty_bitmaps_unlock(bs); | ||
194 | } | ||
195 | @@ -XXX,XX +XXX,XX @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes) | ||
196 | */ | ||
197 | void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *iter, int64_t offset) | ||
198 | { | ||
199 | - hbitmap_iter_init(&iter->hbi, iter->hbi.hb, offset >> BDRV_SECTOR_BITS); | ||
200 | + hbitmap_iter_init(&iter->hbi, iter->hbi.hb, offset); | ||
201 | } | ||
202 | |||
203 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap) | ||
204 | { | ||
205 | - return hbitmap_count(bitmap->bitmap) << BDRV_SECTOR_BITS; | ||
206 | + return hbitmap_count(bitmap->bitmap); | ||
207 | } | ||
208 | |||
209 | int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap) | ||
210 | -- | ||
211 | 2.13.6 | ||
212 | |||
213 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | Add a subtree drain version to the existing test cases. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
6 | --- | 4 | --- |
7 | tests/qemu-iotests/check | 4 ++-- | 5 | tests/test-bdrv-drain.c | 27 ++++++++++++++++++++++++++- |
8 | tests/qemu-iotests/common | 2 +- | 6 | 1 file changed, 26 insertions(+), 1 deletion(-) |
9 | tests/qemu-iotests/common.config | 3 --- | ||
10 | 3 files changed, 3 insertions(+), 6 deletions(-) | ||
11 | 7 | ||
12 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
13 | index XXXXXXX..XXXXXXX 100755 | 9 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tests/qemu-iotests/check | 10 | --- a/tests/test-bdrv-drain.c |
15 | +++ b/tests/qemu-iotests/check | 11 | +++ b/tests/test-bdrv-drain.c |
16 | @@ -XXX,XX +XXX,XX @@ tmp="${TEST_DIR}"/$$ | 12 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
17 | 13 | enum drain_type { | |
18 | _wallclock() | 14 | BDRV_DRAIN_ALL, |
15 | BDRV_DRAIN, | ||
16 | + BDRV_SUBTREE_DRAIN, | ||
17 | DRAIN_TYPE_MAX, | ||
18 | }; | ||
19 | |||
20 | @@ -XXX,XX +XXX,XX @@ static void do_drain_begin(enum drain_type drain_type, BlockDriverState *bs) | ||
21 | switch (drain_type) { | ||
22 | case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; | ||
23 | case BDRV_DRAIN: bdrv_drained_begin(bs); break; | ||
24 | + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_begin(bs); break; | ||
25 | default: g_assert_not_reached(); | ||
26 | } | ||
27 | } | ||
28 | @@ -XXX,XX +XXX,XX @@ static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs) | ||
29 | switch (drain_type) { | ||
30 | case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; | ||
31 | case BDRV_DRAIN: bdrv_drained_end(bs); break; | ||
32 | + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_end(bs); break; | ||
33 | default: g_assert_not_reached(); | ||
34 | } | ||
35 | } | ||
36 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain(void) | ||
37 | test_drv_cb_common(BDRV_DRAIN, false); | ||
38 | } | ||
39 | |||
40 | +static void test_drv_cb_drain_subtree(void) | ||
41 | +{ | ||
42 | + test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); | ||
43 | +} | ||
44 | + | ||
45 | static void test_quiesce_common(enum drain_type drain_type, bool recursive) | ||
19 | { | 46 | { |
20 | - date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }' | 47 | BlockBackend *blk; |
21 | + date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }' | 48 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain(void) |
49 | test_quiesce_common(BDRV_DRAIN, false); | ||
22 | } | 50 | } |
23 | 51 | ||
24 | _timestamp() | 52 | +static void test_quiesce_drain_subtree(void) |
25 | @@ -XXX,XX +XXX,XX @@ _wrapup() | 53 | +{ |
26 | if [ -f $TIMESTAMP_FILE -a -f $tmp.time ] | 54 | + test_quiesce_common(BDRV_SUBTREE_DRAIN, true); |
27 | then | 55 | +} |
28 | cat $TIMESTAMP_FILE $tmp.time \ | 56 | + |
29 | - | $AWK_PROG ' | 57 | static void test_nested(void) |
30 | + | awk ' | 58 | { |
31 | { t[$1] = $2 } | 59 | BlockBackend *blk; |
32 | END { if (NR > 0) { | 60 | @@ -XXX,XX +XXX,XX @@ static void test_nested(void) |
33 | for (i in t) print i " " t[i] | 61 | /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ |
34 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | 62 | int bs_quiesce = (outer != BDRV_DRAIN_ALL) + |
35 | index XXXXXXX..XXXXXXX 100644 | 63 | (inner != BDRV_DRAIN_ALL); |
36 | --- a/tests/qemu-iotests/common | 64 | - int backing_quiesce = 0; |
37 | +++ b/tests/qemu-iotests/common | 65 | + int backing_quiesce = (outer == BDRV_SUBTREE_DRAIN) + |
38 | @@ -XXX,XX +XXX,XX @@ testlist options | 66 | + (inner == BDRV_SUBTREE_DRAIN); |
39 | if $xpand | 67 | int backing_cb_cnt = (outer != BDRV_DRAIN) + |
40 | then | 68 | (inner != BDRV_DRAIN); |
41 | have_test_arg=true | 69 | |
42 | - $AWK_PROG </dev/null ' | 70 | @@ -XXX,XX +XXX,XX @@ static void test_blockjob_drain(void) |
43 | + awk </dev/null ' | 71 | test_blockjob_common(BDRV_DRAIN); |
44 | BEGIN { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \ | ||
45 | | while read id | ||
46 | do | ||
47 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/tests/qemu-iotests/common.config | ||
50 | +++ b/tests/qemu-iotests/common.config | ||
51 | @@ -XXX,XX +XXX,XX @@ _fatal() | ||
52 | exit 1 | ||
53 | } | 72 | } |
54 | 73 | ||
55 | -export AWK_PROG="`set_prog_path awk`" | 74 | +static void test_blockjob_drain_subtree(void) |
56 | -[ "$AWK_PROG" = "" ] && _fatal "awk not found" | 75 | +{ |
57 | - | 76 | + test_blockjob_common(BDRV_SUBTREE_DRAIN); |
58 | if [ -z "$QEMU_PROG" ]; then | 77 | +} |
59 | export QEMU_PROG="`set_prog_path qemu`" | 78 | + |
60 | fi | 79 | int main(int argc, char **argv) |
80 | { | ||
81 | bdrv_init(); | ||
82 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
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(); | ||
102 | } | ||
61 | -- | 103 | -- |
62 | 2.13.6 | 104 | 2.13.6 |
63 | 105 | ||
64 | 106 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 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 | Some functions in common.rc are never used by the tests. Move | ||
4 | them out of that file and into common, which is already included | ||
5 | only by "check". | ||
6 | |||
7 | Code that actually *is* common to "check" and tests can be placed in | ||
8 | common.config. | ||
9 | |||
10 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
13 | --- | 6 | --- |
14 | tests/qemu-iotests/common | 25 ++++++++++++++++++++++++- | 7 | tests/test-bdrv-drain.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ |
15 | tests/qemu-iotests/common.config | 12 ++++++++++++ | 8 | 1 file changed, 59 insertions(+) |
16 | tests/qemu-iotests/common.rc | 40 ---------------------------------------- | ||
17 | 3 files changed, 36 insertions(+), 41 deletions(-) | ||
18 | 9 | ||
19 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | 10 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
20 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/tests/qemu-iotests/common | 12 | --- a/tests/test-bdrv-drain.c |
22 | +++ b/tests/qemu-iotests/common | 13 | +++ b/tests/test-bdrv-drain.c |
23 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ static void aio_ret_cb(void *opaque, int ret) |
24 | # common procedures for QA scripts | 15 | *aio_ret = ret; |
25 | # | 16 | } |
26 | 17 | ||
27 | +_full_imgfmt_details() | 18 | +typedef struct CallInCoroutineData { |
19 | + void (*entry)(void); | ||
20 | + bool done; | ||
21 | +} CallInCoroutineData; | ||
22 | + | ||
23 | +static coroutine_fn void call_in_coroutine_entry(void *opaque) | ||
28 | +{ | 24 | +{ |
29 | + if [ -n "$IMGOPTS" ]; then | 25 | + CallInCoroutineData *data = opaque; |
30 | + echo "$IMGFMT ($IMGOPTS)" | 26 | + |
31 | + else | 27 | + data->entry(); |
32 | + echo "$IMGFMT" | 28 | + data->done = true; |
33 | + fi | ||
34 | +} | 29 | +} |
35 | + | 30 | + |
36 | +_full_platform_details() | 31 | +static void call_in_coroutine(void (*entry)(void)) |
37 | +{ | 32 | +{ |
38 | + os=`uname -s` | 33 | + Coroutine *co; |
39 | + host=`hostname -s` | 34 | + CallInCoroutineData data = { |
40 | + kernel=`uname -r` | 35 | + .entry = entry, |
41 | + platform=`uname -m` | 36 | + .done = false, |
42 | + echo "$os/$platform $host $kernel" | 37 | + }; |
38 | + | ||
39 | + co = qemu_coroutine_create(call_in_coroutine_entry, &data); | ||
40 | + qemu_coroutine_enter(co); | ||
41 | + while (!data.done) { | ||
42 | + aio_poll(qemu_get_aio_context(), true); | ||
43 | + } | ||
43 | +} | 44 | +} |
44 | + | 45 | + |
45 | diff="diff -u" | 46 | enum drain_type { |
46 | verbose=false | 47 | BDRV_DRAIN_ALL, |
47 | debug=false | 48 | BDRV_DRAIN, |
48 | @@ -XXX,XX +XXX,XX @@ if [ "$IMGOPTSSYNTAX" != "true" ]; then | 49 | @@ -XXX,XX +XXX,XX @@ static void test_drv_cb_drain_subtree(void) |
49 | fi | 50 | test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); |
50 | |||
51 | # Set default options for qemu-img create -o if they were not specified | ||
52 | -_set_default_imgopts | ||
53 | +if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then | ||
54 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1") | ||
55 | +fi | ||
56 | +if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then | ||
57 | + IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10") | ||
58 | +fi | ||
59 | |||
60 | if [ -s $tmp.list ] | ||
61 | then | ||
62 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/tests/qemu-iotests/common.config | ||
65 | +++ b/tests/qemu-iotests/common.config | ||
66 | @@ -XXX,XX +XXX,XX @@ export PWD=`pwd` | ||
67 | |||
68 | export _QEMU_HANDLE=0 | ||
69 | |||
70 | +# make sure we have a standard umask | ||
71 | +umask 022 | ||
72 | + | ||
73 | # $1 = prog to look for, $2* = default pathnames if not found in $PATH | ||
74 | set_prog_path() | ||
75 | { | ||
76 | @@ -XXX,XX +XXX,XX @@ set_prog_path() | ||
77 | return 1 | ||
78 | } | 51 | } |
79 | 52 | ||
80 | +_optstr_add() | 53 | +static void test_drv_cb_co_drain(void) |
81 | +{ | 54 | +{ |
82 | + if [ -n "$1" ]; then | 55 | + call_in_coroutine(test_drv_cb_drain); |
83 | + echo "$1,$2" | ||
84 | + else | ||
85 | + echo "$2" | ||
86 | + fi | ||
87 | +} | 56 | +} |
88 | + | 57 | + |
89 | _fatal() | 58 | +static void test_drv_cb_co_drain_subtree(void) |
59 | +{ | ||
60 | + call_in_coroutine(test_drv_cb_drain_subtree); | ||
61 | +} | ||
62 | + | ||
63 | static void test_quiesce_common(enum drain_type drain_type, bool recursive) | ||
90 | { | 64 | { |
91 | echo "$*" | 65 | BlockBackend *blk; |
92 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | 66 | @@ -XXX,XX +XXX,XX @@ static void test_quiesce_drain_subtree(void) |
93 | index XXXXXXX..XXXXXXX 100644 | 67 | test_quiesce_common(BDRV_SUBTREE_DRAIN, true); |
94 | --- a/tests/qemu-iotests/common.rc | 68 | } |
95 | +++ b/tests/qemu-iotests/common.rc | 69 | |
96 | @@ -XXX,XX +XXX,XX @@ then | 70 | +static void test_quiesce_co_drain(void) |
97 | fi | 71 | +{ |
98 | fi | 72 | + call_in_coroutine(test_quiesce_drain); |
99 | 73 | +} | |
100 | -# make sure we have a standard umask | 74 | + |
101 | -umask 022 | 75 | +static void test_quiesce_co_drain_subtree(void) |
102 | - | 76 | +{ |
103 | if [ "$IMGOPTSSYNTAX" = "true" ]; then | 77 | + call_in_coroutine(test_quiesce_drain_subtree); |
104 | DRIVER="driver=$IMGFMT" | 78 | +} |
105 | if [ "$IMGFMT" = "luks" ]; then | 79 | + |
106 | @@ -XXX,XX +XXX,XX @@ else | 80 | static void test_nested(void) |
107 | fi | ||
108 | ORIG_TEST_IMG="$TEST_IMG" | ||
109 | |||
110 | -_optstr_add() | ||
111 | -{ | ||
112 | - if [ -n "$1" ]; then | ||
113 | - echo "$1,$2" | ||
114 | - else | ||
115 | - echo "$2" | ||
116 | - fi | ||
117 | -} | ||
118 | - | ||
119 | -_set_default_imgopts() | ||
120 | -{ | ||
121 | - if [ "$IMGFMT" == "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat=" > /dev/null); then | ||
122 | - IMGOPTS=$(_optstr_add "$IMGOPTS" "compat=1.1") | ||
123 | - fi | ||
124 | - if [ "$IMGFMT" == "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time=" > /dev/null); then | ||
125 | - IMGOPTS=$(_optstr_add "$IMGOPTS" "iter-time=10") | ||
126 | - fi | ||
127 | -} | ||
128 | - | ||
129 | _use_sample_img() | ||
130 | { | 81 | { |
131 | SAMPLE_IMG_FILE="${1%\.bz2}" | 82 | BlockBackend *blk; |
132 | @@ -XXX,XX +XXX,XX @@ _require_command() | 83 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
133 | [ -x "$c" ] || _notrun "$1 utility required, skipped this test" | 84 | g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", |
134 | } | 85 | test_drv_cb_drain_subtree); |
135 | 86 | ||
136 | -_full_imgfmt_details() | 87 | + // XXX bdrv_drain_all() doesn't work in coroutine context |
137 | -{ | 88 | + g_test_add_func("/bdrv-drain/driver-cb/co/drain", test_drv_cb_co_drain); |
138 | - if [ -n "$IMGOPTS" ]; then | 89 | + g_test_add_func("/bdrv-drain/driver-cb/co/drain_subtree", |
139 | - echo "$IMGFMT ($IMGOPTS)" | 90 | + test_drv_cb_co_drain_subtree); |
140 | - else | 91 | + |
141 | - echo "$IMGFMT" | 92 | + |
142 | - fi | 93 | g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_all); |
143 | -} | 94 | g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); |
144 | - | 95 | g_test_add_func("/bdrv-drain/quiesce/drain_subtree", |
145 | -_full_platform_details() | 96 | test_quiesce_drain_subtree); |
146 | -{ | 97 | |
147 | - os=`uname -s` | 98 | + // XXX bdrv_drain_all() doesn't work in coroutine context |
148 | - host=`hostname -s` | 99 | + g_test_add_func("/bdrv-drain/quiesce/co/drain", test_quiesce_co_drain); |
149 | - kernel=`uname -r` | 100 | + g_test_add_func("/bdrv-drain/quiesce/co/drain_subtree", |
150 | - platform=`uname -m` | 101 | + test_quiesce_co_drain_subtree); |
151 | - echo "$os/$platform $host $kernel" | 102 | + |
152 | -} | 103 | g_test_add_func("/bdrv-drain/nested", test_nested); |
153 | - | 104 | |
154 | # make sure this script returns success | 105 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); |
155 | true | ||
156 | -- | 106 | -- |
157 | 2.13.6 | 107 | 2.13.6 |
158 | 108 | ||
159 | 109 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | 1 | Test that drain sections are correctly propagated through the graph. |
---|---|---|---|
2 | 2 | ||
3 | It only provides functions used by the test programs. | ||
4 | |||
5 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
7 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 3 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
8 | --- | 4 | --- |
9 | tests/qemu-iotests/check | 6 ------ | 5 | tests/test-bdrv-drain.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | tests/qemu-iotests/common.rc | 13 +++++-------- | 6 | 1 file changed, 74 insertions(+) |
11 | 2 files changed, 5 insertions(+), 14 deletions(-) | ||
12 | 7 | ||
13 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 8 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
14 | index XXXXXXX..XXXXXXX 100755 | ||
15 | --- a/tests/qemu-iotests/check | ||
16 | +++ b/tests/qemu-iotests/check | ||
17 | @@ -XXX,XX +XXX,XX @@ then | ||
18 | _init_error "failed to source common.config" | ||
19 | fi | ||
20 | |||
21 | -# we need common.rc | ||
22 | -if ! . "$source_iotests/common.rc" | ||
23 | -then | ||
24 | - _init_error "failed to source common.rc" | ||
25 | -fi | ||
26 | - | ||
27 | # we need common | ||
28 | . "$source_iotests/common" | ||
29 | |||
30 | diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc | ||
31 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/tests/qemu-iotests/common.rc | 10 | --- a/tests/test-bdrv-drain.c |
33 | +++ b/tests/qemu-iotests/common.rc | 11 | +++ b/tests/test-bdrv-drain.c |
34 | @@ -XXX,XX +XXX,XX @@ poke_file() | 12 | @@ -XXX,XX +XXX,XX @@ static void test_nested(void) |
35 | printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null | 13 | blk_unref(blk); |
36 | } | 14 | } |
37 | 15 | ||
38 | -# we need common.config | 16 | +static void test_multiparent(void) |
39 | -if [ "$iam" != "check" ] | 17 | +{ |
40 | -then | 18 | + BlockBackend *blk_a, *blk_b; |
41 | - if ! . ./common.config | 19 | + BlockDriverState *bs_a, *bs_b, *backing; |
42 | - then | 20 | + BDRVTestState *a_s, *b_s, *backing_s; |
43 | - echo "$iam: failed to source common.config" | ||
44 | - exit 1 | ||
45 | - fi | ||
46 | + | 21 | + |
47 | +if ! . ./common.config | 22 | + blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
48 | + then | 23 | + bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, |
49 | + echo "$iam: failed to source common.config" | 24 | + &error_abort); |
50 | + exit 1 | 25 | + a_s = bs_a->opaque; |
51 | fi | 26 | + blk_insert_bs(blk_a, bs_a, &error_abort); |
52 | 27 | + | |
53 | _qemu_wrapper() | 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); | ||
54 | -- | 100 | -- |
55 | 2.13.6 | 101 | 2.13.6 |
56 | 102 | ||
57 | 103 | diff view generated by jsdifflib |
1 | There is no good reason for bdrv_drop_intermediate() to know the active | 1 | We need to remember how many of the drain sections in which a node is |
---|---|---|---|
2 | layer above the subchain it is operating on - even more so, because | 2 | were recursive (i.e. subtree drain rather than node drain), so that they |
3 | the assumption that there is a single active layer above it is not | 3 | can be correctly applied when children are added or removed during the |
4 | generally true. | 4 | drained section. |
5 | 5 | ||
6 | In order to prepare removal of the active parameter, use a BdrvChildRole | 6 | With this change, it is safe to modify the graph even inside a |
7 | callback to update the backing file string in the overlay image instead | 7 | bdrv_subtree_drained_begin/end() section. |
8 | of directly calling bdrv_change_backing_file(). | ||
9 | 8 | ||
10 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
12 | --- | 10 | --- |
13 | include/block/block_int.h | 6 ++++++ | 11 | include/block/block.h | 2 -- |
14 | block.c | 33 ++++++++++++++++++++++++++++----- | 12 | include/block/block_int.h | 5 +++++ |
15 | 2 files changed, 34 insertions(+), 5 deletions(-) | 13 | block.c | 32 +++++++++++++++++++++++++++++--- |
16 | 14 | block/io.c | 28 ++++++++++++++++++++++++---- | |
15 | 4 files changed, 58 insertions(+), 9 deletions(-) | ||
16 | |||
17 | diff --git a/include/block/block.h b/include/block/block.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/block/block.h | ||
20 | +++ b/include/block/block.h | ||
21 | @@ -XXX,XX +XXX,XX @@ void bdrv_drained_begin(BlockDriverState *bs); | ||
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 | |||
17 | 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 |
18 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/block/block_int.h | 32 | --- a/include/block/block_int.h |
20 | +++ b/include/block/block_int.h | 33 | +++ b/include/block/block_int.h |
21 | @@ -XXX,XX +XXX,XX @@ struct BdrvChildRole { | 34 | @@ -XXX,XX +XXX,XX @@ struct BlockDriverState { |
22 | 35 | ||
23 | void (*attach)(BdrvChild *child); | 36 | /* Accessed with atomic ops. */ |
24 | void (*detach)(BdrvChild *child); | 37 | int quiesce_counter; |
25 | + | 38 | + int recursive_quiesce_counter; |
26 | + /* Notifies the parent that the filename of its child has changed (e.g. | 39 | + |
27 | + * because the direct child was removed from the backing chain), so that it | 40 | unsigned int write_gen; /* Current data generation */ |
28 | + * can update its reference. */ | 41 | |
29 | + int (*update_filename)(BdrvChild *child, BlockDriverState *new_base, | 42 | /* Protected by reqs_lock. */ |
30 | + const char *filename, Error **errp); | 43 | @@ -XXX,XX +XXX,XX @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, |
31 | }; | 44 | int64_t offset, unsigned int bytes, QEMUIOVector *qiov, |
32 | 45 | BdrvRequestFlags flags); | |
33 | extern const BdrvChildRole child_file; | 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); | ||
34 | diff --git a/block.c b/block.c | 53 | diff --git a/block.c b/block.c |
35 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/block.c | 55 | --- a/block.c |
37 | +++ b/block.c | 56 | +++ b/block.c |
38 | @@ -XXX,XX +XXX,XX @@ static void bdrv_backing_options(int *child_flags, QDict *child_options, | 57 | @@ -XXX,XX +XXX,XX @@ static void bdrv_child_cb_drained_end(BdrvChild *child) |
39 | *child_flags = flags; | 58 | bdrv_drained_end(bs); |
40 | } | 59 | } |
41 | 60 | ||
42 | +static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | 61 | +static void bdrv_child_cb_attach(BdrvChild *child) |
43 | + const char *filename, Error **errp) | 62 | +{ |
44 | +{ | 63 | + BlockDriverState *bs = child->opaque; |
45 | + BlockDriverState *parent = c->opaque; | 64 | + bdrv_apply_subtree_drain(child, bs); |
46 | + int ret; | 65 | +} |
47 | + | 66 | + |
48 | + ret = bdrv_change_backing_file(parent, filename, | 67 | +static void bdrv_child_cb_detach(BdrvChild *child) |
49 | + base->drv ? base->drv->format_name : ""); | 68 | +{ |
50 | + if (ret < 0) { | 69 | + BlockDriverState *bs = child->opaque; |
51 | + error_setg_errno(errp, ret, "Could not update backing file link"); | 70 | + bdrv_unapply_subtree_drain(child, bs); |
52 | + } | 71 | +} |
53 | + | 72 | + |
54 | + return ret; | 73 | static int bdrv_child_cb_inactivate(BdrvChild *child) |
55 | +} | 74 | { |
56 | + | 75 | BlockDriverState *bs = child->opaque; |
57 | const BdrvChildRole child_backing = { | 76 | @@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_file = { |
58 | .get_parent_desc = bdrv_child_get_parent_desc, | 77 | .inherit_options = bdrv_inherited_options, |
59 | .attach = bdrv_backing_attach, | ||
60 | @@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_backing = { | ||
61 | .drained_begin = bdrv_child_cb_drained_begin, | 78 | .drained_begin = bdrv_child_cb_drained_begin, |
62 | .drained_end = bdrv_child_cb_drained_end, | 79 | .drained_end = bdrv_child_cb_drained_end, |
80 | + .attach = bdrv_child_cb_attach, | ||
81 | + .detach = bdrv_child_cb_detach, | ||
63 | .inactivate = bdrv_child_cb_inactivate, | 82 | .inactivate = bdrv_child_cb_inactivate, |
64 | + .update_filename = bdrv_backing_update_filename, | ||
65 | }; | 83 | }; |
66 | 84 | ||
67 | static int bdrv_open_flags(BlockDriverState *bs, int flags) | 85 | @@ -XXX,XX +XXX,XX @@ const BdrvChildRole child_format = { |
68 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 86 | .inherit_options = bdrv_inherited_fmt_options, |
69 | Error *local_err = NULL; | 87 | .drained_begin = bdrv_child_cb_drained_begin, |
70 | int ret = -EIO; | 88 | .drained_end = bdrv_child_cb_drained_end, |
71 | 89 | + .attach = bdrv_child_cb_attach, | |
72 | + bdrv_ref(top); | 90 | + .detach = bdrv_child_cb_detach, |
73 | + | 91 | .inactivate = bdrv_child_cb_inactivate, |
74 | if (!top->drv || !base->drv) { | 92 | }; |
75 | goto exit; | 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)); | ||
76 | } | 114 | } |
77 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 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); | ||
78 | } | 131 | } |
79 | 132 | ||
80 | /* success - we can delete the intermediate states, and link top->base */ | 133 | @@ -XXX,XX +XXX,XX @@ static void bdrv_replace_child_noperm(BdrvChild *child, |
81 | - backing_file_str = backing_file_str ? backing_file_str : base->filename; | 134 | } |
82 | - ret = bdrv_change_backing_file(new_top_bs, backing_file_str, | 135 | } |
83 | - base->drv ? base->drv->format_name : ""); | 136 | |
84 | - if (ret) { | 137 | + /* Attach only after starting new drained sections, so that recursive |
85 | - goto exit; | 138 | + * drain sections coming from @child don't get an extra .drained_begin |
86 | + if (new_top_bs->backing->role->update_filename) { | 139 | + * callback. */ |
87 | + backing_file_str = backing_file_str ? backing_file_str : base->filename; | 140 | if (child->role->attach) { |
88 | + ret = new_top_bs->backing->role->update_filename(new_top_bs->backing, | 141 | child->role->attach(child); |
89 | + base, backing_file_str, | 142 | } |
90 | + &local_err); | 143 | diff --git a/block/io.c b/block/io.c |
91 | + if (ret < 0) { | 144 | index XXXXXXX..XXXXXXX 100644 |
92 | + bdrv_set_backing_hd(new_top_bs, top, &error_abort); | 145 | --- a/block/io.c |
93 | + goto exit; | 146 | +++ b/block/io.c |
94 | + } | 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, | ||
95 | } | 178 | } |
96 | 179 | ||
97 | bdrv_set_backing_hd(new_top_bs, base, &local_err); | 180 | if (recursive) { |
98 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 181 | + bs->recursive_quiesce_counter--; |
99 | 182 | QLIST_FOREACH_SAFE(child, &bs->children, next, next) { | |
100 | ret = 0; | 183 | bdrv_do_drained_end(child->bs, true, child); |
101 | exit: | 184 | } |
102 | + bdrv_unref(top); | 185 | @@ -XXX,XX +XXX,XX @@ void bdrv_subtree_drained_end(BlockDriverState *bs) |
103 | return ret; | 186 | bdrv_do_drained_end(bs, true, NULL); |
104 | } | 187 | } |
105 | 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. | ||
106 | -- | 210 | -- |
107 | 2.13.6 | 211 | 2.13.6 |
108 | 212 | ||
109 | 213 | diff view generated by jsdifflib |
1 | From: Paolo Bonzini <pbonzini@redhat.com> | ||
---|---|---|---|
2 | |||
3 | Instead of ./check failing when a binary is missing, we try each test | ||
4 | case now and each one fails with tons of test case diffs. Also, all the | ||
5 | variables were initialized by "check" prior to "common" being sourced, | ||
6 | and then (uselessly) checked for emptiness again in "check". | ||
7 | |||
8 | Centralize the search for programs in "common" (which will soon be | ||
9 | one with "check"), including the "realpath" invocation which can be done | ||
10 | just once in "check" rather than in the tests. | ||
11 | |||
12 | For qnio_server, move the detection to "common", simplifying | ||
13 | set_prog_path to stop handling the unused second argument, and | ||
14 | embedding the "realpath" pass. | ||
15 | |||
16 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
17 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 1 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
19 | --- | 2 | --- |
20 | tests/qemu-iotests/check | 41 --------------------- | 3 | tests/test-bdrv-drain.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ |
21 | tests/qemu-iotests/common | 77 +++++++++++++++++++++++++++++++++++++--- | 4 | 1 file changed, 80 insertions(+) |
22 | tests/qemu-iotests/common.config | 61 +------------------------------ | ||
23 | 3 files changed, 73 insertions(+), 106 deletions(-) | ||
24 | 5 | ||
25 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | 6 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c |
26 | index XXXXXXX..XXXXXXX 100755 | ||
27 | --- a/tests/qemu-iotests/check | ||
28 | +++ b/tests/qemu-iotests/check | ||
29 | @@ -XXX,XX +XXX,XX @@ fi | ||
30 | |||
31 | build_root="$build_iotests/../.." | ||
32 | |||
33 | -if [ -x "$build_iotests/socket_scm_helper" ] | ||
34 | -then | ||
35 | - export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | ||
36 | -fi | ||
37 | - | ||
38 | -if [[ -z "$QEMU_PROG" && ! -x './qemu' ]] | ||
39 | -then | ||
40 | - arch=$(uname -m 2> /dev/null) | ||
41 | - | ||
42 | - if [[ -n $arch && -x "$build_root/$arch-softmmu/qemu-system-$arch" ]] | ||
43 | - then | ||
44 | - export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch" | ||
45 | - else | ||
46 | - pushd "$build_root" > /dev/null | ||
47 | - for binary in *-softmmu/qemu-system-* | ||
48 | - do | ||
49 | - if [ -x "$binary" ] | ||
50 | - then | ||
51 | - export QEMU_PROG="$build_root/$binary" | ||
52 | - break | ||
53 | - fi | ||
54 | - done | ||
55 | - popd > /dev/null | ||
56 | - fi | ||
57 | -fi | ||
58 | - | ||
59 | -if [[ -z $QEMU_IMG_PROG && -x "$build_root/qemu-img" && ! -x './qemu-img' ]] | ||
60 | -then | ||
61 | - export QEMU_IMG_PROG="$build_root/qemu-img" | ||
62 | -fi | ||
63 | - | ||
64 | -if [[ -z $QEMU_IO_PROG && -x "$build_root/qemu-io" && ! -x './qemu-io' ]] | ||
65 | -then | ||
66 | - export QEMU_IO_PROG="$build_root/qemu-io" | ||
67 | -fi | ||
68 | - | ||
69 | -if [[ -z $QEMU_NBD_PROG && -x "$build_root/qemu-nbd" && ! -x './qemu-nbd' ]] | ||
70 | -then | ||
71 | - export QEMU_NBD_PROG="$build_root/qemu-nbd" | ||
72 | -fi | ||
73 | - | ||
74 | # we need common.env | ||
75 | if ! . "$build_iotests/common.env" | ||
76 | then | ||
77 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | ||
78 | index XXXXXXX..XXXXXXX 100644 | 7 | index XXXXXXX..XXXXXXX 100644 |
79 | --- a/tests/qemu-iotests/common | 8 | --- a/tests/test-bdrv-drain.c |
80 | +++ b/tests/qemu-iotests/common | 9 | +++ b/tests/test-bdrv-drain.c |
81 | @@ -XXX,XX +XXX,XX @@ _full_platform_details() | 10 | @@ -XXX,XX +XXX,XX @@ static void test_multiparent(void) |
82 | echo "$os/$platform $host $kernel" | 11 | blk_unref(blk_b); |
83 | } | 12 | } |
84 | 13 | ||
85 | +# $1 = prog to look for | 14 | +static void test_graph_change(void) |
86 | +set_prog_path() | ||
87 | +{ | 15 | +{ |
88 | + p=`command -v $1 2> /dev/null` | 16 | + BlockBackend *blk_a, *blk_b; |
89 | + if [ -n "$p" -a -x "$p" ]; then | 17 | + BlockDriverState *bs_a, *bs_b, *backing; |
90 | + realpath -- "$(type -p "$p")" | 18 | + BDRVTestState *a_s, *b_s, *backing_s; |
91 | + else | 19 | + |
92 | + return 1 | 20 | + blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); |
93 | + fi | 21 | + bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, |
22 | + &error_abort); | ||
23 | + a_s = bs_a->opaque; | ||
24 | + blk_insert_bs(blk_a, bs_a, &error_abort); | ||
25 | + | ||
26 | + blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL); | ||
27 | + bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, | ||
28 | + &error_abort); | ||
29 | + b_s = bs_b->opaque; | ||
30 | + blk_insert_bs(blk_b, bs_b, &error_abort); | ||
31 | + | ||
32 | + backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort); | ||
33 | + backing_s = backing->opaque; | ||
34 | + bdrv_set_backing_hd(bs_a, backing, &error_abort); | ||
35 | + | ||
36 | + g_assert_cmpint(bs_a->quiesce_counter, ==, 0); | ||
37 | + g_assert_cmpint(bs_b->quiesce_counter, ==, 0); | ||
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); | ||
94 | +} | 91 | +} |
95 | + | 92 | + |
96 | diff="diff -u" | 93 | |
97 | verbose=false | 94 | typedef struct TestBlockJob { |
98 | debug=false | 95 | BlockJob common; |
99 | @@ -XXX,XX +XXX,XX @@ fi | 96 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) |
100 | list=`sort $tmp.list` | 97 | |
101 | rm -f $tmp.list $tmp.tmp $tmp.sed | 98 | g_test_add_func("/bdrv-drain/nested", test_nested); |
102 | 99 | g_test_add_func("/bdrv-drain/multiparent", test_multiparent); | |
103 | -[ "$QEMU" = "" ] && _fatal "qemu not found" | 100 | + g_test_add_func("/bdrv-drain/graph-change", test_graph_change); |
104 | -[ "$QEMU_IMG" = "" ] && _fatal "qemu-img not found" | 101 | |
105 | -[ "$QEMU_IO" = "" ] && _fatal "qemu-io not found" | 102 | g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_all); |
106 | +if [ -z "$QEMU_PROG" ] | 103 | g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); |
107 | +then | ||
108 | + if [ -x "$build_iotests/qemu" ]; then | ||
109 | + export QEMU_PROG="$build_iotests/qemu" | ||
110 | + elif [ -x "$build_root/$arch-softmmu/qemu-system-$arch" ]; then | ||
111 | + export QEMU_PROG="$build_root/$arch-softmmu/qemu-system-$arch" | ||
112 | + else | ||
113 | + pushd "$build_root" > /dev/null | ||
114 | + for binary in *-softmmu/qemu-system-* | ||
115 | + do | ||
116 | + if [ -x "$binary" ] | ||
117 | + then | ||
118 | + export QEMU_PROG="$build_root/$binary" | ||
119 | + break | ||
120 | + fi | ||
121 | + done | ||
122 | + popd > /dev/null | ||
123 | + [ "$QEMU_PROG" = "" ] && _init_error "qemu not found" | ||
124 | + fi | ||
125 | +fi | ||
126 | +export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")") | ||
127 | + | ||
128 | +if [ -z "$QEMU_IMG_PROG" ]; then | ||
129 | + if [ -x "$build_iotests/qemu-img" ]; then | ||
130 | + export QEMU_IMG_PROG="$build_iotests/qemu-img" | ||
131 | + elif [ -x "$build_root/qemu-img" ]; then | ||
132 | + export QEMU_IMG_PROG="$build_root/qemu-img" | ||
133 | + else | ||
134 | + _init_error "qemu-img not found" | ||
135 | + fi | ||
136 | +fi | ||
137 | +export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")") | ||
138 | + | ||
139 | +if [ -z "$QEMU_IO_PROG" ]; then | ||
140 | + if [ -x "$build_iotests/qemu-io" ]; then | ||
141 | + export QEMU_IO_PROG="$build_iotests/qemu-io" | ||
142 | + elif [ -x "$build_root/qemu-io" ]; then | ||
143 | + export QEMU_IO_PROG="$build_root/qemu-io" | ||
144 | + else | ||
145 | + _init_error "qemu-io not found" | ||
146 | + fi | ||
147 | +fi | ||
148 | +export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")") | ||
149 | |||
150 | -if [ "$IMGPROTO" = "nbd" ] ; then | ||
151 | - [ "$QEMU_NBD" = "" ] && _fatal "qemu-nbd not found" | ||
152 | +if [ -z $QEMU_NBD_PROG ]; then | ||
153 | + if [ -x "$build_iotests/qemu-nbd" ]; then | ||
154 | + export QEMU_NBD_PROG="$build_iotests/qemu-nbd" | ||
155 | + elif [ -x "$build_root/qemu-nbd" ]; then | ||
156 | + export QEMU_NBD_PROG="$build_root/qemu-nbd" | ||
157 | + else | ||
158 | + _init_error "qemu-nbd not found" | ||
159 | + fi | ||
160 | +fi | ||
161 | +export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")") | ||
162 | + | ||
163 | +if [ -z "$QEMU_VXHS_PROG" ]; then | ||
164 | + export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | ||
165 | +fi | ||
166 | + | ||
167 | +if [ -x "$build_iotests/socket_scm_helper" ] | ||
168 | +then | ||
169 | + export SOCKET_SCM_HELPER="$build_iotests/socket_scm_helper" | ||
170 | fi | ||
171 | diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/tests/qemu-iotests/common.config | ||
174 | +++ b/tests/qemu-iotests/common.config | ||
175 | @@ -XXX,XX +XXX,XX @@ export LANG=C | ||
176 | PATH=".:$PATH" | ||
177 | |||
178 | HOSTOS=`uname -s` | ||
179 | +arch=`uname -m` | ||
180 | |||
181 | export PWD=`pwd` | ||
182 | |||
183 | @@ -XXX,XX +XXX,XX @@ export _QEMU_HANDLE=0 | ||
184 | # make sure we have a standard umask | ||
185 | umask 022 | ||
186 | |||
187 | -# $1 = prog to look for, $2* = default pathnames if not found in $PATH | ||
188 | -set_prog_path() | ||
189 | -{ | ||
190 | - p=`command -v $1 2> /dev/null` | ||
191 | - if [ -n "$p" -a -x "$p" ]; then | ||
192 | - echo $p | ||
193 | - return 0 | ||
194 | - fi | ||
195 | - p=$1 | ||
196 | - | ||
197 | - shift | ||
198 | - for f; do | ||
199 | - if [ -x $f ]; then | ||
200 | - echo $f | ||
201 | - return 0 | ||
202 | - fi | ||
203 | - done | ||
204 | - | ||
205 | - echo "" | ||
206 | - return 1 | ||
207 | -} | ||
208 | - | ||
209 | _optstr_add() | ||
210 | { | ||
211 | if [ -n "$1" ]; then | ||
212 | @@ -XXX,XX +XXX,XX @@ _optstr_add() | ||
213 | fi | ||
214 | } | ||
215 | |||
216 | -_fatal() | ||
217 | -{ | ||
218 | - echo "$*" | ||
219 | - status=1 | ||
220 | - exit 1 | ||
221 | -} | ||
222 | - | ||
223 | -if [ -z "$QEMU_PROG" ]; then | ||
224 | - export QEMU_PROG="`set_prog_path qemu`" | ||
225 | -fi | ||
226 | - | ||
227 | -if [ -z "$QEMU_IMG_PROG" ]; then | ||
228 | - export QEMU_IMG_PROG="`set_prog_path qemu-img`" | ||
229 | -fi | ||
230 | - | ||
231 | -if [ -z "$QEMU_IO_PROG" ]; then | ||
232 | - export QEMU_IO_PROG="`set_prog_path qemu-io`" | ||
233 | -fi | ||
234 | - | ||
235 | -if [ -z "$QEMU_NBD_PROG" ]; then | ||
236 | - export QEMU_NBD_PROG="`set_prog_path qemu-nbd`" | ||
237 | -fi | ||
238 | - | ||
239 | -if [ -z "$QEMU_VXHS_PROG" ]; then | ||
240 | - export QEMU_VXHS_PROG="`set_prog_path qnio_server`" | ||
241 | -fi | ||
242 | - | ||
243 | -export QEMU_PROG=$(realpath -- "$(type -p "$QEMU_PROG")") | ||
244 | -export QEMU_IMG_PROG=$(realpath -- "$(type -p "$QEMU_IMG_PROG")") | ||
245 | -export QEMU_IO_PROG=$(realpath -- "$(type -p "$QEMU_IO_PROG")") | ||
246 | -export QEMU_NBD_PROG=$(realpath -- "$(type -p "$QEMU_NBD_PROG")") | ||
247 | - | ||
248 | -# This program is not built as part of qemu but (possibly) provided by the | ||
249 | -# system, so it may not be present at all | ||
250 | -if [ -n "$QEMU_VXHS_PROG" ]; then | ||
251 | - export QEMU_VXHS_PROG=$(realpath -- "$(type -p "$QEMU_VXHS_PROG")") | ||
252 | -fi | ||
253 | - | ||
254 | _qemu_wrapper() | ||
255 | { | ||
256 | ( | ||
257 | -- | 104 | -- |
258 | 2.13.6 | 105 | 2.13.6 |
259 | 106 | ||
260 | 107 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Paolo Bonzini <pbonzini@redhat.com> | ||
2 | 1 | ||
3 | The variable is used in "common" but defined only after the file | ||
4 | is sourced. | ||
5 | |||
6 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/check | 2 -- | ||
11 | tests/qemu-iotests/common | 2 ++ | ||
12 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
13 | |||
14 | diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check | ||
15 | index XXXXXXX..XXXXXXX 100755 | ||
16 | --- a/tests/qemu-iotests/check | ||
17 | +++ b/tests/qemu-iotests/check | ||
18 | @@ -XXX,XX +XXX,XX @@ fi | ||
19 | |||
20 | TIMESTAMP_FILE=check.time-$IMGPROTO-$IMGFMT | ||
21 | |||
22 | -tmp="${TEST_DIR}"/$$ | ||
23 | - | ||
24 | _wallclock() | ||
25 | { | ||
26 | date "+%H %M %S" | awk '{ print $1*3600 + $2*60 + $3 }' | ||
27 | diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/tests/qemu-iotests/common | ||
30 | +++ b/tests/qemu-iotests/common | ||
31 | @@ -XXX,XX +XXX,XX @@ sortme=false | ||
32 | expunge=true | ||
33 | have_test_arg=false | ||
34 | cachemode=false | ||
35 | + | ||
36 | +tmp="${TEST_DIR}"/$$ | ||
37 | rm -f $tmp.list $tmp.tmp $tmp.sed | ||
38 | |||
39 | export IMGFMT=raw | ||
40 | -- | ||
41 | 2.13.6 | ||
42 | |||
43 | diff view generated by jsdifflib |
1 | QMP responses to certain commands can become quite long, which doesn't | 1 | Since commit bde70715, base is the only node that is reopened in |
---|---|---|---|
2 | only make reading them hard, but also means that the maximum line length | 2 | commit_start(). This means that the code, which still involves an |
3 | in patch emails can be exceeded. Allow tests to switch to QMP pretty | 3 | explicit BlockReopenQueue, can now be simplified by using bdrv_reopen(). |
4 | printing, which results in more, but shorter lines. | ||
5 | |||
6 | We also need to make sure to keep indentation in the response for this | ||
7 | to work as expected. | ||
8 | 4 | ||
9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 5 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | Reviewed-by: Eric Blake <eblake@redhat.com> | 6 | Reviewed-by: Fam Zheng <famz@redhat.com> |
11 | --- | 7 | --- |
12 | tests/qemu-iotests/common.qemu | 14 +++++++++++--- | 8 | block/commit.c | 8 +------- |
13 | 1 file changed, 11 insertions(+), 3 deletions(-) | 9 | 1 file changed, 1 insertion(+), 7 deletions(-) |
14 | 10 | ||
15 | diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu | 11 | diff --git a/block/commit.c b/block/commit.c |
16 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tests/qemu-iotests/common.qemu | 13 | --- a/block/commit.c |
18 | +++ b/tests/qemu-iotests/common.qemu | 14 | +++ b/block/commit.c |
19 | @@ -XXX,XX +XXX,XX @@ function _timed_wait_for() | 15 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, |
20 | shift | 16 | const char *filter_node_name, Error **errp) |
21 | 17 | { | |
22 | QEMU_STATUS[$h]=0 | 18 | CommitBlockJob *s; |
23 | - while read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]} | 19 | - BlockReopenQueue *reopen_queue = NULL; |
24 | + while IFS= read -t ${QEMU_COMM_TIMEOUT} resp <&${QEMU_OUT[$h]} | 20 | int orig_base_flags; |
25 | do | 21 | BlockDriverState *iter; |
26 | if [ -z "${silent}" ]; then | 22 | BlockDriverState *commit_top_bs = NULL; |
27 | echo "${resp}" | _filter_testdir | _filter_qemu \ | 23 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, |
28 | | _filter_qemu_io | _filter_qmp | _filter_hmp | 24 | /* convert base to r/w, if necessary */ |
29 | fi | 25 | orig_base_flags = bdrv_get_flags(base); |
30 | - grep -q "${*}" < <(echo ${resp}) | 26 | if (!(orig_base_flags & BDRV_O_RDWR)) { |
31 | + grep -q "${*}" < <(echo "${resp}") | 27 | - reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL, |
32 | if [ $? -eq 0 ]; then | 28 | - orig_base_flags | BDRV_O_RDWR); |
33 | return | 29 | - } |
34 | fi | 30 | - |
35 | @@ -XXX,XX +XXX,XX @@ function _send_qemu_cmd() | 31 | - if (reopen_queue) { |
36 | # $qemu_comm_method: set this variable to 'monitor' (case insensitive) | 32 | - bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &local_err); |
37 | # to use the QEMU HMP monitor for communication. | 33 | + bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err); |
38 | # Otherwise, the default of QMP is used. | 34 | if (local_err != NULL) { |
39 | +# $qmp_pretty: Set this variable to 'y' to enable QMP pretty printing. | 35 | error_propagate(errp, local_err); |
40 | # $keep_stderr: Set this variable to 'y' to keep QEMU's stderr output on stderr. | 36 | goto fail; |
41 | # If this variable is empty, stderr will be redirected to stdout. | ||
42 | # Returns: | ||
43 | @@ -XXX,XX +XXX,XX @@ function _launch_qemu() | ||
44 | comm="-monitor stdio" | ||
45 | else | ||
46 | local qemu_comm_method="qmp" | ||
47 | - comm="-monitor none -qmp stdio" | ||
48 | + if [ "$qmp_pretty" = "y" ]; then | ||
49 | + comm="-monitor none -qmp-pretty stdio" | ||
50 | + else | ||
51 | + comm="-monitor none -qmp stdio" | ||
52 | + fi | ||
53 | fi | ||
54 | |||
55 | fifo_out=${QEMU_FIFO_OUT}_${_QEMU_HANDLE} | ||
56 | @@ -XXX,XX +XXX,XX @@ function _launch_qemu() | ||
57 | then | ||
58 | # Don't print response, since it has version information in it | ||
59 | silent=yes _timed_wait_for ${_QEMU_HANDLE} "capabilities" | ||
60 | + if [ "$qmp_pretty" = "y" ]; then | ||
61 | + silent=yes _timed_wait_for ${_QEMU_HANDLE} "^}" | ||
62 | + fi | ||
63 | fi | ||
64 | QEMU_HANDLE=${_QEMU_HANDLE} | ||
65 | let _QEMU_HANDLE++ | ||
66 | -- | 37 | -- |
67 | 2.13.6 | 38 | 2.13.6 |
68 | 39 | ||
69 | 40 | diff view generated by jsdifflib |
1 | This changes the commit block job to support operation in a graph where | 1 | The bdrv_reopen*() implementation doesn't like it if the graph is |
---|---|---|---|
2 | there is more than a single active layer that references the top node. | 2 | changed between queuing nodes for reopen and actually reopening them |
3 | (one of the reasons is that queuing can be recursive). | ||
3 | 4 | ||
4 | This involves inserting the commit filter node not only on the path | 5 | So instead of draining the device only in bdrv_reopen_multiple(), |
5 | between the given active node and the top node, but between the top node | 6 | require that callers already drained all affected nodes, and assert this |
6 | and all of its parents. | 7 | in bdrv_reopen_queue(). |
7 | |||
8 | On completion, bdrv_drop_intermediate() must consider all parents for | ||
9 | updating the backing file link. These parents may be backing files | ||
10 | themselves and as such read-only; reopen them temporarily if necessary. | ||
11 | Previously this was achieved by the bdrv_reopen() calls in the commit | ||
12 | block job that made overlay_bs read-write for the whole duration of the | ||
13 | block job, even though write access is only needed on completion. | ||
14 | |||
15 | Now that we consider all parents, overlay_bs is meaningless. It is left | ||
16 | in place in this commit, but we'll remove it soon. | ||
17 | 8 | ||
18 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | 9 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> |
10 | Reviewed-by: Fam Zheng <famz@redhat.com> | ||
19 | --- | 11 | --- |
20 | block.c | 68 ++++++++++++++++++++++++++++++++++------------------------ | 12 | block.c | 23 ++++++++++++++++------- |
21 | block/commit.c | 2 +- | 13 | block/replication.c | 6 ++++++ |
22 | 2 files changed, 41 insertions(+), 29 deletions(-) | 14 | qemu-io-cmds.c | 3 +++ |
15 | 3 files changed, 25 insertions(+), 7 deletions(-) | ||
23 | 16 | ||
24 | diff --git a/block.c b/block.c | 17 | diff --git a/block.c b/block.c |
25 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/block.c | 19 | --- a/block.c |
27 | +++ b/block.c | 20 | +++ b/block.c |
28 | @@ -XXX,XX +XXX,XX @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, | 21 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, |
29 | const char *filename, Error **errp) | 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) | ||
30 | { | 49 | { |
31 | BlockDriverState *parent = c->opaque; | 50 | @@ -XXX,XX +XXX,XX @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **er |
32 | + int orig_flags = bdrv_get_flags(parent); | 51 | |
33 | int ret; | 52 | assert(bs_queue != NULL); |
34 | 53 | ||
35 | + if (!(orig_flags & BDRV_O_RDWR)) { | 54 | - aio_context_release(ctx); |
36 | + ret = bdrv_reopen(parent, orig_flags | BDRV_O_RDWR, errp); | 55 | - bdrv_drain_all_begin(); |
37 | + if (ret < 0) { | 56 | - aio_context_acquire(ctx); |
38 | + return ret; | 57 | - |
39 | + } | 58 | QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { |
40 | + } | 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); | ||
41 | + | 80 | + |
42 | ret = bdrv_change_backing_file(parent, filename, | 81 | + queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); |
43 | base->drv ? base->drv->format_name : ""); | 82 | ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_err); |
44 | if (ret < 0) { | 83 | if (local_err != NULL) { |
45 | error_setg_errno(errp, ret, "Could not update backing file link"); | 84 | error_propagate(errp, local_err); |
46 | } | 85 | } |
47 | 86 | + | |
48 | + if (!(orig_flags & BDRV_O_RDWR)) { | 87 | + bdrv_subtree_drained_end(bs); |
49 | + bdrv_reopen(parent, orig_flags, NULL); | ||
50 | + } | ||
51 | + | 88 | + |
52 | return ret; | 89 | return ret; |
53 | } | 90 | } |
54 | 91 | ||
55 | @@ -XXX,XX +XXX,XX @@ BlockDriverState *bdrv_find_base(BlockDriverState *bs) | 92 | diff --git a/block/replication.c b/block/replication.c |
56 | int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | 93 | index XXXXXXX..XXXXXXX 100644 |
57 | BlockDriverState *base, const char *backing_file_str) | 94 | --- a/block/replication.c |
58 | { | 95 | +++ b/block/replication.c |
59 | - BlockDriverState *new_top_bs = NULL; | 96 | @@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, |
60 | + BdrvChild *c, *next; | 97 | new_secondary_flags = s->orig_secondary_flags; |
61 | Error *local_err = NULL; | ||
62 | int ret = -EIO; | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top, | ||
65 | goto exit; | ||
66 | } | 98 | } |
67 | 99 | ||
68 | - new_top_bs = bdrv_find_overlay(active, top); | 100 | + bdrv_subtree_drained_begin(s->hidden_disk->bs); |
69 | - | 101 | + bdrv_subtree_drained_begin(s->secondary_disk->bs); |
70 | - if (new_top_bs == NULL) { | 102 | + |
71 | - /* we could not find the image above 'top', this is an error */ | 103 | if (orig_hidden_flags != new_hidden_flags) { |
72 | - goto exit; | 104 | reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL, |
73 | - } | 105 | new_hidden_flags); |
74 | - | 106 | @@ -XXX,XX +XXX,XX @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, |
75 | - /* special case of new_top_bs->backing->bs already pointing to base - nothing | 107 | reopen_queue, &local_err); |
76 | - * to do, no intermediate images */ | 108 | error_propagate(errp, local_err); |
77 | - if (backing_bs(new_top_bs) == base) { | ||
78 | - ret = 0; | ||
79 | - goto exit; | ||
80 | - } | ||
81 | - | ||
82 | /* Make sure that base is in the backing chain of top */ | ||
83 | if (!bdrv_chain_contains(top, base)) { | ||
84 | goto exit; | ||
85 | } | 109 | } |
86 | |||
87 | /* success - we can delete the intermediate states, and link top->base */ | ||
88 | - if (new_top_bs->backing->role->update_filename) { | ||
89 | - backing_file_str = backing_file_str ? backing_file_str : base->filename; | ||
90 | - ret = new_top_bs->backing->role->update_filename(new_top_bs->backing, | ||
91 | - base, backing_file_str, | ||
92 | - &local_err); | ||
93 | - if (ret < 0) { | ||
94 | - bdrv_set_backing_hd(new_top_bs, top, &error_abort); | ||
95 | + backing_file_str = backing_file_str ? backing_file_str : base->filename; | ||
96 | + | 110 | + |
97 | + QLIST_FOREACH_SAFE(c, &top->parents, next_parent, next) { | 111 | + bdrv_subtree_drained_end(s->hidden_disk->bs); |
98 | + /* Check whether we are allowed to switch c from top to base */ | 112 | + bdrv_subtree_drained_end(s->secondary_disk->bs); |
99 | + GSList *ignore_children = g_slist_prepend(NULL, c); | 113 | } |
100 | + bdrv_check_update_perm(base, NULL, c->perm, c->shared_perm, | 114 | |
101 | + ignore_children, &local_err); | 115 | static void backup_job_cleanup(BlockDriverState *bs) |
102 | + if (local_err) { | 116 | diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c |
103 | + ret = -EPERM; | 117 | index XXXXXXX..XXXXXXX 100644 |
104 | + error_report_err(local_err); | 118 | --- a/qemu-io-cmds.c |
105 | goto exit; | 119 | +++ b/qemu-io-cmds.c |
106 | } | 120 | @@ -XXX,XX +XXX,XX @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) |
107 | - } | 121 | opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; |
108 | + g_slist_free(ignore_children); | 122 | qemu_opts_reset(&reopen_opts); |
109 | 123 | ||
110 | - bdrv_set_backing_hd(new_top_bs, base, &local_err); | 124 | + bdrv_subtree_drained_begin(bs); |
111 | - if (local_err) { | 125 | brq = bdrv_reopen_queue(NULL, bs, opts, flags); |
112 | - ret = -EPERM; | 126 | bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); |
113 | - error_report_err(local_err); | 127 | + bdrv_subtree_drained_end(bs); |
114 | - goto exit; | ||
115 | + /* If so, update the backing file path in the image file */ | ||
116 | + if (c->role->update_filename) { | ||
117 | + ret = c->role->update_filename(c, base, backing_file_str, | ||
118 | + &local_err); | ||
119 | + if (ret < 0) { | ||
120 | + bdrv_abort_perm_update(base); | ||
121 | + error_report_err(local_err); | ||
122 | + goto exit; | ||
123 | + } | ||
124 | + } | ||
125 | + | 128 | + |
126 | + /* Do the actual switch in the in-memory graph. | ||
127 | + * Completes bdrv_check_update_perm() transaction internally. */ | ||
128 | + bdrv_ref(base); | ||
129 | + bdrv_replace_child(c, base); | ||
130 | + bdrv_unref(top); | ||
131 | } | ||
132 | |||
133 | ret = 0; | ||
134 | diff --git a/block/commit.c b/block/commit.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/block/commit.c | ||
137 | +++ b/block/commit.c | ||
138 | @@ -XXX,XX +XXX,XX @@ void commit_start(const char *job_id, BlockDriverState *bs, | ||
139 | error_propagate(errp, local_err); | ||
140 | goto fail; | ||
141 | } | ||
142 | - bdrv_set_backing_hd(overlay_bs, commit_top_bs, &local_err); | ||
143 | + bdrv_replace_node(top, commit_top_bs, &local_err); | ||
144 | if (local_err) { | 129 | if (local_err) { |
145 | bdrv_unref(commit_top_bs); | 130 | error_report_err(local_err); |
146 | commit_top_bs = NULL; | 131 | } else { |
147 | -- | 132 | -- |
148 | 2.13.6 | 133 | 2.13.6 |
149 | 134 | ||
150 | 135 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | ||
2 | 1 | ||
3 | Using 16KB bounce buffers creates a significant performance | ||
4 | penalty for I/O to encrypted volumes on storage which high | ||
5 | I/O latency (rotating rust & network drives), because it | ||
6 | triggers lots of fairly small I/O operations. | ||
7 | |||
8 | On tests with rotating rust, and cache=none|directsync, | ||
9 | write speed increased from 2MiB/s to 32MiB/s, on a par | ||
10 | with that achieved by the in-kernel luks driver. With | ||
11 | other cache modes the in-kernel driver is still notably | ||
12 | faster because it is able to report completion of the | ||
13 | I/O request before any encryption is done, while the | ||
14 | in-QEMU driver must encrypt the data before completion. | ||
15 | |||
16 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
17 | Message-id: 20170927125340.12360-2-berrange@redhat.com | ||
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
19 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
20 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
21 | --- | ||
22 | block/crypto.c | 28 +++++++++++++++------------- | ||
23 | 1 file changed, 15 insertions(+), 13 deletions(-) | ||
24 | |||
25 | diff --git a/block/crypto.c b/block/crypto.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/block/crypto.c | ||
28 | +++ b/block/crypto.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static void block_crypto_close(BlockDriverState *bs) | ||
30 | } | ||
31 | |||
32 | |||
33 | -#define BLOCK_CRYPTO_MAX_SECTORS 32 | ||
34 | +/* | ||
35 | + * 1 MB bounce buffer gives good performance / memory tradeoff | ||
36 | + * when using cache=none|directsync. | ||
37 | + */ | ||
38 | +#define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) | ||
39 | |||
40 | static coroutine_fn int | ||
41 | block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
42 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
43 | |||
44 | qemu_iovec_init(&hd_qiov, qiov->niov); | ||
45 | |||
46 | - /* Bounce buffer so we have a linear mem region for | ||
47 | - * entire sector. XXX optimize so we avoid bounce | ||
48 | - * buffer in case that qiov->niov == 1 | ||
49 | + /* Bounce buffer because we don't wish to expose cipher text | ||
50 | + * in qiov which points to guest memory. | ||
51 | */ | ||
52 | cipher_data = | ||
53 | - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_SECTORS * 512, | ||
54 | + qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, | ||
55 | qiov->size)); | ||
56 | if (cipher_data == NULL) { | ||
57 | ret = -ENOMEM; | ||
58 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
59 | while (remaining_sectors) { | ||
60 | cur_nr_sectors = remaining_sectors; | ||
61 | |||
62 | - if (cur_nr_sectors > BLOCK_CRYPTO_MAX_SECTORS) { | ||
63 | - cur_nr_sectors = BLOCK_CRYPTO_MAX_SECTORS; | ||
64 | + if (cur_nr_sectors > (BLOCK_CRYPTO_MAX_IO_SIZE / 512)) { | ||
65 | + cur_nr_sectors = (BLOCK_CRYPTO_MAX_IO_SIZE / 512); | ||
66 | } | ||
67 | |||
68 | qemu_iovec_reset(&hd_qiov); | ||
69 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
70 | |||
71 | qemu_iovec_init(&hd_qiov, qiov->niov); | ||
72 | |||
73 | - /* Bounce buffer so we have a linear mem region for | ||
74 | - * entire sector. XXX optimize so we avoid bounce | ||
75 | - * buffer in case that qiov->niov == 1 | ||
76 | + /* Bounce buffer because we're not permitted to touch | ||
77 | + * contents of qiov - it points to guest memory. | ||
78 | */ | ||
79 | cipher_data = | ||
80 | - qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_SECTORS * 512, | ||
81 | + qemu_try_blockalign(bs->file->bs, MIN(BLOCK_CRYPTO_MAX_IO_SIZE, | ||
82 | qiov->size)); | ||
83 | if (cipher_data == NULL) { | ||
84 | ret = -ENOMEM; | ||
85 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
86 | while (remaining_sectors) { | ||
87 | cur_nr_sectors = remaining_sectors; | ||
88 | |||
89 | - if (cur_nr_sectors > BLOCK_CRYPTO_MAX_SECTORS) { | ||
90 | - cur_nr_sectors = BLOCK_CRYPTO_MAX_SECTORS; | ||
91 | + if (cur_nr_sectors > (BLOCK_CRYPTO_MAX_IO_SIZE / 512)) { | ||
92 | + cur_nr_sectors = (BLOCK_CRYPTO_MAX_IO_SIZE / 512); | ||
93 | } | ||
94 | |||
95 | qemu_iovec_to_buf(qiov, bytes_done, | ||
96 | -- | ||
97 | 2.13.6 | ||
98 | |||
99 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | ||
2 | 1 | ||
3 | The crypto APIs report the offset of the data payload as an uint64_t | ||
4 | type, but the block driver is casting to size_t or ssize_t which will | ||
5 | potentially truncate. | ||
6 | |||
7 | Most of the block APIs use int64_t for offsets meanwhile, so even if | ||
8 | using uint64_t in the crypto block driver we are still at risk of | ||
9 | truncation. | ||
10 | |||
11 | Change the block crypto driver to use uint64_t, but add asserts that | ||
12 | the value is less than INT64_MAX. | ||
13 | |||
14 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
15 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
16 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
17 | Message-id: 20170927125340.12360-4-berrange@redhat.com | ||
18 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
19 | --- | ||
20 | block/crypto.c | 13 +++++++++---- | ||
21 | 1 file changed, 9 insertions(+), 4 deletions(-) | ||
22 | |||
23 | diff --git a/block/crypto.c b/block/crypto.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/block/crypto.c | ||
26 | +++ b/block/crypto.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_truncate(BlockDriverState *bs, int64_t offset, | ||
28 | PreallocMode prealloc, Error **errp) | ||
29 | { | ||
30 | BlockCrypto *crypto = bs->opaque; | ||
31 | - size_t payload_offset = | ||
32 | + uint64_t payload_offset = | ||
33 | qcrypto_block_get_payload_offset(crypto->block); | ||
34 | + assert(payload_offset < (INT64_MAX - offset)); | ||
35 | |||
36 | offset += payload_offset; | ||
37 | |||
38 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
39 | uint8_t *cipher_data = NULL; | ||
40 | QEMUIOVector hd_qiov; | ||
41 | int ret = 0; | ||
42 | - size_t payload_offset = | ||
43 | + uint64_t payload_offset = | ||
44 | qcrypto_block_get_payload_offset(crypto->block) / 512; | ||
45 | + assert(payload_offset < (INT64_MAX / 512)); | ||
46 | |||
47 | qemu_iovec_init(&hd_qiov, qiov->niov); | ||
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
50 | uint8_t *cipher_data = NULL; | ||
51 | QEMUIOVector hd_qiov; | ||
52 | int ret = 0; | ||
53 | - size_t payload_offset = | ||
54 | + uint64_t payload_offset = | ||
55 | qcrypto_block_get_payload_offset(crypto->block) / 512; | ||
56 | + assert(payload_offset < (INT64_MAX / 512)); | ||
57 | |||
58 | qemu_iovec_init(&hd_qiov, qiov->niov); | ||
59 | |||
60 | @@ -XXX,XX +XXX,XX @@ static int64_t block_crypto_getlength(BlockDriverState *bs) | ||
61 | BlockCrypto *crypto = bs->opaque; | ||
62 | int64_t len = bdrv_getlength(bs->file->bs); | ||
63 | |||
64 | - ssize_t offset = qcrypto_block_get_payload_offset(crypto->block); | ||
65 | + uint64_t offset = qcrypto_block_get_payload_offset(crypto->block); | ||
66 | + assert(offset < INT64_MAX); | ||
67 | + assert(offset < len); | ||
68 | |||
69 | len -= offset; | ||
70 | |||
71 | -- | ||
72 | 2.13.6 | ||
73 | |||
74 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | ||
2 | 1 | ||
3 | Instead of sector offset, take the bytes offset when encrypting | ||
4 | or decrypting data. | ||
5 | |||
6 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
7 | Message-id: 20170927125340.12360-6-berrange@redhat.com | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | crypto/blockpriv.h | 4 ++-- | ||
13 | include/crypto/block.h | 14 ++++++++------ | ||
14 | block/crypto.c | 12 ++++-------- | ||
15 | block/qcow.c | 11 +++++++---- | ||
16 | block/qcow2-cluster.c | 8 +++----- | ||
17 | block/qcow2.c | 4 ++-- | ||
18 | crypto/block-luks.c | 12 ++++++++---- | ||
19 | crypto/block-qcow.c | 12 ++++++++---- | ||
20 | crypto/block.c | 20 ++++++++++++++------ | ||
21 | 9 files changed, 56 insertions(+), 41 deletions(-) | ||
22 | |||
23 | diff --git a/crypto/blockpriv.h b/crypto/blockpriv.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/crypto/blockpriv.h | ||
26 | +++ b/crypto/blockpriv.h | ||
27 | @@ -XXX,XX +XXX,XX @@ int qcrypto_block_decrypt_helper(QCryptoCipher *cipher, | ||
28 | size_t niv, | ||
29 | QCryptoIVGen *ivgen, | ||
30 | int sectorsize, | ||
31 | - uint64_t startsector, | ||
32 | + uint64_t offset, | ||
33 | uint8_t *buf, | ||
34 | size_t len, | ||
35 | Error **errp); | ||
36 | @@ -XXX,XX +XXX,XX @@ int qcrypto_block_encrypt_helper(QCryptoCipher *cipher, | ||
37 | size_t niv, | ||
38 | QCryptoIVGen *ivgen, | ||
39 | int sectorsize, | ||
40 | - uint64_t startsector, | ||
41 | + uint64_t offset, | ||
42 | uint8_t *buf, | ||
43 | size_t len, | ||
44 | Error **errp); | ||
45 | diff --git a/include/crypto/block.h b/include/crypto/block.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/include/crypto/block.h | ||
48 | +++ b/include/crypto/block.h | ||
49 | @@ -XXX,XX +XXX,XX @@ QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block, | ||
50 | /** | ||
51 | * @qcrypto_block_decrypt: | ||
52 | * @block: the block encryption object | ||
53 | - * @startsector: the sector from which @buf was read | ||
54 | + * @offset: the position at which @iov was read | ||
55 | * @buf: the buffer to decrypt | ||
56 | * @len: the length of @buf in bytes | ||
57 | * @errp: pointer to a NULL-initialized error object | ||
58 | * | ||
59 | * Decrypt @len bytes of cipher text in @buf, writing | ||
60 | - * plain text back into @buf | ||
61 | + * plain text back into @buf. @len and @offset must be | ||
62 | + * a multiple of the encryption format sector size. | ||
63 | * | ||
64 | * Returns 0 on success, -1 on failure | ||
65 | */ | ||
66 | int qcrypto_block_decrypt(QCryptoBlock *block, | ||
67 | - uint64_t startsector, | ||
68 | + uint64_t offset, | ||
69 | uint8_t *buf, | ||
70 | size_t len, | ||
71 | Error **errp); | ||
72 | @@ -XXX,XX +XXX,XX @@ int qcrypto_block_decrypt(QCryptoBlock *block, | ||
73 | /** | ||
74 | * @qcrypto_block_encrypt: | ||
75 | * @block: the block encryption object | ||
76 | - * @startsector: the sector to which @buf will be written | ||
77 | + * @offset: the position at which @iov will be written | ||
78 | * @buf: the buffer to decrypt | ||
79 | * @len: the length of @buf in bytes | ||
80 | * @errp: pointer to a NULL-initialized error object | ||
81 | * | ||
82 | * Encrypt @len bytes of plain text in @buf, writing | ||
83 | - * cipher text back into @buf | ||
84 | + * cipher text back into @buf. @len and @offset must be | ||
85 | + * a multiple of the encryption format sector size. | ||
86 | * | ||
87 | * Returns 0 on success, -1 on failure | ||
88 | */ | ||
89 | int qcrypto_block_encrypt(QCryptoBlock *block, | ||
90 | - uint64_t startsector, | ||
91 | + uint64_t offset, | ||
92 | uint8_t *buf, | ||
93 | size_t len, | ||
94 | Error **errp); | ||
95 | diff --git a/block/crypto.c b/block/crypto.c | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/block/crypto.c | ||
98 | +++ b/block/crypto.c | ||
99 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
100 | int ret = 0; | ||
101 | uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | ||
102 | uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block); | ||
103 | - uint64_t sector_num = offset / sector_size; | ||
104 | |||
105 | assert(!flags); | ||
106 | assert(payload_offset < INT64_MAX); | ||
107 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
108 | goto cleanup; | ||
109 | } | ||
110 | |||
111 | - if (qcrypto_block_decrypt(crypto->block, sector_num, cipher_data, | ||
112 | - cur_bytes, NULL) < 0) { | ||
113 | + if (qcrypto_block_decrypt(crypto->block, offset + bytes_done, | ||
114 | + cipher_data, cur_bytes, NULL) < 0) { | ||
115 | ret = -EIO; | ||
116 | goto cleanup; | ||
117 | } | ||
118 | |||
119 | qemu_iovec_from_buf(qiov, bytes_done, cipher_data, cur_bytes); | ||
120 | |||
121 | - sector_num += cur_bytes / sector_size; | ||
122 | bytes -= cur_bytes; | ||
123 | bytes_done += cur_bytes; | ||
124 | } | ||
125 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
126 | int ret = 0; | ||
127 | uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | ||
128 | uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block); | ||
129 | - uint64_t sector_num = offset / sector_size; | ||
130 | |||
131 | assert(!flags); | ||
132 | assert(payload_offset < INT64_MAX); | ||
133 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
134 | |||
135 | qemu_iovec_to_buf(qiov, bytes_done, cipher_data, cur_bytes); | ||
136 | |||
137 | - if (qcrypto_block_encrypt(crypto->block, sector_num, cipher_data, | ||
138 | - cur_bytes, NULL) < 0) { | ||
139 | + if (qcrypto_block_encrypt(crypto->block, offset + bytes_done, | ||
140 | + cipher_data, cur_bytes, NULL) < 0) { | ||
141 | ret = -EIO; | ||
142 | goto cleanup; | ||
143 | } | ||
144 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
145 | goto cleanup; | ||
146 | } | ||
147 | |||
148 | - sector_num += cur_bytes / sector_size; | ||
149 | bytes -= cur_bytes; | ||
150 | bytes_done += cur_bytes; | ||
151 | } | ||
152 | diff --git a/block/qcow.c b/block/qcow.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/block/qcow.c | ||
155 | +++ b/block/qcow.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static int get_cluster_offset(BlockDriverState *bs, | ||
157 | for(i = 0; i < s->cluster_sectors; i++) { | ||
158 | if (i < n_start || i >= n_end) { | ||
159 | memset(s->cluster_data, 0x00, 512); | ||
160 | - if (qcrypto_block_encrypt(s->crypto, start_sect + i, | ||
161 | + if (qcrypto_block_encrypt(s->crypto, | ||
162 | + (start_sect + i) * | ||
163 | + BDRV_SECTOR_SIZE, | ||
164 | s->cluster_data, | ||
165 | BDRV_SECTOR_SIZE, | ||
166 | NULL) < 0) { | ||
167 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, | ||
168 | } | ||
169 | if (bs->encrypted) { | ||
170 | assert(s->crypto); | ||
171 | - if (qcrypto_block_decrypt(s->crypto, sector_num, buf, | ||
172 | + if (qcrypto_block_decrypt(s->crypto, | ||
173 | + sector_num * BDRV_SECTOR_SIZE, buf, | ||
174 | n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
175 | ret = -EIO; | ||
176 | break; | ||
177 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, | ||
178 | } | ||
179 | if (bs->encrypted) { | ||
180 | assert(s->crypto); | ||
181 | - if (qcrypto_block_encrypt(s->crypto, sector_num, buf, | ||
182 | - n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
183 | + if (qcrypto_block_encrypt(s->crypto, sector_num * BDRV_SECTOR_SIZE, | ||
184 | + buf, n * BDRV_SECTOR_SIZE, NULL) < 0) { | ||
185 | ret = -EIO; | ||
186 | break; | ||
187 | } | ||
188 | diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/block/qcow2-cluster.c | ||
191 | +++ b/block/qcow2-cluster.c | ||
192 | @@ -XXX,XX +XXX,XX @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs, | ||
193 | { | ||
194 | if (bytes && bs->encrypted) { | ||
195 | BDRVQcow2State *s = bs->opaque; | ||
196 | - int64_t sector = (s->crypt_physical_offset ? | ||
197 | + int64_t offset = (s->crypt_physical_offset ? | ||
198 | (cluster_offset + offset_in_cluster) : | ||
199 | - (src_cluster_offset + offset_in_cluster)) | ||
200 | - >> BDRV_SECTOR_BITS; | ||
201 | + (src_cluster_offset + offset_in_cluster)); | ||
202 | assert((offset_in_cluster & ~BDRV_SECTOR_MASK) == 0); | ||
203 | assert((bytes & ~BDRV_SECTOR_MASK) == 0); | ||
204 | assert(s->crypto); | ||
205 | - if (qcrypto_block_encrypt(s->crypto, sector, buffer, | ||
206 | - bytes, NULL) < 0) { | ||
207 | + if (qcrypto_block_encrypt(s->crypto, offset, buffer, bytes, NULL) < 0) { | ||
208 | return false; | ||
209 | } | ||
210 | } | ||
211 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/block/qcow2.c | ||
214 | +++ b/block/qcow2.c | ||
215 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, | ||
216 | if (qcrypto_block_decrypt(s->crypto, | ||
217 | (s->crypt_physical_offset ? | ||
218 | cluster_offset + offset_in_cluster : | ||
219 | - offset) >> BDRV_SECTOR_BITS, | ||
220 | + offset), | ||
221 | cluster_data, | ||
222 | cur_bytes, | ||
223 | NULL) < 0) { | ||
224 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, | ||
225 | if (qcrypto_block_encrypt(s->crypto, | ||
226 | (s->crypt_physical_offset ? | ||
227 | cluster_offset + offset_in_cluster : | ||
228 | - offset) >> BDRV_SECTOR_BITS, | ||
229 | + offset), | ||
230 | cluster_data, | ||
231 | cur_bytes, NULL) < 0) { | ||
232 | ret = -EIO; | ||
233 | diff --git a/crypto/block-luks.c b/crypto/block-luks.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/crypto/block-luks.c | ||
236 | +++ b/crypto/block-luks.c | ||
237 | @@ -XXX,XX +XXX,XX @@ static void qcrypto_block_luks_cleanup(QCryptoBlock *block) | ||
238 | |||
239 | static int | ||
240 | qcrypto_block_luks_decrypt(QCryptoBlock *block, | ||
241 | - uint64_t startsector, | ||
242 | + uint64_t offset, | ||
243 | uint8_t *buf, | ||
244 | size_t len, | ||
245 | Error **errp) | ||
246 | { | ||
247 | + assert(QEMU_IS_ALIGNED(offset, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)); | ||
248 | + assert(QEMU_IS_ALIGNED(len, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)); | ||
249 | return qcrypto_block_decrypt_helper(block->cipher, | ||
250 | block->niv, block->ivgen, | ||
251 | QCRYPTO_BLOCK_LUKS_SECTOR_SIZE, | ||
252 | - startsector, buf, len, errp); | ||
253 | + offset, buf, len, errp); | ||
254 | } | ||
255 | |||
256 | |||
257 | static int | ||
258 | qcrypto_block_luks_encrypt(QCryptoBlock *block, | ||
259 | - uint64_t startsector, | ||
260 | + uint64_t offset, | ||
261 | uint8_t *buf, | ||
262 | size_t len, | ||
263 | Error **errp) | ||
264 | { | ||
265 | + assert(QEMU_IS_ALIGNED(offset, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)); | ||
266 | + assert(QEMU_IS_ALIGNED(len, QCRYPTO_BLOCK_LUKS_SECTOR_SIZE)); | ||
267 | return qcrypto_block_encrypt_helper(block->cipher, | ||
268 | block->niv, block->ivgen, | ||
269 | QCRYPTO_BLOCK_LUKS_SECTOR_SIZE, | ||
270 | - startsector, buf, len, errp); | ||
271 | + offset, buf, len, errp); | ||
272 | } | ||
273 | |||
274 | |||
275 | diff --git a/crypto/block-qcow.c b/crypto/block-qcow.c | ||
276 | index XXXXXXX..XXXXXXX 100644 | ||
277 | --- a/crypto/block-qcow.c | ||
278 | +++ b/crypto/block-qcow.c | ||
279 | @@ -XXX,XX +XXX,XX @@ qcrypto_block_qcow_cleanup(QCryptoBlock *block) | ||
280 | |||
281 | static int | ||
282 | qcrypto_block_qcow_decrypt(QCryptoBlock *block, | ||
283 | - uint64_t startsector, | ||
284 | + uint64_t offset, | ||
285 | uint8_t *buf, | ||
286 | size_t len, | ||
287 | Error **errp) | ||
288 | { | ||
289 | + assert(QEMU_IS_ALIGNED(offset, QCRYPTO_BLOCK_QCOW_SECTOR_SIZE)); | ||
290 | + assert(QEMU_IS_ALIGNED(len, QCRYPTO_BLOCK_QCOW_SECTOR_SIZE)); | ||
291 | return qcrypto_block_decrypt_helper(block->cipher, | ||
292 | block->niv, block->ivgen, | ||
293 | QCRYPTO_BLOCK_QCOW_SECTOR_SIZE, | ||
294 | - startsector, buf, len, errp); | ||
295 | + offset, buf, len, errp); | ||
296 | } | ||
297 | |||
298 | |||
299 | static int | ||
300 | qcrypto_block_qcow_encrypt(QCryptoBlock *block, | ||
301 | - uint64_t startsector, | ||
302 | + uint64_t offset, | ||
303 | uint8_t *buf, | ||
304 | size_t len, | ||
305 | Error **errp) | ||
306 | { | ||
307 | + assert(QEMU_IS_ALIGNED(offset, QCRYPTO_BLOCK_QCOW_SECTOR_SIZE)); | ||
308 | + assert(QEMU_IS_ALIGNED(len, QCRYPTO_BLOCK_QCOW_SECTOR_SIZE)); | ||
309 | return qcrypto_block_encrypt_helper(block->cipher, | ||
310 | block->niv, block->ivgen, | ||
311 | QCRYPTO_BLOCK_QCOW_SECTOR_SIZE, | ||
312 | - startsector, buf, len, errp); | ||
313 | + offset, buf, len, errp); | ||
314 | } | ||
315 | |||
316 | |||
317 | diff --git a/crypto/block.c b/crypto/block.c | ||
318 | index XXXXXXX..XXXXXXX 100644 | ||
319 | --- a/crypto/block.c | ||
320 | +++ b/crypto/block.c | ||
321 | @@ -XXX,XX +XXX,XX @@ QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block, | ||
322 | |||
323 | |||
324 | int qcrypto_block_decrypt(QCryptoBlock *block, | ||
325 | - uint64_t startsector, | ||
326 | + uint64_t offset, | ||
327 | uint8_t *buf, | ||
328 | size_t len, | ||
329 | Error **errp) | ||
330 | { | ||
331 | - return block->driver->decrypt(block, startsector, buf, len, errp); | ||
332 | + return block->driver->decrypt(block, offset, buf, len, errp); | ||
333 | } | ||
334 | |||
335 | |||
336 | int qcrypto_block_encrypt(QCryptoBlock *block, | ||
337 | - uint64_t startsector, | ||
338 | + uint64_t offset, | ||
339 | uint8_t *buf, | ||
340 | size_t len, | ||
341 | Error **errp) | ||
342 | { | ||
343 | - return block->driver->encrypt(block, startsector, buf, len, errp); | ||
344 | + return block->driver->encrypt(block, offset, buf, len, errp); | ||
345 | } | ||
346 | |||
347 | |||
348 | @@ -XXX,XX +XXX,XX @@ int qcrypto_block_decrypt_helper(QCryptoCipher *cipher, | ||
349 | size_t niv, | ||
350 | QCryptoIVGen *ivgen, | ||
351 | int sectorsize, | ||
352 | - uint64_t startsector, | ||
353 | + uint64_t offset, | ||
354 | uint8_t *buf, | ||
355 | size_t len, | ||
356 | Error **errp) | ||
357 | { | ||
358 | uint8_t *iv; | ||
359 | int ret = -1; | ||
360 | + uint64_t startsector = offset / sectorsize; | ||
361 | + | ||
362 | + assert(QEMU_IS_ALIGNED(offset, sectorsize)); | ||
363 | + assert(QEMU_IS_ALIGNED(len, sectorsize)); | ||
364 | |||
365 | iv = niv ? g_new0(uint8_t, niv) : NULL; | ||
366 | |||
367 | @@ -XXX,XX +XXX,XX @@ int qcrypto_block_encrypt_helper(QCryptoCipher *cipher, | ||
368 | size_t niv, | ||
369 | QCryptoIVGen *ivgen, | ||
370 | int sectorsize, | ||
371 | - uint64_t startsector, | ||
372 | + uint64_t offset, | ||
373 | uint8_t *buf, | ||
374 | size_t len, | ||
375 | Error **errp) | ||
376 | { | ||
377 | uint8_t *iv; | ||
378 | int ret = -1; | ||
379 | + uint64_t startsector = offset / sectorsize; | ||
380 | + | ||
381 | + assert(QEMU_IS_ALIGNED(offset, sectorsize)); | ||
382 | + assert(QEMU_IS_ALIGNED(len, sectorsize)); | ||
383 | |||
384 | iv = niv ? g_new0(uint8_t, niv) : NULL; | ||
385 | |||
386 | -- | ||
387 | 2.13.6 | ||
388 | |||
389 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: "Daniel P. Berrange" <berrange@redhat.com> | ||
2 | 1 | ||
3 | The BDRV_REQ_FUA flag can trivially be allowed in the crypt driver | ||
4 | as a passthrough to the underlying block driver. | ||
5 | |||
6 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Signed-off-by: Daniel P. Berrange <berrange@redhat.com> | ||
9 | Message-id: 20170927125340.12360-7-berrange@redhat.com | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | block/crypto.c | 7 +++++-- | ||
13 | 1 file changed, 5 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/block/crypto.c b/block/crypto.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/block/crypto.c | ||
18 | +++ b/block/crypto.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_open_generic(QCryptoBlockFormat format, | ||
20 | return -EINVAL; | ||
21 | } | ||
22 | |||
23 | + bs->supported_write_flags = BDRV_REQ_FUA & | ||
24 | + bs->file->bs->supported_write_flags; | ||
25 | + | ||
26 | opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort); | ||
27 | qemu_opts_absorb_qdict(opts, options, &local_err); | ||
28 | if (local_err) { | ||
29 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
30 | uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block); | ||
31 | uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block); | ||
32 | |||
33 | - assert(!flags); | ||
34 | + assert(!(flags & ~BDRV_REQ_FUA)); | ||
35 | assert(payload_offset < INT64_MAX); | ||
36 | assert(QEMU_IS_ALIGNED(offset, sector_size)); | ||
37 | assert(QEMU_IS_ALIGNED(bytes, sector_size)); | ||
38 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, | ||
39 | qemu_iovec_add(&hd_qiov, cipher_data, cur_bytes); | ||
40 | |||
41 | ret = bdrv_co_pwritev(bs->file, payload_offset + offset + bytes_done, | ||
42 | - cur_bytes, &hd_qiov, 0); | ||
43 | + cur_bytes, &hd_qiov, flags); | ||
44 | if (ret < 0) { | ||
45 | goto cleanup; | ||
46 | } | ||
47 | -- | ||
48 | 2.13.6 | ||
49 | |||
50 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Backing may be zero after failed bdrv_attach_child in | ||
4 | bdrv_set_backing_hd, which leads to SIGSEGV. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Message-id: 20170928120300.58164-1-vsementsov@virtuozzo.com | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
10 | --- | ||
11 | block/mirror.c | 5 +++++ | ||
12 | 1 file changed, 5 insertions(+) | ||
13 | |||
14 | diff --git a/block/mirror.c b/block/mirror.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/block/mirror.c | ||
17 | +++ b/block/mirror.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs, | ||
19 | |||
20 | static void bdrv_mirror_top_refresh_filename(BlockDriverState *bs, QDict *opts) | ||
21 | { | ||
22 | + if (bs->backing == NULL) { | ||
23 | + /* we can be here after failed bdrv_attach_child in | ||
24 | + * bdrv_set_backing_hd */ | ||
25 | + return; | ||
26 | + } | ||
27 | bdrv_refresh_filename(bs->backing->bs); | ||
28 | pstrcpy(bs->exact_filename, sizeof(bs->exact_filename), | ||
29 | bs->backing->bs->filename); | ||
30 | -- | ||
31 | 2.13.6 | ||
32 | |||
33 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Max Reitz <mreitz@redhat.com> | ||
2 | 1 | ||
3 | do_run_qemu() in iotest 195 first applies _filter_imgfmt when printing | ||
4 | qemu's command line and _filter_testdir only afterwards. Therefore, if | ||
5 | the image format is part of the test directory path, _filter_testdir | ||
6 | will no longer apply and the actual output will differ from the | ||
7 | reference output even in case of success. | ||
8 | |||
9 | For example, TEST_DIR might be "/tmp/test-qcow2", in which case | ||
10 | _filter_imgfmt first transforms this to "/tmp/test-IMGFMT" which is no | ||
11 | longer recognized as the TEST_DIR by _filter_testdir. | ||
12 | |||
13 | Fix this by not applying _filter_imgfmt in do_run_qemu() but in | ||
14 | run_qemu() instead, and only after _filter_testdir. | ||
15 | |||
16 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
17 | Message-id: 20170927211334.3988-1-mreitz@redhat.com | ||
18 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
19 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
20 | --- | ||
21 | tests/qemu-iotests/195 | 7 ++++--- | ||
22 | 1 file changed, 4 insertions(+), 3 deletions(-) | ||
23 | |||
24 | diff --git a/tests/qemu-iotests/195 b/tests/qemu-iotests/195 | ||
25 | index XXXXXXX..XXXXXXX 100755 | ||
26 | --- a/tests/qemu-iotests/195 | ||
27 | +++ b/tests/qemu-iotests/195 | ||
28 | @@ -XXX,XX +XXX,XX @@ _supported_os Linux | ||
29 | |||
30 | function do_run_qemu() | ||
31 | { | ||
32 | - echo Testing: "$@" | _filter_imgfmt | ||
33 | + echo Testing: "$@" | ||
34 | $QEMU -nographic -qmp-pretty stdio -serial none "$@" | ||
35 | echo | ||
36 | } | ||
37 | |||
38 | function run_qemu() | ||
39 | { | ||
40 | - do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp \ | ||
41 | - | _filter_qemu_io | _filter_generated_node_ids | ||
42 | + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \ | ||
43 | + | _filter_qmp | _filter_qemu_io \ | ||
44 | + | _filter_generated_node_ids | ||
45 | } | ||
46 | |||
47 | size=64M | ||
48 | -- | ||
49 | 2.13.6 | ||
50 | |||
51 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Pavel Butsykin <pbutsykin@virtuozzo.com> | ||
2 | 1 | ||
3 | Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com> | ||
4 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
5 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
6 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
7 | Message-id: 20170929121613.25997-2-pbutsykin@virtuozzo.com | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | block/qcow2.c | 4 ++-- | ||
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/block/qcow2.c | ||
16 | +++ b/block/qcow2.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, | ||
18 | if (old_file_size < 0) { | ||
19 | error_setg_errno(errp, -old_file_size, | ||
20 | "Failed to inquire current file length"); | ||
21 | - return ret; | ||
22 | + return old_file_size; | ||
23 | } | ||
24 | |||
25 | nb_new_data_clusters = DIV_ROUND_UP(offset - old_length, | ||
26 | @@ -XXX,XX +XXX,XX @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, | ||
27 | if (allocation_start < 0) { | ||
28 | error_setg_errno(errp, -allocation_start, | ||
29 | "Failed to resize refcount structures"); | ||
30 | - return -allocation_start; | ||
31 | + return allocation_start; | ||
32 | } | ||
33 | |||
34 | clusters_allocated = qcow2_alloc_clusters_at(bs, allocation_start, | ||
35 | -- | ||
36 | 2.13.6 | ||
37 | |||
38 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
2 | 1 | ||
3 | Backing may be zero after failed bdrv_append in mirror_start_job, | ||
4 | which leads to SIGSEGV. | ||
5 | |||
6 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
7 | Message-id: 20170929152255.5431-1-vsementsov@virtuozzo.com | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | block/mirror.c | 4 ++++ | ||
11 | 1 file changed, 4 insertions(+) | ||
12 | |||
13 | diff --git a/block/mirror.c b/block/mirror.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/block/mirror.c | ||
16 | +++ b/block/mirror.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs, | ||
18 | |||
19 | static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs) | ||
20 | { | ||
21 | + if (bs->backing == NULL) { | ||
22 | + /* we can be here after failed bdrv_append in mirror_start_job */ | ||
23 | + return 0; | ||
24 | + } | ||
25 | return bdrv_co_flush(bs->backing->bs); | ||
26 | } | ||
27 | |||
28 | -- | ||
29 | 2.13.6 | ||
30 | |||
31 | diff view generated by jsdifflib |