1 | The following changes since commit 3fbd3405d2b0604ea530fc7a1828f19da1e95ff9: | 1 | The following changes since commit 6c769690ac845fa62642a5f93b4e4bd906adab95: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/huth-gitlab/tags/pull-request-2019-08-17' into staging (2019-08-19 14:14:09 +0100) | 3 | Merge remote-tracking branch 'remotes/vsementsov/tags/pull-simplebench-2021-05-04' into staging (2021-05-21 12:02:34 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/XanClic/qemu.git tags/pull-block-2019-08-19 | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to fa27c478102a6b5d1c6b02c005607ad9404b915f: | 9 | for you to fetch changes up to 0a6f0c76a030710780ce10d6347a70f098024d21: |
10 | 10 | ||
11 | doc: Preallocation does not require writing zeroes (2019-08-19 17:13:26 +0200) | 11 | coroutine-sleep: introduce qemu_co_sleep (2021-05-21 18:22:33 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Block patches: | 14 | Pull request |
15 | - preallocation=falloc/full support for LUKS | 15 | |
16 | - Various minor fixes | 16 | (Resent due to an email preparation mistake.) |
17 | 17 | ||
18 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
19 | Max Reitz (16): | ||
20 | qemu-img: Fix bdrv_has_zero_init() use in convert | ||
21 | mirror: Fix bdrv_has_zero_init() use | ||
22 | block: Add bdrv_has_zero_init_truncate() | ||
23 | block: Implement .bdrv_has_zero_init_truncate() | ||
24 | block: Use bdrv_has_zero_init_truncate() | ||
25 | qcow2: Fix .bdrv_has_zero_init() | ||
26 | vdi: Fix .bdrv_has_zero_init() | ||
27 | vhdx: Fix .bdrv_has_zero_init() | ||
28 | iotests: Convert to preallocated encrypted qcow2 | ||
29 | iotests: Test convert -n to pre-filled image | ||
30 | iotests: Full mirror to existing non-zero image | ||
31 | vdi: Make block_status recurse for fixed images | ||
32 | vmdk: Make block_status recurse for flat extents | ||
33 | vpc: Do not return RAW from block_status | ||
34 | iotests: Fix 141 when run with qed | ||
35 | doc: Preallocation does not require writing zeroes | ||
36 | 19 | ||
37 | Maxim Levitsky (1): | 20 | Paolo Bonzini (6): |
38 | LUKS: support preallocation | 21 | coroutine-sleep: use a stack-allocated timer |
22 | coroutine-sleep: disallow NULL QemuCoSleepState** argument | ||
23 | coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing | ||
24 | coroutine-sleep: move timer out of QemuCoSleepState | ||
25 | coroutine-sleep: replace QemuCoSleepState pointer with struct in the | ||
26 | API | ||
27 | coroutine-sleep: introduce qemu_co_sleep | ||
39 | 28 | ||
40 | qapi/block-core.json | 15 +++++--- | 29 | Philippe Mathieu-Daudé (1): |
41 | include/block/block.h | 1 + | 30 | bitops.h: Improve find_xxx_bit() documentation |
42 | include/block/block_int.h | 9 +++++ | 31 | |
43 | block.c | 21 +++++++++++ | 32 | Zenghui Yu (1): |
44 | block/crypto.c | 30 ++++++++++++++-- | 33 | multi-process: Initialize variables declared with g_auto* |
45 | block/file-posix.c | 1 + | 34 | |
46 | block/file-win32.c | 1 + | 35 | include/qemu/bitops.h | 15 ++++++-- |
47 | block/gluster.c | 4 +++ | 36 | include/qemu/coroutine.h | 27 ++++++++----- |
48 | block/mirror.c | 11 ++++-- | 37 | block/block-copy.c | 10 ++--- |
49 | block/nfs.c | 1 + | 38 | block/nbd.c | 14 +++---- |
50 | block/parallels.c | 2 +- | 39 | hw/remote/memory.c | 5 +-- |
51 | block/qcow2.c | 30 +++++++++++++++- | 40 | hw/remote/proxy.c | 3 +- |
52 | block/qed.c | 1 + | 41 | util/qemu-coroutine-sleep.c | 75 +++++++++++++++++++------------------ |
53 | block/raw-format.c | 6 ++++ | 42 | 7 files changed, 79 insertions(+), 70 deletions(-) |
54 | block/rbd.c | 1 + | ||
55 | block/sheepdog.c | 1 + | ||
56 | block/ssh.c | 1 + | ||
57 | block/vdi.c | 16 +++++++-- | ||
58 | block/vhdx.c | 28 +++++++++++++-- | ||
59 | block/vmdk.c | 3 ++ | ||
60 | block/vpc.c | 2 +- | ||
61 | blockdev.c | 16 +++++++-- | ||
62 | qemu-img.c | 11 ++++-- | ||
63 | tests/test-block-iothread.c | 2 +- | ||
64 | docs/qemu-block-drivers.texi | 4 +-- | ||
65 | qemu-img.texi | 4 +-- | ||
66 | tests/qemu-iotests/041 | 62 +++++++++++++++++++++++++++++--- | ||
67 | tests/qemu-iotests/041.out | 4 +-- | ||
68 | tests/qemu-iotests/122 | 17 +++++++++ | ||
69 | tests/qemu-iotests/122.out | 8 +++++ | ||
70 | tests/qemu-iotests/141 | 9 +++-- | ||
71 | tests/qemu-iotests/141.out | 5 --- | ||
72 | tests/qemu-iotests/188 | 20 ++++++++++- | ||
73 | tests/qemu-iotests/188.out | 4 +++ | ||
74 | tests/qemu-iotests/common.filter | 5 +++ | ||
75 | 35 files changed, 313 insertions(+), 43 deletions(-) | ||
76 | 43 | ||
77 | -- | 44 | -- |
78 | 2.21.0 | 45 | 2.31.1 |
79 | 46 | ||
80 | diff view generated by jsdifflib |
1 | When preallocating an encrypted qcow2 image, it just lets the protocol | 1 | From: Zenghui Yu <yuzenghui@huawei.com> |
---|---|---|---|
2 | driver write data and then does not mark the clusters as zero. | ||
3 | Therefore, reading this image will yield effectively random data. | ||
4 | 2 | ||
5 | As such, we have not fulfilled the promise of always writing zeroes when | 3 | Quote docs/devel/style.rst (section "Automatic memory deallocation"): |
6 | preallocating an image in a while. It seems that nobody has really | ||
7 | cared, so change the documentation to conform to qemu's actual behavior. | ||
8 | 4 | ||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 5 | * Variables declared with g_auto* MUST always be initialized, |
10 | Message-id: 20190711132935.13070-1-mreitz@redhat.com | 6 | otherwise the cleanup function will use uninitialized stack memory |
11 | Reviewed-by: Eric Blake <eblake@redhat.com> | 7 | |
12 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | 8 | Initialize @name properly to get rid of the compilation error (using |
13 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 9 | gcc-7.3.0 on CentOS): |
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 10 | |
11 | ../hw/remote/proxy.c: In function 'pci_proxy_dev_realize': | ||
12 | /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be used uninitialized in this function [-Werror=maybe-uninitialized] | ||
13 | g_free (*pp); | ||
14 | ^~~~~~~~~~~~ | ||
15 | ../hw/remote/proxy.c:350:30: note: 'name' was declared here | ||
16 | g_autofree char *name; | ||
17 | ^~~~ | ||
18 | |||
19 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
20 | Reviewed-by: Jagannathan Raman <jag.raman@oracle.com> | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
22 | Reviewed-by: Miroslav Rezanina <mrezanin@redhat.com> | ||
23 | Message-id: 20210312112143.1369-1-yuzenghui@huawei.com | ||
24 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | 25 | --- |
16 | qapi/block-core.json | 9 +++++---- | 26 | hw/remote/memory.c | 5 ++--- |
17 | docs/qemu-block-drivers.texi | 4 ++-- | 27 | hw/remote/proxy.c | 3 +-- |
18 | qemu-img.texi | 4 ++-- | 28 | 2 files changed, 3 insertions(+), 5 deletions(-) |
19 | 3 files changed, 9 insertions(+), 8 deletions(-) | ||
20 | 29 | ||
21 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 30 | diff --git a/hw/remote/memory.c b/hw/remote/memory.c |
22 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/qapi/block-core.json | 32 | --- a/hw/remote/memory.c |
24 | +++ b/qapi/block-core.json | 33 | +++ b/hw/remote/memory.c |
25 | @@ -XXX,XX +XXX,XX @@ | 34 | @@ -XXX,XX +XXX,XX @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) |
26 | # @off: no preallocation | 35 | |
27 | # @metadata: preallocate only for metadata | 36 | remote_sysmem_reset(); |
28 | # @falloc: like @full preallocation but allocate disk space by | 37 | |
29 | -# posix_fallocate() rather than writing zeros. | 38 | - for (region = 0; region < msg->num_fds; region++) { |
30 | -# @full: preallocate all data by writing zeros to device to ensure disk | 39 | - g_autofree char *name; |
31 | -# space is really available. @full preallocation also sets up | 40 | + for (region = 0; region < msg->num_fds; region++, suffix++) { |
32 | -# metadata correctly. | 41 | + g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix); |
33 | +# posix_fallocate() rather than writing data. | 42 | subregion = g_new(MemoryRegion, 1); |
34 | +# @full: preallocate all data by writing it to the device to ensure | 43 | - name = g_strdup_printf("remote-mem-%u", suffix++); |
35 | +# disk space is really available. This data may or may not be | 44 | memory_region_init_ram_from_fd(subregion, NULL, |
36 | +# zero, depending on the image format and storage. | 45 | name, sysmem_info->sizes[region], |
37 | +# @full preallocation also sets up metadata correctly. | 46 | true, msg->fds[region], |
38 | # | 47 | diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c |
39 | # Since: 2.2 | ||
40 | ## | ||
41 | diff --git a/docs/qemu-block-drivers.texi b/docs/qemu-block-drivers.texi | ||
42 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/docs/qemu-block-drivers.texi | 49 | --- a/hw/remote/proxy.c |
44 | +++ b/docs/qemu-block-drivers.texi | 50 | +++ b/hw/remote/proxy.c |
45 | @@ -XXX,XX +XXX,XX @@ Supported options: | 51 | @@ -XXX,XX +XXX,XX @@ static void probe_pci_info(PCIDevice *dev, Error **errp) |
46 | @item preallocation | 52 | PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMORY; |
47 | Preallocation mode (allowed values: @code{off}, @code{falloc}, @code{full}). | 53 | |
48 | @code{falloc} mode preallocates space for image by calling posix_fallocate(). | 54 | if (size) { |
49 | -@code{full} mode preallocates space for image by writing zeros to underlying | 55 | - g_autofree char *name; |
50 | -storage. | 56 | + g_autofree char *name = g_strdup_printf("bar-region-%d", i); |
51 | +@code{full} mode preallocates space for image by writing data to underlying | 57 | pdev->region[i].dev = pdev; |
52 | +storage. This data may or may not be zero, depending on the storage location. | 58 | pdev->region[i].present = true; |
53 | @end table | 59 | if (type == PCI_BASE_ADDRESS_SPACE_MEMORY) { |
54 | 60 | pdev->region[i].memory = true; | |
55 | @item qcow2 | 61 | } |
56 | diff --git a/qemu-img.texi b/qemu-img.texi | 62 | - name = g_strdup_printf("bar-region-%d", i); |
57 | index XXXXXXX..XXXXXXX 100644 | 63 | memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), |
58 | --- a/qemu-img.texi | 64 | &proxy_mr_ops, &pdev->region[i], |
59 | +++ b/qemu-img.texi | 65 | name, size); |
60 | @@ -XXX,XX +XXX,XX @@ Supported options: | ||
61 | @item preallocation | ||
62 | Preallocation mode (allowed values: @code{off}, @code{falloc}, @code{full}). | ||
63 | @code{falloc} mode preallocates space for image by calling posix_fallocate(). | ||
64 | -@code{full} mode preallocates space for image by writing zeros to underlying | ||
65 | -storage. | ||
66 | +@code{full} mode preallocates space for image by writing data to underlying | ||
67 | +storage. This data may or may not be zero, depending on the storage location. | ||
68 | @end table | ||
69 | |||
70 | @item qcow2 | ||
71 | -- | 66 | -- |
72 | 2.21.0 | 67 | 2.31.1 |
73 | 68 | ||
74 | diff view generated by jsdifflib |
1 | 69f47505ee has changed qcow2 in such a way that the commit job run in | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | test 141 (and 144[1]) returns before it emits the READY event. However, | ||
3 | 141 also runs with qed, where the order is still the other way around. | ||
4 | Just filter out the {"return": {}} so the test passes for qed again. | ||
5 | 2 | ||
6 | [1] 144 only runs with qcow2, so it is fine as it is. | 3 | Document the following functions return the bitmap size |
4 | if no matching bit is found: | ||
7 | 5 | ||
8 | Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 6 | - find_first_bit |
9 | Fixes: 69f47505ee66afaa513305de0c1895a224e52c45 | 7 | - find_next_bit |
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 8 | - find_last_bit |
11 | Message-id: 20190809185253.17535-1-mreitz@redhat.com | 9 | - find_first_zero_bit |
12 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 10 | - find_next_zero_bit |
13 | Reviewed-by: John Snow <jsnow@redhat.com> | 11 | |
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
13 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Message-id: 20210510200758.2623154-2-philmd@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | 17 | --- |
16 | tests/qemu-iotests/141 | 9 +++++++-- | 18 | include/qemu/bitops.h | 15 ++++++++++++--- |
17 | tests/qemu-iotests/141.out | 5 ----- | 19 | 1 file changed, 12 insertions(+), 3 deletions(-) |
18 | tests/qemu-iotests/common.filter | 5 +++++ | ||
19 | 3 files changed, 12 insertions(+), 7 deletions(-) | ||
20 | 20 | ||
21 | diff --git a/tests/qemu-iotests/141 b/tests/qemu-iotests/141 | 21 | diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h |
22 | index XXXXXXX..XXXXXXX 100755 | ||
23 | --- a/tests/qemu-iotests/141 | ||
24 | +++ b/tests/qemu-iotests/141 | ||
25 | @@ -XXX,XX +XXX,XX @@ test_blockjob() | ||
26 | }}}" \ | ||
27 | 'return' | ||
28 | |||
29 | + # If "$2" is an event, we may or may not see it before the | ||
30 | + # {"return": {}}. Therefore, filter the {"return": {}} out both | ||
31 | + # here and in the next command. (Naturally, if we do not see it | ||
32 | + # here, we will see it before the next command can be executed, | ||
33 | + # so it will appear in the next _send_qemu_cmd's output.) | ||
34 | _send_qemu_cmd $QEMU_HANDLE \ | ||
35 | "$1" \ | ||
36 | "$2" \ | ||
37 | - | _filter_img_create | ||
38 | + | _filter_img_create | _filter_qmp_empty_return | ||
39 | |||
40 | # We want this to return an error because the block job is still running | ||
41 | _send_qemu_cmd $QEMU_HANDLE \ | ||
42 | "{'execute': 'blockdev-del', | ||
43 | 'arguments': {'node-name': 'drv0'}}" \ | ||
44 | - 'error' | _filter_generated_node_ids | ||
45 | + 'error' | _filter_generated_node_ids | _filter_qmp_empty_return | ||
46 | |||
47 | _send_qemu_cmd $QEMU_HANDLE \ | ||
48 | "{'execute': 'block-job-cancel', | ||
49 | diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out | ||
50 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/tests/qemu-iotests/141.out | 23 | --- a/include/qemu/bitops.h |
52 | +++ b/tests/qemu-iotests/141.out | 24 | +++ b/include/qemu/bitops.h |
53 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/m. | 25 | @@ -XXX,XX +XXX,XX @@ static inline int test_bit(long nr, const unsigned long *addr) |
54 | Formatting 'TEST_DIR/o.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.IMGFMT backing_fmt=IMGFMT | 26 | * @addr: The address to start the search at |
55 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} | 27 | * @size: The maximum size to search |
56 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} | 28 | * |
57 | -{"return": {}} | 29 | - * Returns the bit number of the first set bit, or size. |
58 | {"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} | 30 | + * Returns the bit number of the last set bit, |
59 | {"return": {}} | 31 | + * or @size if there is no set bit in the bitmap. |
60 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "job0"}} | 32 | */ |
61 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t. | 33 | unsigned long find_last_bit(const unsigned long *addr, |
62 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} | 34 | unsigned long size); |
63 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} | 35 | @@ -XXX,XX +XXX,XX @@ unsigned long find_last_bit(const unsigned long *addr, |
64 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "mirror"}} | 36 | * @addr: The address to base the search on |
65 | -{"return": {}} | 37 | * @offset: The bitnumber to start searching at |
66 | {"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block device is in use by block job: mirror"}} | 38 | * @size: The bitmap size in bits |
67 | {"return": {}} | 39 | + * |
68 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "job0"}} | 40 | + * Returns the bit number of the next set bit, |
69 | @@ -XXX,XX +XXX,XX @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t. | 41 | + * or @size if there are no further set bits in the bitmap. |
70 | {"return": {}} | 42 | */ |
71 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} | 43 | unsigned long find_next_bit(const unsigned long *addr, |
72 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} | 44 | unsigned long size, |
73 | -{"return": {}} | 45 | @@ -XXX,XX +XXX,XX @@ unsigned long find_next_bit(const unsigned long *addr, |
74 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}} | 46 | * @addr: The address to base the search on |
75 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}} | 47 | * @offset: The bitnumber to start searching at |
76 | {"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block device is in use by block job: commit"}} | 48 | * @size: The bitmap size in bits |
77 | @@ -XXX,XX +XXX,XX @@ wrote 1048576/1048576 bytes at offset 0 | 49 | + * |
78 | {"return": {}} | 50 | + * Returns the bit number of the next cleared bit, |
79 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} | 51 | + * or @size if there are no further clear bits in the bitmap. |
80 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} | 52 | */ |
81 | -{"return": {}} | 53 | |
82 | {"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} | 54 | unsigned long find_next_zero_bit(const unsigned long *addr, |
83 | {"return": {}} | 55 | @@ -XXX,XX +XXX,XX @@ unsigned long find_next_zero_bit(const unsigned long *addr, |
84 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "job0"}} | 56 | * @addr: The address to start the search at |
85 | @@ -XXX,XX +XXX,XX @@ wrote 1048576/1048576 bytes at offset 0 | 57 | * @size: The maximum size to search |
86 | {"return": {}} | 58 | * |
87 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}} | 59 | - * Returns the bit number of the first set bit. |
88 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}} | 60 | + * Returns the bit number of the first set bit, |
89 | -{"return": {}} | 61 | + * or @size if there is no set bit in the bitmap. |
90 | {"error": {"class": "GenericError", "desc": "Node drv0 is in use"}} | 62 | */ |
91 | {"return": {}} | 63 | static inline unsigned long find_first_bit(const unsigned long *addr, |
92 | {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "aborting", "id": "job0"}} | 64 | unsigned long size) |
93 | diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter | 65 | @@ -XXX,XX +XXX,XX @@ static inline unsigned long find_first_bit(const unsigned long *addr, |
94 | index XXXXXXX..XXXXXXX 100644 | 66 | * @addr: The address to start the search at |
95 | --- a/tests/qemu-iotests/common.filter | 67 | * @size: The maximum size to search |
96 | +++ b/tests/qemu-iotests/common.filter | 68 | * |
97 | @@ -XXX,XX +XXX,XX @@ _filter_nbd() | 69 | - * Returns the bit number of the first cleared bit. |
98 | -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#' | 70 | + * Returns the bit number of the first cleared bit, |
99 | } | 71 | + * or @size if there is no clear bit in the bitmap. |
100 | 72 | */ | |
101 | +_filter_qmp_empty_return() | 73 | static inline unsigned long find_first_zero_bit(const unsigned long *addr, |
102 | +{ | 74 | unsigned long size) |
103 | + grep -v '{"return": {}}' | ||
104 | +} | ||
105 | + | ||
106 | # make sure this script returns success | ||
107 | true | ||
108 | -- | 75 | -- |
109 | 2.21.0 | 76 | 2.31.1 |
110 | 77 | ||
111 | diff view generated by jsdifflib |
1 | Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | Fixes: 69f47505ee66afaa513305de0c1895a224e52c45 | 2 | |
3 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 3 | The lifetime of the timer is well-known (it cannot outlive |
4 | Message-id: 20190725155512.9827-2-mreitz@redhat.com | 4 | qemu_co_sleep_ns_wakeable, because it's deleted by the time the |
5 | coroutine resumes), so it is not necessary to place it on the heap. | ||
6 | |||
5 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
7 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 9 | Message-id: 20210517100548.28806-2-pbonzini@redhat.com |
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
8 | --- | 11 | --- |
9 | block/vdi.c | 3 ++- | 12 | util/qemu-coroutine-sleep.c | 9 ++++----- |
10 | 1 file changed, 2 insertions(+), 1 deletion(-) | 13 | 1 file changed, 4 insertions(+), 5 deletions(-) |
11 | 14 | ||
12 | diff --git a/block/vdi.c b/block/vdi.c | 15 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/block/vdi.c | 17 | --- a/util/qemu-coroutine-sleep.c |
15 | +++ b/block/vdi.c | 18 | +++ b/util/qemu-coroutine-sleep.c |
16 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vdi_co_block_status(BlockDriverState *bs, | 19 | @@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; |
17 | *map = s->header.offset_data + (uint64_t)bmap_entry * s->block_size + | 20 | |
18 | index_in_block; | 21 | struct QemuCoSleepState { |
19 | *file = bs->file->bs; | 22 | Coroutine *co; |
20 | - return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; | 23 | - QEMUTimer *ts; |
21 | + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | | 24 | + QEMUTimer ts; |
22 | + (s->header.image_type == VDI_TYPE_STATIC ? BDRV_BLOCK_RECURSE : 0); | 25 | QemuCoSleepState **user_state_pointer; |
26 | }; | ||
27 | |||
28 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
29 | if (sleep_state->user_state_pointer) { | ||
30 | *sleep_state->user_state_pointer = NULL; | ||
31 | } | ||
32 | - timer_del(sleep_state->ts); | ||
33 | + timer_del(&sleep_state->ts); | ||
34 | aio_co_wake(sleep_state->co); | ||
23 | } | 35 | } |
24 | 36 | ||
25 | static int coroutine_fn | 37 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, |
38 | AioContext *ctx = qemu_get_current_aio_context(); | ||
39 | QemuCoSleepState state = { | ||
40 | .co = qemu_coroutine_self(), | ||
41 | - .ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state), | ||
42 | .user_state_pointer = sleep_state, | ||
43 | }; | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
46 | abort(); | ||
47 | } | ||
48 | |||
49 | + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); | ||
50 | if (sleep_state) { | ||
51 | *sleep_state = &state; | ||
52 | } | ||
53 | - timer_mod(state.ts, qemu_clock_get_ns(type) + ns); | ||
54 | + timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | ||
55 | qemu_coroutine_yield(); | ||
56 | if (sleep_state) { | ||
57 | /* | ||
58 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
59 | */ | ||
60 | assert(*sleep_state == NULL); | ||
61 | } | ||
62 | - timer_free(state.ts); | ||
63 | } | ||
26 | -- | 64 | -- |
27 | 2.21.0 | 65 | 2.31.1 |
28 | 66 | ||
29 | diff view generated by jsdifflib |
1 | vpc is not really a passthrough driver, even when using the fixed | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | subformat (where host and guest offsets are equal). It should handle | ||
3 | preallocation like all other drivers do, namely by returning | ||
4 | DATA | RECURSE instead of RAW. | ||
5 | 2 | ||
6 | There is no tangible difference but the fact that bdrv_is_allocated() no | 3 | Simplify the code by removing conditionals. qemu_co_sleep_ns |
7 | longer falls through to the protocol layer. | 4 | can simply point the argument to an on-stack temporary. |
8 | 5 | ||
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 6 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
10 | Message-id: 20190725155512.9827-4-mreitz@redhat.com | 7 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
11 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | Message-id: 20210517100548.28806-3-pbonzini@redhat.com |
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 10 | --- |
14 | block/vpc.c | 2 +- | 11 | include/qemu/coroutine.h | 5 +++-- |
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | util/qemu-coroutine-sleep.c | 18 +++++------------- |
13 | 2 files changed, 8 insertions(+), 15 deletions(-) | ||
16 | 14 | ||
17 | diff --git a/block/vpc.c b/block/vpc.c | 15 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/vpc.c | 17 | --- a/include/qemu/coroutine.h |
20 | +++ b/block/vpc.c | 18 | +++ b/include/qemu/coroutine.h |
21 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vpc_co_block_status(BlockDriverState *bs, | 19 | @@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleepState QemuCoSleepState; |
22 | *pnum = bytes; | 20 | |
23 | *map = offset; | 21 | /** |
24 | *file = bs->file->bs; | 22 | * Yield the coroutine for a given duration. During this yield, @sleep_state |
25 | - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; | 23 | - * (if not NULL) is set to an opaque pointer, which may be used for |
26 | + return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_RECURSE; | 24 | + * is set to an opaque pointer, which may be used for |
25 | * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the | ||
26 | * timer fires. Don't save the obtained value to other variables and don't call | ||
27 | * qemu_co_sleep_wake from another aio context. | ||
28 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
29 | QemuCoSleepState **sleep_state); | ||
30 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
31 | { | ||
32 | - qemu_co_sleep_ns_wakeable(type, ns, NULL); | ||
33 | + QemuCoSleepState *unused = NULL; | ||
34 | + qemu_co_sleep_ns_wakeable(type, ns, &unused); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/util/qemu-coroutine-sleep.c | ||
41 | +++ b/util/qemu-coroutine-sleep.c | ||
42 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
43 | qemu_co_sleep_ns__scheduled, NULL); | ||
44 | |||
45 | assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
46 | - if (sleep_state->user_state_pointer) { | ||
47 | - *sleep_state->user_state_pointer = NULL; | ||
48 | - } | ||
49 | + *sleep_state->user_state_pointer = NULL; | ||
50 | timer_del(&sleep_state->ts); | ||
51 | aio_co_wake(sleep_state->co); | ||
52 | } | ||
53 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
27 | } | 54 | } |
28 | 55 | ||
29 | qemu_co_mutex_lock(&s->lock); | 56 | aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); |
57 | - if (sleep_state) { | ||
58 | - *sleep_state = &state; | ||
59 | - } | ||
60 | + *sleep_state = &state; | ||
61 | timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); | ||
62 | qemu_coroutine_yield(); | ||
63 | - if (sleep_state) { | ||
64 | - /* | ||
65 | - * Note that *sleep_state is cleared during qemu_co_sleep_wake | ||
66 | - * before resuming this coroutine. | ||
67 | - */ | ||
68 | - assert(*sleep_state == NULL); | ||
69 | - } | ||
70 | + | ||
71 | + /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ | ||
72 | + assert(*sleep_state == NULL); | ||
73 | } | ||
30 | -- | 74 | -- |
31 | 2.21.0 | 75 | 2.31.1 |
32 | 76 | ||
33 | diff view generated by jsdifflib |
1 | From: Maxim Levitsky <mlevitsk@redhat.com> | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | preallocation=off and preallocation=metadata | 3 | All callers of qemu_co_sleep_wake are checking whether they are passing |
4 | both allocate luks header only, and preallocation=falloc/full | 4 | a NULL argument inside the pointer-to-pointer: do the check in |
5 | is passed to underlying file. | 5 | qemu_co_sleep_wake itself. |
6 | 6 | ||
7 | Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1534951 | 7 | As a side effect, qemu_co_sleep_wake can be called more than once and |
8 | it will only wake the coroutine once; after the first time, the argument | ||
9 | will be set to NULL via *sleep_state->user_state_pointer. However, this | ||
10 | would not be safe unless co_sleep_cb keeps using the QemuCoSleepState* | ||
11 | directly, so make it go through the pointer-to-pointer instead. | ||
8 | 12 | ||
9 | Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> | 13 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
10 | Message-id: 20190716161901.1430-1-mlevitsk@redhat.com | 14 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 15 | Message-id: 20210517100548.28806-4-pbonzini@redhat.com |
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | --- | 17 | --- |
13 | qapi/block-core.json | 6 +++++- | 18 | block/block-copy.c | 4 +--- |
14 | block/crypto.c | 30 +++++++++++++++++++++++++++--- | 19 | block/nbd.c | 8 ++------ |
15 | 2 files changed, 32 insertions(+), 4 deletions(-) | 20 | util/qemu-coroutine-sleep.c | 21 ++++++++++++--------- |
21 | 3 files changed, 15 insertions(+), 18 deletions(-) | ||
16 | 22 | ||
17 | diff --git a/qapi/block-core.json b/qapi/block-core.json | 23 | diff --git a/block/block-copy.c b/block/block-copy.c |
18 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/qapi/block-core.json | 25 | --- a/block/block-copy.c |
20 | +++ b/qapi/block-core.json | 26 | +++ b/block/block-copy.c |
21 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ out: |
22 | # | 28 | |
23 | # @file Node to create the image format on | 29 | void block_copy_kick(BlockCopyCallState *call_state) |
24 | # @size Size of the virtual disk in bytes | 30 | { |
25 | +# @preallocation Preallocation mode for the new image | 31 | - if (call_state->sleep_state) { |
26 | +# (since: 4.2) | 32 | - qemu_co_sleep_wake(call_state->sleep_state); |
27 | +# (default: off; allowed values: off, metadata, falloc, full) | 33 | - } |
28 | # | 34 | + qemu_co_sleep_wake(call_state->sleep_state); |
29 | # Since: 2.12 | 35 | } |
30 | ## | 36 | |
31 | { 'struct': 'BlockdevCreateOptionsLUKS', | 37 | /* |
32 | 'base': 'QCryptoBlockCreateOptionsLUKS', | 38 | diff --git a/block/nbd.c b/block/nbd.c |
33 | 'data': { 'file': 'BlockdevRef', | ||
34 | - 'size': 'size' } } | ||
35 | + 'size': 'size', | ||
36 | + '*preallocation': 'PreallocMode' } } | ||
37 | |||
38 | ## | ||
39 | # @BlockdevCreateOptionsNfs: | ||
40 | diff --git a/block/crypto.c b/block/crypto.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/block/crypto.c | 40 | --- a/block/nbd.c |
43 | +++ b/block/crypto.c | 41 | +++ b/block/nbd.c |
44 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_read_func(QCryptoBlock *block, | 42 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) |
45 | struct BlockCryptoCreateData { | 43 | BDRVNBDState *s = (BDRVNBDState *)bs->opaque; |
46 | BlockBackend *blk; | 44 | |
47 | uint64_t size; | 45 | s->drained = true; |
48 | + PreallocMode prealloc; | 46 | - if (s->connection_co_sleep_ns_state) { |
49 | }; | 47 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); |
50 | 48 | - } | |
51 | 49 | + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | |
52 | @@ -XXX,XX +XXX,XX @@ static ssize_t block_crypto_init_func(QCryptoBlock *block, | 50 | |
53 | * available to the guest, so we must take account of that | 51 | nbd_co_establish_connection_cancel(bs, false); |
54 | * which will be used by the crypto header | 52 | |
55 | */ | 53 | @@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs) |
56 | - return blk_truncate(data->blk, data->size + headerlen, PREALLOC_MODE_OFF, | 54 | |
57 | + return blk_truncate(data->blk, data->size + headerlen, data->prealloc, | 55 | s->state = NBD_CLIENT_QUIT; |
58 | errp); | 56 | if (s->connection_co) { |
57 | - if (s->connection_co_sleep_ns_state) { | ||
58 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
59 | - } | ||
60 | + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
61 | nbd_co_establish_connection_cancel(bs, true); | ||
62 | } | ||
63 | if (qemu_in_coroutine()) { | ||
64 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/util/qemu-coroutine-sleep.c | ||
67 | +++ b/util/qemu-coroutine-sleep.c | ||
68 | @@ -XXX,XX +XXX,XX @@ struct QemuCoSleepState { | ||
69 | |||
70 | void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
71 | { | ||
72 | - /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
73 | - const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
74 | - qemu_co_sleep_ns__scheduled, NULL); | ||
75 | + if (sleep_state) { | ||
76 | + /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
77 | + const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
78 | + qemu_co_sleep_ns__scheduled, NULL); | ||
79 | |||
80 | - assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
81 | - *sleep_state->user_state_pointer = NULL; | ||
82 | - timer_del(&sleep_state->ts); | ||
83 | - aio_co_wake(sleep_state->co); | ||
84 | + assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
85 | + *sleep_state->user_state_pointer = NULL; | ||
86 | + timer_del(&sleep_state->ts); | ||
87 | + aio_co_wake(sleep_state->co); | ||
88 | + } | ||
59 | } | 89 | } |
60 | 90 | ||
61 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_open_generic(QCryptoBlockFormat format, | 91 | static void co_sleep_cb(void *opaque) |
62 | static int block_crypto_co_create_generic(BlockDriverState *bs, | ||
63 | int64_t size, | ||
64 | QCryptoBlockCreateOptions *opts, | ||
65 | + PreallocMode prealloc, | ||
66 | Error **errp) | ||
67 | { | 92 | { |
68 | int ret; | 93 | - qemu_co_sleep_wake(opaque); |
69 | @@ -XXX,XX +XXX,XX @@ static int block_crypto_co_create_generic(BlockDriverState *bs, | 94 | + QemuCoSleepState **sleep_state = opaque; |
70 | goto cleanup; | 95 | + qemu_co_sleep_wake(*sleep_state); |
96 | } | ||
97 | |||
98 | void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
99 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
100 | abort(); | ||
71 | } | 101 | } |
72 | 102 | ||
73 | + if (prealloc == PREALLOC_MODE_METADATA) { | 103 | - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); |
74 | + prealloc = PREALLOC_MODE_OFF; | 104 | + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state); |
75 | + } | 105 | *sleep_state = &state; |
76 | + | 106 | timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); |
77 | data = (struct BlockCryptoCreateData) { | 107 | qemu_coroutine_yield(); |
78 | .blk = blk, | ||
79 | .size = size, | ||
80 | + .prealloc = prealloc, | ||
81 | }; | ||
82 | |||
83 | crypto = qcrypto_block_create(opts, NULL, | ||
84 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp) | ||
85 | BlockdevCreateOptionsLUKS *luks_opts; | ||
86 | BlockDriverState *bs = NULL; | ||
87 | QCryptoBlockCreateOptions create_opts; | ||
88 | + PreallocMode preallocation = PREALLOC_MODE_OFF; | ||
89 | int ret; | ||
90 | |||
91 | assert(create_options->driver == BLOCKDEV_DRIVER_LUKS); | ||
92 | @@ -XXX,XX +XXX,XX @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp) | ||
93 | .u.luks = *qapi_BlockdevCreateOptionsLUKS_base(luks_opts), | ||
94 | }; | ||
95 | |||
96 | + if (luks_opts->has_preallocation) { | ||
97 | + preallocation = luks_opts->preallocation; | ||
98 | + } | ||
99 | + | ||
100 | ret = block_crypto_co_create_generic(bs, luks_opts->size, &create_opts, | ||
101 | - errp); | ||
102 | + preallocation, errp); | ||
103 | if (ret < 0) { | ||
104 | goto fail; | ||
105 | } | ||
106 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename, | ||
107 | QCryptoBlockCreateOptions *create_opts = NULL; | ||
108 | BlockDriverState *bs = NULL; | ||
109 | QDict *cryptoopts; | ||
110 | + PreallocMode prealloc; | ||
111 | + char *buf = NULL; | ||
112 | int64_t size; | ||
113 | int ret; | ||
114 | + Error *local_err = NULL; | ||
115 | |||
116 | /* Parse options */ | ||
117 | size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0); | ||
118 | |||
119 | + buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC); | ||
120 | + prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, | ||
121 | + PREALLOC_MODE_OFF, &local_err); | ||
122 | + g_free(buf); | ||
123 | + if (local_err) { | ||
124 | + error_propagate(errp, local_err); | ||
125 | + return -EINVAL; | ||
126 | + } | ||
127 | + | ||
128 | cryptoopts = qemu_opts_to_qdict_filtered(opts, NULL, | ||
129 | &block_crypto_create_opts_luks, | ||
130 | true); | ||
131 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn block_crypto_co_create_opts_luks(const char *filename, | ||
132 | } | ||
133 | |||
134 | /* Create format layer */ | ||
135 | - ret = block_crypto_co_create_generic(bs, size, create_opts, errp); | ||
136 | + ret = block_crypto_co_create_generic(bs, size, create_opts, prealloc, errp); | ||
137 | if (ret < 0) { | ||
138 | goto fail; | ||
139 | } | ||
140 | -- | 108 | -- |
141 | 2.21.0 | 109 | 2.31.1 |
142 | 110 | ||
143 | diff view generated by jsdifflib |
1 | vhdx and parallels call bdrv_has_zero_init() when they do not really | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | care about an image's post-create state but only about what happens when | ||
3 | you grow an image. That is a bit ugly, and also overly safe when | ||
4 | growing preallocated images without preallocating the new areas. | ||
5 | 2 | ||
6 | Let them use bdrv_has_zero_init_truncate() instead. | 3 | This simplification is enabled by the previous patch. Now aio_co_wake |
4 | will only be called once, therefore we do not care about a spurious | ||
5 | firing of the timer after a qemu_co_sleep_wake. | ||
7 | 6 | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> |
9 | Message-id: 20190724171239.8764-6-mreitz@redhat.com | 8 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> |
10 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 9 | Message-id: 20210517100548.28806-5-pbonzini@redhat.com |
11 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | [mreitz: Added commit message] | ||
13 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
14 | --- | 11 | --- |
15 | block/parallels.c | 2 +- | 12 | util/qemu-coroutine-sleep.c | 8 ++++---- |
16 | block/vhdx.c | 2 +- | 13 | 1 file changed, 4 insertions(+), 4 deletions(-) |
17 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
18 | 14 | ||
19 | diff --git a/block/parallels.c b/block/parallels.c | 15 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c |
20 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/block/parallels.c | 17 | --- a/util/qemu-coroutine-sleep.c |
22 | +++ b/block/parallels.c | 18 | +++ b/util/qemu-coroutine-sleep.c |
23 | @@ -XXX,XX +XXX,XX @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, | 19 | @@ -XXX,XX +XXX,XX @@ static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; |
24 | goto fail_options; | 20 | |
21 | struct QemuCoSleepState { | ||
22 | Coroutine *co; | ||
23 | - QEMUTimer ts; | ||
24 | QemuCoSleepState **user_state_pointer; | ||
25 | }; | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
28 | |||
29 | assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
30 | *sleep_state->user_state_pointer = NULL; | ||
31 | - timer_del(&sleep_state->ts); | ||
32 | aio_co_wake(sleep_state->co); | ||
25 | } | 33 | } |
26 | 34 | } | |
27 | - if (!bdrv_has_zero_init(bs->file->bs)) { | 35 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, |
28 | + if (!bdrv_has_zero_init_truncate(bs->file->bs)) { | 36 | QemuCoSleepState **sleep_state) |
29 | s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE; | 37 | { |
38 | AioContext *ctx = qemu_get_current_aio_context(); | ||
39 | + QEMUTimer ts; | ||
40 | QemuCoSleepState state = { | ||
41 | .co = qemu_coroutine_self(), | ||
42 | .user_state_pointer = sleep_state, | ||
43 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
44 | abort(); | ||
30 | } | 45 | } |
31 | 46 | ||
32 | diff --git a/block/vhdx.c b/block/vhdx.c | 47 | - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_state); |
33 | index XXXXXXX..XXXXXXX 100644 | 48 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); |
34 | --- a/block/vhdx.c | 49 | *sleep_state = &state; |
35 | +++ b/block/vhdx.c | 50 | - timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); |
36 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, | 51 | + timer_mod(&ts, qemu_clock_get_ns(type) + ns); |
37 | /* Queue another write of zero buffers if the underlying file | 52 | qemu_coroutine_yield(); |
38 | * does not zero-fill on file extension */ | 53 | + timer_del(&ts); |
39 | 54 | ||
40 | - if (bdrv_has_zero_init(bs->file->bs) == 0) { | 55 | /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ |
41 | + if (bdrv_has_zero_init_truncate(bs->file->bs) == 0) { | 56 | assert(*sleep_state == NULL); |
42 | use_zero_buffers = true; | ||
43 | |||
44 | /* zero fill the front, if any */ | ||
45 | -- | 57 | -- |
46 | 2.21.0 | 58 | 2.31.1 |
47 | 59 | ||
48 | diff view generated by jsdifflib |
1 | bdrv_has_zero_init() only has meaning for newly created images or image | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | areas. If qemu-img convert did not create the image itself, it cannot | 2 | |
3 | rely on bdrv_has_zero_init()'s result to carry any meaning. | 3 | Right now, users of qemu_co_sleep_ns_wakeable are simply passing |
4 | 4 | a pointer to QemuCoSleepState by reference to the function. But | |
5 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 5 | QemuCoSleepState really is just a Coroutine*; making the |
6 | Message-id: 20190724171239.8764-2-mreitz@redhat.com | 6 | content of the struct public is just as efficient and lets us |
7 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 7 | skip the user_state_pointer indirection. |
8 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> | 8 | |
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 9 | Since the usage is changed, take the occasion to rename the |
10 | struct to QemuCoSleep. | ||
11 | |||
12 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
13 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
14 | Message-id: 20210517100548.28806-6-pbonzini@redhat.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 16 | --- |
11 | qemu-img.c | 11 ++++++++--- | 17 | include/qemu/coroutine.h | 23 +++++++++++---------- |
12 | 1 file changed, 8 insertions(+), 3 deletions(-) | 18 | block/block-copy.c | 8 ++++---- |
13 | 19 | block/nbd.c | 10 ++++----- | |
14 | diff --git a/qemu-img.c b/qemu-img.c | 20 | util/qemu-coroutine-sleep.c | 41 ++++++++++++++++--------------------- |
15 | index XXXXXXX..XXXXXXX 100644 | 21 | 4 files changed, 39 insertions(+), 43 deletions(-) |
16 | --- a/qemu-img.c | 22 | |
17 | +++ b/qemu-img.c | 23 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h |
18 | @@ -XXX,XX +XXX,XX @@ typedef struct ImgConvertState { | 24 | index XXXXXXX..XXXXXXX 100644 |
19 | bool has_zero_init; | 25 | --- a/include/qemu/coroutine.h |
20 | bool compressed; | 26 | +++ b/include/qemu/coroutine.h |
21 | bool unallocated_blocks_are_zero; | 27 | @@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_wrlock(CoRwlock *lock); |
22 | + bool target_is_new; | 28 | */ |
23 | bool target_has_backing; | 29 | void qemu_co_rwlock_unlock(CoRwlock *lock); |
24 | int64_t target_backing_sectors; /* negative if unknown */ | 30 | |
25 | bool wr_in_order; | 31 | -typedef struct QemuCoSleepState QemuCoSleepState; |
26 | @@ -XXX,XX +XXX,XX @@ static int convert_do_copy(ImgConvertState *s) | 32 | +typedef struct QemuCoSleep { |
27 | int64_t sector_num = 0; | 33 | + Coroutine *to_wake; |
28 | 34 | +} QemuCoSleep; | |
29 | /* Check whether we have zero initialisation or can get it efficiently */ | 35 | |
30 | - s->has_zero_init = s->min_sparse && !s->target_has_backing | 36 | /** |
31 | - ? bdrv_has_zero_init(blk_bs(s->target)) | 37 | - * Yield the coroutine for a given duration. During this yield, @sleep_state |
32 | - : false; | 38 | - * is set to an opaque pointer, which may be used for |
33 | + if (s->target_is_new && s->min_sparse && !s->target_has_backing) { | 39 | - * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when the |
34 | + s->has_zero_init = bdrv_has_zero_init(blk_bs(s->target)); | 40 | - * timer fires. Don't save the obtained value to other variables and don't call |
35 | + } else { | 41 | - * qemu_co_sleep_wake from another aio context. |
36 | + s->has_zero_init = false; | 42 | + * Yield the coroutine for a given duration. Initializes @w so that, |
37 | + } | 43 | + * during this yield, it can be passed to qemu_co_sleep_wake() to |
38 | 44 | + * terminate the sleep. | |
39 | if (!s->has_zero_init && !s->target_has_backing && | 45 | */ |
40 | bdrv_can_write_zeroes_with_unmap(blk_bs(s->target))) | 46 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, |
41 | @@ -XXX,XX +XXX,XX @@ static int img_convert(int argc, char **argv) | 47 | - QemuCoSleepState **sleep_state); |
42 | } | 48 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, |
49 | + QEMUClockType type, int64_t ns); | ||
50 | + | ||
51 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
52 | { | ||
53 | - QemuCoSleepState *unused = NULL; | ||
54 | - qemu_co_sleep_ns_wakeable(type, ns, &unused); | ||
55 | + QemuCoSleep w = { 0 }; | ||
56 | + qemu_co_sleep_ns_wakeable(&w, type, ns); | ||
57 | } | ||
58 | |||
59 | /** | ||
60 | @@ -XXX,XX +XXX,XX @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
61 | * qemu_co_sleep_ns() and should be checked to be non-NULL before calling | ||
62 | * qemu_co_sleep_wake(). | ||
63 | */ | ||
64 | -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state); | ||
65 | +void qemu_co_sleep_wake(QemuCoSleep *w); | ||
66 | |||
67 | /** | ||
68 | * Yield until a file descriptor becomes readable | ||
69 | diff --git a/block/block-copy.c b/block/block-copy.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/block/block-copy.c | ||
72 | +++ b/block/block-copy.c | ||
73 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockCopyCallState { | ||
74 | /* State */ | ||
75 | int ret; | ||
76 | bool finished; | ||
77 | - QemuCoSleepState *sleep_state; | ||
78 | + QemuCoSleep sleep; | ||
79 | bool cancelled; | ||
80 | |||
81 | /* OUT parameters */ | ||
82 | @@ -XXX,XX +XXX,XX @@ block_copy_dirty_clusters(BlockCopyCallState *call_state) | ||
83 | if (ns > 0) { | ||
84 | block_copy_task_end(task, -EAGAIN); | ||
85 | g_free(task); | ||
86 | - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns, | ||
87 | - &call_state->sleep_state); | ||
88 | + qemu_co_sleep_ns_wakeable(&call_state->sleep, | ||
89 | + QEMU_CLOCK_REALTIME, ns); | ||
90 | continue; | ||
91 | } | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ out: | ||
94 | |||
95 | void block_copy_kick(BlockCopyCallState *call_state) | ||
96 | { | ||
97 | - qemu_co_sleep_wake(call_state->sleep_state); | ||
98 | + qemu_co_sleep_wake(&call_state->sleep); | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | diff --git a/block/nbd.c b/block/nbd.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/block/nbd.c | ||
105 | +++ b/block/nbd.c | ||
106 | @@ -XXX,XX +XXX,XX @@ typedef struct BDRVNBDState { | ||
107 | CoQueue free_sema; | ||
108 | Coroutine *connection_co; | ||
109 | Coroutine *teardown_co; | ||
110 | - QemuCoSleepState *connection_co_sleep_ns_state; | ||
111 | + QemuCoSleep reconnect_sleep; | ||
112 | bool drained; | ||
113 | bool wait_drained_end; | ||
114 | int in_flight; | ||
115 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn nbd_client_co_drain_begin(BlockDriverState *bs) | ||
116 | BDRVNBDState *s = (BDRVNBDState *)bs->opaque; | ||
117 | |||
118 | s->drained = true; | ||
119 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
120 | + qemu_co_sleep_wake(&s->reconnect_sleep); | ||
121 | |||
122 | nbd_co_establish_connection_cancel(bs, false); | ||
123 | |||
124 | @@ -XXX,XX +XXX,XX @@ static void nbd_teardown_connection(BlockDriverState *bs) | ||
125 | |||
126 | s->state = NBD_CLIENT_QUIT; | ||
127 | if (s->connection_co) { | ||
128 | - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); | ||
129 | + qemu_co_sleep_wake(&s->reconnect_sleep); | ||
130 | nbd_co_establish_connection_cancel(bs, true); | ||
43 | } | 131 | } |
44 | 132 | if (qemu_in_coroutine()) { | |
45 | + s.target_is_new = !skip_create; | 133 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDState *s) |
46 | + | 134 | } |
47 | flags = s.min_sparse ? (BDRV_O_RDWR | BDRV_O_UNMAP) : BDRV_O_RDWR; | 135 | bdrv_inc_in_flight(s->bs); |
48 | ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); | 136 | } else { |
49 | if (ret < 0) { | 137 | - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout, |
138 | - &s->connection_co_sleep_ns_state); | ||
139 | + qemu_co_sleep_ns_wakeable(&s->reconnect_sleep, | ||
140 | + QEMU_CLOCK_REALTIME, timeout); | ||
141 | if (s->drained) { | ||
142 | continue; | ||
143 | } | ||
144 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
145 | index XXXXXXX..XXXXXXX 100644 | ||
146 | --- a/util/qemu-coroutine-sleep.c | ||
147 | +++ b/util/qemu-coroutine-sleep.c | ||
148 | @@ -XXX,XX +XXX,XX @@ | ||
149 | |||
150 | static const char *qemu_co_sleep_ns__scheduled = "qemu_co_sleep_ns"; | ||
151 | |||
152 | -struct QemuCoSleepState { | ||
153 | +void qemu_co_sleep_wake(QemuCoSleep *w) | ||
154 | +{ | ||
155 | Coroutine *co; | ||
156 | - QemuCoSleepState **user_state_pointer; | ||
157 | -}; | ||
158 | |||
159 | -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) | ||
160 | -{ | ||
161 | - if (sleep_state) { | ||
162 | + co = w->to_wake; | ||
163 | + w->to_wake = NULL; | ||
164 | + if (co) { | ||
165 | /* Write of schedule protected by barrier write in aio_co_schedule */ | ||
166 | - const char *scheduled = qatomic_cmpxchg(&sleep_state->co->scheduled, | ||
167 | + const char *scheduled = qatomic_cmpxchg(&co->scheduled, | ||
168 | qemu_co_sleep_ns__scheduled, NULL); | ||
169 | |||
170 | assert(scheduled == qemu_co_sleep_ns__scheduled); | ||
171 | - *sleep_state->user_state_pointer = NULL; | ||
172 | - aio_co_wake(sleep_state->co); | ||
173 | + aio_co_wake(co); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | static void co_sleep_cb(void *opaque) | ||
178 | { | ||
179 | - QemuCoSleepState **sleep_state = opaque; | ||
180 | - qemu_co_sleep_wake(*sleep_state); | ||
181 | + QemuCoSleep *w = opaque; | ||
182 | + qemu_co_sleep_wake(w); | ||
183 | } | ||
184 | |||
185 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
186 | - QemuCoSleepState **sleep_state) | ||
187 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | ||
188 | + QEMUClockType type, int64_t ns) | ||
189 | { | ||
190 | + Coroutine *co = qemu_coroutine_self(); | ||
191 | AioContext *ctx = qemu_get_current_aio_context(); | ||
192 | QEMUTimer ts; | ||
193 | - QemuCoSleepState state = { | ||
194 | - .co = qemu_coroutine_self(), | ||
195 | - .user_state_pointer = sleep_state, | ||
196 | - }; | ||
197 | |||
198 | - const char *scheduled = qatomic_cmpxchg(&state.co->scheduled, NULL, | ||
199 | - qemu_co_sleep_ns__scheduled); | ||
200 | + const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL, | ||
201 | + qemu_co_sleep_ns__scheduled); | ||
202 | if (scheduled) { | ||
203 | fprintf(stderr, | ||
204 | "%s: Co-routine was already scheduled in '%s'\n", | ||
205 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, | ||
206 | abort(); | ||
207 | } | ||
208 | |||
209 | - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); | ||
210 | - *sleep_state = &state; | ||
211 | + w->to_wake = co; | ||
212 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), | ||
213 | timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
214 | qemu_coroutine_yield(); | ||
215 | timer_del(&ts); | ||
216 | |||
217 | - /* qemu_co_sleep_wake clears *sleep_state before resuming this coroutine. */ | ||
218 | - assert(*sleep_state == NULL); | ||
219 | + /* w->to_wake is cleared before resuming this coroutine. */ | ||
220 | + assert(w->to_wake == NULL); | ||
221 | } | ||
50 | -- | 222 | -- |
51 | 2.21.0 | 223 | 2.31.1 |
52 | 224 | ||
53 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | bdrv_has_zero_init() only has meaning for newly created images or image | ||
2 | areas. If the mirror job itself did not create the image, it cannot | ||
3 | rely on bdrv_has_zero_init()'s result to carry any meaning. | ||
4 | 1 | ||
5 | This is the case for drive-mirror with mode=existing and always for | ||
6 | blockdev-mirror. | ||
7 | |||
8 | Note that we only have to zero-initialize the target with sync=full, | ||
9 | because other modes actually do not promise that the target will contain | ||
10 | the same data as the source after the job -- sync=top only promises to | ||
11 | copy anything allocated in the top layer, and sync=none will only copy | ||
12 | new I/O. (Which is how mirror has always handled it.) | ||
13 | |||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | Message-id: 20190724171239.8764-3-mreitz@redhat.com | ||
16 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
17 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
18 | --- | ||
19 | include/block/block_int.h | 2 ++ | ||
20 | block/mirror.c | 11 ++++++++--- | ||
21 | blockdev.c | 16 +++++++++++++--- | ||
22 | tests/test-block-iothread.c | 2 +- | ||
23 | 4 files changed, 24 insertions(+), 7 deletions(-) | ||
24 | |||
25 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/block/block_int.h | ||
28 | +++ b/include/block/block_int.h | ||
29 | @@ -XXX,XX +XXX,XX @@ BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs, | ||
30 | * @buf_size: The amount of data that can be in flight at one time. | ||
31 | * @mode: Whether to collapse all images in the chain to the target. | ||
32 | * @backing_mode: How to establish the target's backing chain after completion. | ||
33 | + * @zero_target: Whether the target should be explicitly zero-initialized | ||
34 | * @on_source_error: The action to take upon error reading from the source. | ||
35 | * @on_target_error: The action to take upon error writing to the target. | ||
36 | * @unmap: Whether to unmap target where source sectors only contain zeroes. | ||
37 | @@ -XXX,XX +XXX,XX @@ void mirror_start(const char *job_id, BlockDriverState *bs, | ||
38 | int creation_flags, int64_t speed, | ||
39 | uint32_t granularity, int64_t buf_size, | ||
40 | MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, | ||
41 | + bool zero_target, | ||
42 | BlockdevOnError on_source_error, | ||
43 | BlockdevOnError on_target_error, | ||
44 | bool unmap, const char *filter_node_name, | ||
45 | diff --git a/block/mirror.c b/block/mirror.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/block/mirror.c | ||
48 | +++ b/block/mirror.c | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef struct MirrorBlockJob { | ||
50 | Error *replace_blocker; | ||
51 | bool is_none_mode; | ||
52 | BlockMirrorBackingMode backing_mode; | ||
53 | + /* Whether the target image requires explicit zero-initialization */ | ||
54 | + bool zero_target; | ||
55 | MirrorCopyMode copy_mode; | ||
56 | BlockdevOnError on_source_error, on_target_error; | ||
57 | bool synced; | ||
58 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) | ||
59 | int ret; | ||
60 | int64_t count; | ||
61 | |||
62 | - if (base == NULL && !bdrv_has_zero_init(target_bs)) { | ||
63 | + if (s->zero_target) { | ||
64 | if (!bdrv_can_write_zeroes_with_unmap(target_bs)) { | ||
65 | bdrv_set_dirty_bitmap(s->dirty_bitmap, 0, s->bdev_length); | ||
66 | return 0; | ||
67 | @@ -XXX,XX +XXX,XX @@ static BlockJob *mirror_start_job( | ||
68 | const char *replaces, int64_t speed, | ||
69 | uint32_t granularity, int64_t buf_size, | ||
70 | BlockMirrorBackingMode backing_mode, | ||
71 | + bool zero_target, | ||
72 | BlockdevOnError on_source_error, | ||
73 | BlockdevOnError on_target_error, | ||
74 | bool unmap, | ||
75 | @@ -XXX,XX +XXX,XX @@ static BlockJob *mirror_start_job( | ||
76 | s->on_target_error = on_target_error; | ||
77 | s->is_none_mode = is_none_mode; | ||
78 | s->backing_mode = backing_mode; | ||
79 | + s->zero_target = zero_target; | ||
80 | s->copy_mode = copy_mode; | ||
81 | s->base = base; | ||
82 | s->granularity = granularity; | ||
83 | @@ -XXX,XX +XXX,XX @@ void mirror_start(const char *job_id, BlockDriverState *bs, | ||
84 | int creation_flags, int64_t speed, | ||
85 | uint32_t granularity, int64_t buf_size, | ||
86 | MirrorSyncMode mode, BlockMirrorBackingMode backing_mode, | ||
87 | + bool zero_target, | ||
88 | BlockdevOnError on_source_error, | ||
89 | BlockdevOnError on_target_error, | ||
90 | bool unmap, const char *filter_node_name, | ||
91 | @@ -XXX,XX +XXX,XX @@ void mirror_start(const char *job_id, BlockDriverState *bs, | ||
92 | is_none_mode = mode == MIRROR_SYNC_MODE_NONE; | ||
93 | base = mode == MIRROR_SYNC_MODE_TOP ? backing_bs(bs) : NULL; | ||
94 | mirror_start_job(job_id, bs, creation_flags, target, replaces, | ||
95 | - speed, granularity, buf_size, backing_mode, | ||
96 | + speed, granularity, buf_size, backing_mode, zero_target, | ||
97 | on_source_error, on_target_error, unmap, NULL, NULL, | ||
98 | &mirror_job_driver, is_none_mode, base, false, | ||
99 | filter_node_name, true, copy_mode, errp); | ||
100 | @@ -XXX,XX +XXX,XX @@ BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs, | ||
101 | |||
102 | ret = mirror_start_job( | ||
103 | job_id, bs, creation_flags, base, NULL, speed, 0, 0, | ||
104 | - MIRROR_LEAVE_BACKING_CHAIN, | ||
105 | + MIRROR_LEAVE_BACKING_CHAIN, false, | ||
106 | on_error, on_error, true, cb, opaque, | ||
107 | &commit_active_job_driver, false, base, auto_complete, | ||
108 | filter_node_name, false, MIRROR_COPY_MODE_BACKGROUND, | ||
109 | diff --git a/blockdev.c b/blockdev.c | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/blockdev.c | ||
112 | +++ b/blockdev.c | ||
113 | @@ -XXX,XX +XXX,XX @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, | ||
114 | bool has_replaces, const char *replaces, | ||
115 | enum MirrorSyncMode sync, | ||
116 | BlockMirrorBackingMode backing_mode, | ||
117 | + bool zero_target, | ||
118 | bool has_speed, int64_t speed, | ||
119 | bool has_granularity, uint32_t granularity, | ||
120 | bool has_buf_size, int64_t buf_size, | ||
121 | @@ -XXX,XX +XXX,XX @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs, | ||
122 | */ | ||
123 | mirror_start(job_id, bs, target, | ||
124 | has_replaces ? replaces : NULL, job_flags, | ||
125 | - speed, granularity, buf_size, sync, backing_mode, | ||
126 | + speed, granularity, buf_size, sync, backing_mode, zero_target, | ||
127 | on_source_error, on_target_error, unmap, filter_node_name, | ||
128 | copy_mode, errp); | ||
129 | } | ||
130 | @@ -XXX,XX +XXX,XX @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) | ||
131 | int flags; | ||
132 | int64_t size; | ||
133 | const char *format = arg->format; | ||
134 | + bool zero_target; | ||
135 | int ret; | ||
136 | |||
137 | bs = qmp_get_root_bs(arg->device, errp); | ||
138 | @@ -XXX,XX +XXX,XX @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) | ||
139 | goto out; | ||
140 | } | ||
141 | |||
142 | + zero_target = (arg->sync == MIRROR_SYNC_MODE_FULL && | ||
143 | + (arg->mode == NEW_IMAGE_MODE_EXISTING || | ||
144 | + !bdrv_has_zero_init(target_bs))); | ||
145 | + | ||
146 | ret = bdrv_try_set_aio_context(target_bs, aio_context, errp); | ||
147 | if (ret < 0) { | ||
148 | bdrv_unref(target_bs); | ||
149 | @@ -XXX,XX +XXX,XX @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) | ||
150 | |||
151 | blockdev_mirror_common(arg->has_job_id ? arg->job_id : NULL, bs, target_bs, | ||
152 | arg->has_replaces, arg->replaces, arg->sync, | ||
153 | - backing_mode, arg->has_speed, arg->speed, | ||
154 | + backing_mode, zero_target, | ||
155 | + arg->has_speed, arg->speed, | ||
156 | arg->has_granularity, arg->granularity, | ||
157 | arg->has_buf_size, arg->buf_size, | ||
158 | arg->has_on_source_error, arg->on_source_error, | ||
159 | @@ -XXX,XX +XXX,XX @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id, | ||
160 | AioContext *aio_context; | ||
161 | BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN; | ||
162 | Error *local_err = NULL; | ||
163 | + bool zero_target; | ||
164 | int ret; | ||
165 | |||
166 | bs = qmp_get_root_bs(device, errp); | ||
167 | @@ -XXX,XX +XXX,XX @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id, | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | + zero_target = (sync == MIRROR_SYNC_MODE_FULL); | ||
172 | + | ||
173 | aio_context = bdrv_get_aio_context(bs); | ||
174 | aio_context_acquire(aio_context); | ||
175 | |||
176 | @@ -XXX,XX +XXX,XX @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id, | ||
177 | |||
178 | blockdev_mirror_common(has_job_id ? job_id : NULL, bs, target_bs, | ||
179 | has_replaces, replaces, sync, backing_mode, | ||
180 | - has_speed, speed, | ||
181 | + zero_target, has_speed, speed, | ||
182 | has_granularity, granularity, | ||
183 | has_buf_size, buf_size, | ||
184 | has_on_source_error, on_source_error, | ||
185 | diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c | ||
186 | index XXXXXXX..XXXXXXX 100644 | ||
187 | --- a/tests/test-block-iothread.c | ||
188 | +++ b/tests/test-block-iothread.c | ||
189 | @@ -XXX,XX +XXX,XX @@ static void test_propagate_mirror(void) | ||
190 | |||
191 | /* Start a mirror job */ | ||
192 | mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0, | ||
193 | - MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, | ||
194 | + MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN, false, | ||
195 | BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, | ||
196 | false, "filter_node", MIRROR_COPY_MODE_BACKGROUND, | ||
197 | &error_abort); | ||
198 | -- | ||
199 | 2.21.0 | ||
200 | |||
201 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | No .bdrv_has_zero_init() implementation returns 1 if growing the file | ||
2 | would add non-zero areas (at least with PREALLOC_MODE_OFF), so using it | ||
3 | in lieu of this new function was always safe. | ||
4 | 1 | ||
5 | But on the other hand, it is possible that growing an image that is not | ||
6 | zero-initialized would still add a zero-initialized area, like when | ||
7 | using nonpreallocating truncation on a preallocated image. For callers | ||
8 | that care only about truncation, not about creation with potential | ||
9 | preallocation, this new function is useful. | ||
10 | |||
11 | Alternatively, we could have added a PreallocMode parameter to | ||
12 | bdrv_has_zero_init(). But the only user would have been qemu-img | ||
13 | convert, which does not have a plain PreallocMode value right now -- it | ||
14 | would have to parse the creation option to obtain it. Therefore, the | ||
15 | simpler solution is to let bdrv_has_zero_init() inquire the | ||
16 | preallocation status and add the new bdrv_has_zero_init_truncate() that | ||
17 | presupposes PREALLOC_MODE_OFF. | ||
18 | |||
19 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
20 | Message-id: 20190724171239.8764-4-mreitz@redhat.com | ||
21 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
22 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> | ||
23 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
24 | --- | ||
25 | include/block/block.h | 1 + | ||
26 | include/block/block_int.h | 7 +++++++ | ||
27 | block.c | 21 +++++++++++++++++++++ | ||
28 | 3 files changed, 29 insertions(+) | ||
29 | |||
30 | diff --git a/include/block/block.h b/include/block/block.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/block/block.h | ||
33 | +++ b/include/block/block.h | ||
34 | @@ -XXX,XX +XXX,XX @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); | ||
35 | int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); | ||
36 | int bdrv_has_zero_init_1(BlockDriverState *bs); | ||
37 | int bdrv_has_zero_init(BlockDriverState *bs); | ||
38 | +int bdrv_has_zero_init_truncate(BlockDriverState *bs); | ||
39 | bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs); | ||
40 | bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); | ||
41 | int bdrv_block_status(BlockDriverState *bs, int64_t offset, | ||
42 | diff --git a/include/block/block_int.h b/include/block/block_int.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/include/block/block_int.h | ||
45 | +++ b/include/block/block_int.h | ||
46 | @@ -XXX,XX +XXX,XX @@ struct BlockDriver { | ||
47 | /* | ||
48 | * Returns 1 if newly created images are guaranteed to contain only | ||
49 | * zeros, 0 otherwise. | ||
50 | + * Must return 0 if .bdrv_has_zero_init_truncate() returns 0. | ||
51 | */ | ||
52 | int (*bdrv_has_zero_init)(BlockDriverState *bs); | ||
53 | |||
54 | + /* | ||
55 | + * Returns 1 if new areas added by growing the image with | ||
56 | + * PREALLOC_MODE_OFF contain only zeros, 0 otherwise. | ||
57 | + */ | ||
58 | + int (*bdrv_has_zero_init_truncate)(BlockDriverState *bs); | ||
59 | + | ||
60 | /* Remove fd handlers, timers, and other event loop callbacks so the event | ||
61 | * loop is no longer in use. Called with no in-flight requests and in | ||
62 | * depth-first traversal order with parents before child nodes. | ||
63 | diff --git a/block.c b/block.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/block.c | ||
66 | +++ b/block.c | ||
67 | @@ -XXX,XX +XXX,XX @@ int bdrv_has_zero_init(BlockDriverState *bs) | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | +int bdrv_has_zero_init_truncate(BlockDriverState *bs) | ||
72 | +{ | ||
73 | + if (!bs->drv) { | ||
74 | + return 0; | ||
75 | + } | ||
76 | + | ||
77 | + if (bs->backing) { | ||
78 | + /* Depends on the backing image length, but better safe than sorry */ | ||
79 | + return 0; | ||
80 | + } | ||
81 | + if (bs->drv->bdrv_has_zero_init_truncate) { | ||
82 | + return bs->drv->bdrv_has_zero_init_truncate(bs); | ||
83 | + } | ||
84 | + if (bs->file && bs->drv->is_filter) { | ||
85 | + return bdrv_has_zero_init_truncate(bs->file->bs); | ||
86 | + } | ||
87 | + | ||
88 | + /* safe default */ | ||
89 | + return 0; | ||
90 | +} | ||
91 | + | ||
92 | bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs) | ||
93 | { | ||
94 | BlockDriverInfo bdi; | ||
95 | -- | ||
96 | 2.21.0 | ||
97 | |||
98 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | We need to implement .bdrv_has_zero_init_truncate() for every block | ||
2 | driver that supports truncation and has a .bdrv_has_zero_init() | ||
3 | implementation. | ||
4 | 1 | ||
5 | Implement it the same way each driver implements .bdrv_has_zero_init(). | ||
6 | This is at least not any more unsafe than what we had before. | ||
7 | |||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | Message-id: 20190724171239.8764-5-mreitz@redhat.com | ||
10 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
11 | Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | --- | ||
14 | block/file-posix.c | 1 + | ||
15 | block/file-win32.c | 1 + | ||
16 | block/gluster.c | 4 ++++ | ||
17 | block/nfs.c | 1 + | ||
18 | block/qcow2.c | 1 + | ||
19 | block/qed.c | 1 + | ||
20 | block/raw-format.c | 6 ++++++ | ||
21 | block/rbd.c | 1 + | ||
22 | block/sheepdog.c | 1 + | ||
23 | block/ssh.c | 1 + | ||
24 | 10 files changed, 18 insertions(+) | ||
25 | |||
26 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/block/file-posix.c | ||
29 | +++ b/block/file-posix.c | ||
30 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = { | ||
31 | .bdrv_co_create = raw_co_create, | ||
32 | .bdrv_co_create_opts = raw_co_create_opts, | ||
33 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
34 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
35 | .bdrv_co_block_status = raw_co_block_status, | ||
36 | .bdrv_co_invalidate_cache = raw_co_invalidate_cache, | ||
37 | .bdrv_co_pwrite_zeroes = raw_co_pwrite_zeroes, | ||
38 | diff --git a/block/file-win32.c b/block/file-win32.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/block/file-win32.c | ||
41 | +++ b/block/file-win32.c | ||
42 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_file = { | ||
43 | .bdrv_close = raw_close, | ||
44 | .bdrv_co_create_opts = raw_co_create_opts, | ||
45 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
46 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
47 | |||
48 | .bdrv_aio_preadv = raw_aio_preadv, | ||
49 | .bdrv_aio_pwritev = raw_aio_pwritev, | ||
50 | diff --git a/block/gluster.c b/block/gluster.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/block/gluster.c | ||
53 | +++ b/block/gluster.c | ||
54 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_gluster = { | ||
55 | .bdrv_co_writev = qemu_gluster_co_writev, | ||
56 | .bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk, | ||
57 | .bdrv_has_zero_init = qemu_gluster_has_zero_init, | ||
58 | + .bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init, | ||
59 | #ifdef CONFIG_GLUSTERFS_DISCARD | ||
60 | .bdrv_co_pdiscard = qemu_gluster_co_pdiscard, | ||
61 | #endif | ||
62 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_gluster_tcp = { | ||
63 | .bdrv_co_writev = qemu_gluster_co_writev, | ||
64 | .bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk, | ||
65 | .bdrv_has_zero_init = qemu_gluster_has_zero_init, | ||
66 | + .bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init, | ||
67 | #ifdef CONFIG_GLUSTERFS_DISCARD | ||
68 | .bdrv_co_pdiscard = qemu_gluster_co_pdiscard, | ||
69 | #endif | ||
70 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_gluster_unix = { | ||
71 | .bdrv_co_writev = qemu_gluster_co_writev, | ||
72 | .bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk, | ||
73 | .bdrv_has_zero_init = qemu_gluster_has_zero_init, | ||
74 | + .bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init, | ||
75 | #ifdef CONFIG_GLUSTERFS_DISCARD | ||
76 | .bdrv_co_pdiscard = qemu_gluster_co_pdiscard, | ||
77 | #endif | ||
78 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_gluster_rdma = { | ||
79 | .bdrv_co_writev = qemu_gluster_co_writev, | ||
80 | .bdrv_co_flush_to_disk = qemu_gluster_co_flush_to_disk, | ||
81 | .bdrv_has_zero_init = qemu_gluster_has_zero_init, | ||
82 | + .bdrv_has_zero_init_truncate = qemu_gluster_has_zero_init, | ||
83 | #ifdef CONFIG_GLUSTERFS_DISCARD | ||
84 | .bdrv_co_pdiscard = qemu_gluster_co_pdiscard, | ||
85 | #endif | ||
86 | diff --git a/block/nfs.c b/block/nfs.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/block/nfs.c | ||
89 | +++ b/block/nfs.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_nfs = { | ||
91 | .create_opts = &nfs_create_opts, | ||
92 | |||
93 | .bdrv_has_zero_init = nfs_has_zero_init, | ||
94 | + .bdrv_has_zero_init_truncate = nfs_has_zero_init, | ||
95 | .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, | ||
96 | .bdrv_co_truncate = nfs_file_co_truncate, | ||
97 | |||
98 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/block/qcow2.c | ||
101 | +++ b/block/qcow2.c | ||
102 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_qcow2 = { | ||
103 | .bdrv_co_create_opts = qcow2_co_create_opts, | ||
104 | .bdrv_co_create = qcow2_co_create, | ||
105 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
106 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
107 | .bdrv_co_block_status = qcow2_co_block_status, | ||
108 | |||
109 | .bdrv_co_preadv = qcow2_co_preadv, | ||
110 | diff --git a/block/qed.c b/block/qed.c | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/block/qed.c | ||
113 | +++ b/block/qed.c | ||
114 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_qed = { | ||
115 | .bdrv_co_create = bdrv_qed_co_create, | ||
116 | .bdrv_co_create_opts = bdrv_qed_co_create_opts, | ||
117 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
118 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
119 | .bdrv_co_block_status = bdrv_qed_co_block_status, | ||
120 | .bdrv_co_readv = bdrv_qed_co_readv, | ||
121 | .bdrv_co_writev = bdrv_qed_co_writev, | ||
122 | diff --git a/block/raw-format.c b/block/raw-format.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/block/raw-format.c | ||
125 | +++ b/block/raw-format.c | ||
126 | @@ -XXX,XX +XXX,XX @@ static int raw_has_zero_init(BlockDriverState *bs) | ||
127 | return bdrv_has_zero_init(bs->file->bs); | ||
128 | } | ||
129 | |||
130 | +static int raw_has_zero_init_truncate(BlockDriverState *bs) | ||
131 | +{ | ||
132 | + return bdrv_has_zero_init_truncate(bs->file->bs); | ||
133 | +} | ||
134 | + | ||
135 | static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, | ||
136 | Error **errp) | ||
137 | { | ||
138 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_raw = { | ||
139 | .bdrv_co_ioctl = &raw_co_ioctl, | ||
140 | .create_opts = &raw_create_opts, | ||
141 | .bdrv_has_zero_init = &raw_has_zero_init, | ||
142 | + .bdrv_has_zero_init_truncate = &raw_has_zero_init_truncate, | ||
143 | .strong_runtime_opts = raw_strong_runtime_opts, | ||
144 | .mutable_opts = mutable_opts, | ||
145 | }; | ||
146 | diff --git a/block/rbd.c b/block/rbd.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/block/rbd.c | ||
149 | +++ b/block/rbd.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_rbd = { | ||
151 | .bdrv_co_create = qemu_rbd_co_create, | ||
152 | .bdrv_co_create_opts = qemu_rbd_co_create_opts, | ||
153 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
154 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
155 | .bdrv_get_info = qemu_rbd_getinfo, | ||
156 | .create_opts = &qemu_rbd_create_opts, | ||
157 | .bdrv_getlength = qemu_rbd_getlength, | ||
158 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
159 | index XXXXXXX..XXXXXXX 100644 | ||
160 | --- a/block/sheepdog.c | ||
161 | +++ b/block/sheepdog.c | ||
162 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_sheepdog = { | ||
163 | .bdrv_co_create = sd_co_create, | ||
164 | .bdrv_co_create_opts = sd_co_create_opts, | ||
165 | .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
166 | + .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
167 | .bdrv_getlength = sd_getlength, | ||
168 | .bdrv_get_allocated_file_size = sd_get_allocated_file_size, | ||
169 | .bdrv_co_truncate = sd_co_truncate, | ||
170 | diff --git a/block/ssh.c b/block/ssh.c | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/block/ssh.c | ||
173 | +++ b/block/ssh.c | ||
174 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_ssh = { | ||
175 | .bdrv_co_create_opts = ssh_co_create_opts, | ||
176 | .bdrv_close = ssh_close, | ||
177 | .bdrv_has_zero_init = ssh_has_zero_init, | ||
178 | + .bdrv_has_zero_init_truncate = ssh_has_zero_init, | ||
179 | .bdrv_co_readv = ssh_co_readv, | ||
180 | .bdrv_co_writev = ssh_co_writev, | ||
181 | .bdrv_getlength = ssh_getlength, | ||
182 | -- | ||
183 | 2.21.0 | ||
184 | |||
185 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | If a qcow2 file is preallocated, it can no longer guarantee that it | ||
2 | initially appears as filled with zeroes. | ||
3 | 1 | ||
4 | So implement .bdrv_has_zero_init() by checking whether the file is | ||
5 | preallocated; if so, forward the call to the underlying storage node, | ||
6 | except for when it is encrypted: Encrypted preallocated images always | ||
7 | return effectively random data, so .bdrv_has_zero_init() must always | ||
8 | return 0 for them. | ||
9 | |||
10 | .bdrv_has_zero_init_truncate() can remain bdrv_has_zero_init_1(), | ||
11 | because it presupposes PREALLOC_MODE_OFF. | ||
12 | |||
13 | Reported-by: Stefano Garzarella <sgarzare@redhat.com> | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | Message-id: 20190724171239.8764-7-mreitz@redhat.com | ||
16 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
17 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
18 | --- | ||
19 | block/qcow2.c | 29 ++++++++++++++++++++++++++++- | ||
20 | 1 file changed, 28 insertions(+), 1 deletion(-) | ||
21 | |||
22 | diff --git a/block/qcow2.c b/block/qcow2.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/block/qcow2.c | ||
25 | +++ b/block/qcow2.c | ||
26 | @@ -XXX,XX +XXX,XX @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs, | ||
27 | return spec_info; | ||
28 | } | ||
29 | |||
30 | +static int qcow2_has_zero_init(BlockDriverState *bs) | ||
31 | +{ | ||
32 | + BDRVQcow2State *s = bs->opaque; | ||
33 | + bool preallocated; | ||
34 | + | ||
35 | + if (qemu_in_coroutine()) { | ||
36 | + qemu_co_mutex_lock(&s->lock); | ||
37 | + } | ||
38 | + /* | ||
39 | + * Check preallocation status: Preallocated images have all L2 | ||
40 | + * tables allocated, nonpreallocated images have none. It is | ||
41 | + * therefore enough to check the first one. | ||
42 | + */ | ||
43 | + preallocated = s->l1_size > 0 && s->l1_table[0] != 0; | ||
44 | + if (qemu_in_coroutine()) { | ||
45 | + qemu_co_mutex_unlock(&s->lock); | ||
46 | + } | ||
47 | + | ||
48 | + if (!preallocated) { | ||
49 | + return 1; | ||
50 | + } else if (bs->encrypted) { | ||
51 | + return 0; | ||
52 | + } else { | ||
53 | + return bdrv_has_zero_init(s->data_file->bs); | ||
54 | + } | ||
55 | +} | ||
56 | + | ||
57 | static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, | ||
58 | int64_t pos) | ||
59 | { | ||
60 | @@ -XXX,XX +XXX,XX @@ BlockDriver bdrv_qcow2 = { | ||
61 | .bdrv_child_perm = bdrv_format_default_perms, | ||
62 | .bdrv_co_create_opts = qcow2_co_create_opts, | ||
63 | .bdrv_co_create = qcow2_co_create, | ||
64 | - .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
65 | + .bdrv_has_zero_init = qcow2_has_zero_init, | ||
66 | .bdrv_has_zero_init_truncate = bdrv_has_zero_init_1, | ||
67 | .bdrv_co_block_status = qcow2_co_block_status, | ||
68 | |||
69 | -- | ||
70 | 2.21.0 | ||
71 | |||
72 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Static VDI images cannot guarantee to be zero-initialized. If the image | ||
2 | has been statically allocated, forward the call to the underlying | ||
3 | storage node. | ||
4 | 1 | ||
5 | Reported-by: Stefano Garzarella <sgarzare@redhat.com> | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Reviewed-by: Stefan Weil <sw@weilnetz.de> | ||
8 | Acked-by: Stefano Garzarella <sgarzare@redhat.com> | ||
9 | Tested-by: Stefano Garzarella <sgarzare@redhat.com> | ||
10 | Message-id: 20190724171239.8764-8-mreitz@redhat.com | ||
11 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
12 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
13 | --- | ||
14 | block/vdi.c | 13 ++++++++++++- | ||
15 | 1 file changed, 12 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/block/vdi.c b/block/vdi.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/block/vdi.c | ||
20 | +++ b/block/vdi.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void vdi_close(BlockDriverState *bs) | ||
22 | error_free(s->migration_blocker); | ||
23 | } | ||
24 | |||
25 | +static int vdi_has_zero_init(BlockDriverState *bs) | ||
26 | +{ | ||
27 | + BDRVVdiState *s = bs->opaque; | ||
28 | + | ||
29 | + if (s->header.image_type == VDI_TYPE_STATIC) { | ||
30 | + return bdrv_has_zero_init(bs->file->bs); | ||
31 | + } else { | ||
32 | + return 1; | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | static QemuOptsList vdi_create_opts = { | ||
37 | .name = "vdi-create-opts", | ||
38 | .head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.head), | ||
39 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vdi = { | ||
40 | .bdrv_child_perm = bdrv_format_default_perms, | ||
41 | .bdrv_co_create = vdi_co_create, | ||
42 | .bdrv_co_create_opts = vdi_co_create_opts, | ||
43 | - .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
44 | + .bdrv_has_zero_init = vdi_has_zero_init, | ||
45 | .bdrv_co_block_status = vdi_co_block_status, | ||
46 | .bdrv_make_empty = vdi_make_empty, | ||
47 | |||
48 | -- | ||
49 | 2.21.0 | ||
50 | |||
51 | diff view generated by jsdifflib |
1 | Fixed VHDX images cannot guarantee to be zero-initialized. If the image | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | has the "fixed" subformat, forward the call to the underlying storage | ||
3 | node. | ||
4 | 2 | ||
5 | Reported-by: Stefano Garzarella <sgarzare@redhat.com> | 3 | Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake. |
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 4 | This makes the logic of qemu_co_sleep_ns_wakeable easy to understand. |
7 | Message-id: 20190724171239.8764-9-mreitz@redhat.com | 5 | |
8 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | 6 | In the future we will introduce an API that can work even if the |
9 | Signed-off-by: Max Reitz <mreitz@redhat.com> | 7 | sleep and wake happen from different threads. For now, initializing |
8 | w->to_wake after timer_mod is fine because the timer can only fire in | ||
9 | the same AioContext. | ||
10 | |||
11 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
12 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
13 | Message-id: 20210517100548.28806-7-pbonzini@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
10 | --- | 15 | --- |
11 | block/vhdx.c | 26 +++++++++++++++++++++++++- | 16 | include/qemu/coroutine.h | 5 +++++ |
12 | 1 file changed, 25 insertions(+), 1 deletion(-) | 17 | util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++------- |
18 | 2 files changed, 24 insertions(+), 7 deletions(-) | ||
13 | 19 | ||
14 | diff --git a/block/vhdx.c b/block/vhdx.c | 20 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h |
15 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/block/vhdx.c | 22 | --- a/include/qemu/coroutine.h |
17 | +++ b/block/vhdx.c | 23 | +++ b/include/qemu/coroutine.h |
18 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vhdx_co_check(BlockDriverState *bs, | 24 | @@ -XXX,XX +XXX,XX @@ typedef struct QemuCoSleep { |
19 | return 0; | 25 | void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, |
26 | QEMUClockType type, int64_t ns); | ||
27 | |||
28 | +/** | ||
29 | + * Yield the coroutine until the next call to qemu_co_sleep_wake. | ||
30 | + */ | ||
31 | +void coroutine_fn qemu_co_sleep(QemuCoSleep *w); | ||
32 | + | ||
33 | static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
34 | { | ||
35 | QemuCoSleep w = { 0 }; | ||
36 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/util/qemu-coroutine-sleep.c | ||
39 | +++ b/util/qemu-coroutine-sleep.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque) | ||
41 | qemu_co_sleep_wake(w); | ||
20 | } | 42 | } |
21 | 43 | ||
22 | +static int vhdx_has_zero_init(BlockDriverState *bs) | 44 | -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, |
45 | - QEMUClockType type, int64_t ns) | ||
46 | +void coroutine_fn qemu_co_sleep(QemuCoSleep *w) | ||
47 | { | ||
48 | Coroutine *co = qemu_coroutine_self(); | ||
49 | - AioContext *ctx = qemu_get_current_aio_context(); | ||
50 | - QEMUTimer ts; | ||
51 | |||
52 | const char *scheduled = qatomic_cmpxchg(&co->scheduled, NULL, | ||
53 | qemu_co_sleep_ns__scheduled); | ||
54 | @@ -XXX,XX +XXX,XX @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | ||
55 | } | ||
56 | |||
57 | w->to_wake = co; | ||
58 | - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), | ||
59 | - timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
60 | qemu_coroutine_yield(); | ||
61 | - timer_del(&ts); | ||
62 | |||
63 | /* w->to_wake is cleared before resuming this coroutine. */ | ||
64 | assert(w->to_wake == NULL); | ||
65 | } | ||
66 | + | ||
67 | +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, | ||
68 | + QEMUClockType type, int64_t ns) | ||
23 | +{ | 69 | +{ |
24 | + BDRVVHDXState *s = bs->opaque; | 70 | + AioContext *ctx = qemu_get_current_aio_context(); |
25 | + int state; | 71 | + QEMUTimer ts; |
72 | + | ||
73 | + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w); | ||
74 | + timer_mod(&ts, qemu_clock_get_ns(type) + ns); | ||
26 | + | 75 | + |
27 | + /* | 76 | + /* |
28 | + * Check the subformat: Fixed images have all BAT entries present, | 77 | + * The timer will fire in the current AiOContext, so the callback |
29 | + * dynamic images have none (right after creation). It is | 78 | + * must happen after qemu_co_sleep yields and there is no race |
30 | + * therefore enough to check the first BAT entry. | 79 | + * between timer_mod and qemu_co_sleep. |
31 | + */ | 80 | + */ |
32 | + if (!s->bat_entries) { | 81 | + qemu_co_sleep(w); |
33 | + return 1; | 82 | + timer_del(&ts); |
34 | + } | ||
35 | + | ||
36 | + state = s->bat[0] & VHDX_BAT_STATE_BIT_MASK; | ||
37 | + if (state == PAYLOAD_BLOCK_FULLY_PRESENT) { | ||
38 | + /* Fixed subformat */ | ||
39 | + return bdrv_has_zero_init(bs->file->bs); | ||
40 | + } | ||
41 | + | ||
42 | + /* Dynamic subformat */ | ||
43 | + return 1; | ||
44 | +} | 83 | +} |
45 | + | ||
46 | static QemuOptsList vhdx_create_opts = { | ||
47 | .name = "vhdx-create-opts", | ||
48 | .head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head), | ||
49 | @@ -XXX,XX +XXX,XX @@ static BlockDriver bdrv_vhdx = { | ||
50 | .bdrv_co_create_opts = vhdx_co_create_opts, | ||
51 | .bdrv_get_info = vhdx_get_info, | ||
52 | .bdrv_co_check = vhdx_co_check, | ||
53 | - .bdrv_has_zero_init = bdrv_has_zero_init_1, | ||
54 | + .bdrv_has_zero_init = vhdx_has_zero_init, | ||
55 | |||
56 | .create_opts = &vhdx_create_opts, | ||
57 | }; | ||
58 | -- | 84 | -- |
59 | 2.21.0 | 85 | 2.31.1 |
60 | 86 | ||
61 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Add a test case for converting an empty image (which only returns zeroes | ||
2 | when read) to a preallocated encrypted qcow2 image. | ||
3 | qcow2_has_zero_init() should return 0 then, thus forcing qemu-img | ||
4 | convert to create zero clusters. | ||
5 | 1 | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Acked-by: Stefano Garzarella <sgarzare@redhat.com> | ||
8 | Tested-by: Stefano Garzarella <sgarzare@redhat.com> | ||
9 | Message-id: 20190724171239.8764-10-mreitz@redhat.com | ||
10 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
11 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
12 | --- | ||
13 | tests/qemu-iotests/188 | 20 +++++++++++++++++++- | ||
14 | tests/qemu-iotests/188.out | 4 ++++ | ||
15 | 2 files changed, 23 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/188 b/tests/qemu-iotests/188 | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/188 | ||
20 | +++ b/tests/qemu-iotests/188 | ||
21 | @@ -XXX,XX +XXX,XX @@ SECRETALT="secret,id=sec0,data=platypus" | ||
22 | |||
23 | _make_test_img --object $SECRET -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size | ||
24 | |||
25 | -IMGSPEC="driver=$IMGFMT,file.filename=$TEST_IMG,encrypt.key-secret=sec0" | ||
26 | +IMGSPEC="driver=$IMGFMT,encrypt.key-secret=sec0,file.filename=$TEST_IMG" | ||
27 | |||
28 | QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT | ||
29 | |||
30 | @@ -XXX,XX +XXX,XX @@ echo | ||
31 | echo "== verify open failure with wrong password ==" | ||
32 | $QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir | ||
33 | |||
34 | +_cleanup_test_img | ||
35 | + | ||
36 | +echo | ||
37 | +echo "== verify that has_zero_init returns false when preallocating ==" | ||
38 | + | ||
39 | +# Empty source file | ||
40 | +if [ -n "$TEST_IMG_FILE" ]; then | ||
41 | + TEST_IMG_FILE="${TEST_IMG_FILE}.orig" _make_test_img $size | ||
42 | +else | ||
43 | + TEST_IMG="${TEST_IMG}.orig" _make_test_img $size | ||
44 | +fi | ||
45 | + | ||
46 | +$QEMU_IMG convert -O "$IMGFMT" --object $SECRET \ | ||
47 | + -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10,preallocation=metadata" \ | ||
48 | + "${TEST_IMG}.orig" "$TEST_IMG" | ||
49 | + | ||
50 | +$QEMU_IMG compare --object $SECRET --image-opts "${IMGSPEC}.orig" "$IMGSPEC" | ||
51 | + | ||
52 | |||
53 | # success, all done | ||
54 | echo "*** done" | ||
55 | diff --git a/tests/qemu-iotests/188.out b/tests/qemu-iotests/188.out | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/tests/qemu-iotests/188.out | ||
58 | +++ b/tests/qemu-iotests/188.out | ||
59 | @@ -XXX,XX +XXX,XX @@ read 16777216/16777216 bytes at offset 0 | ||
60 | |||
61 | == verify open failure with wrong password == | ||
62 | qemu-io: can't open: Invalid password, cannot unlock any keyslot | ||
63 | + | ||
64 | +== verify that has_zero_init returns false when preallocating == | ||
65 | +Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=16777216 | ||
66 | +Images are identical. | ||
67 | *** done | ||
68 | -- | ||
69 | 2.21.0 | ||
70 | |||
71 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
2 | Message-id: 20190724171239.8764-11-mreitz@redhat.com | ||
3 | Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> | ||
4 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
5 | --- | ||
6 | tests/qemu-iotests/122 | 17 +++++++++++++++++ | ||
7 | tests/qemu-iotests/122.out | 8 ++++++++ | ||
8 | 2 files changed, 25 insertions(+) | ||
9 | 1 | ||
10 | diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122 | ||
11 | index XXXXXXX..XXXXXXX 100755 | ||
12 | --- a/tests/qemu-iotests/122 | ||
13 | +++ b/tests/qemu-iotests/122 | ||
14 | @@ -XXX,XX +XXX,XX @@ for min_sparse in 4k 8k; do | ||
15 | $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map | ||
16 | done | ||
17 | |||
18 | + | ||
19 | +echo | ||
20 | +echo '=== -n to a non-zero image ===' | ||
21 | +echo | ||
22 | + | ||
23 | +# Keep source zero | ||
24 | +_make_test_img 64M | ||
25 | + | ||
26 | +# Output is not zero, but has bdrv_has_zero_init() == 1 | ||
27 | +TEST_IMG="$TEST_IMG".orig _make_test_img 64M | ||
28 | +$QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io | ||
29 | + | ||
30 | +# Convert with -n, which should not assume that the target is zeroed | ||
31 | +$QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig | ||
32 | + | ||
33 | +$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig | ||
34 | + | ||
35 | # success, all done | ||
36 | echo '*** done' | ||
37 | rm -f $seq.full | ||
38 | diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/tests/qemu-iotests/122.out | ||
41 | +++ b/tests/qemu-iotests/122.out | ||
42 | @@ -XXX,XX +XXX,XX @@ convert -c -S 8k | ||
43 | { "start": 9216, "length": 8192, "depth": 0, "zero": true, "data": false}, | ||
44 | { "start": 17408, "length": 1024, "depth": 0, "zero": false, "data": true}, | ||
45 | { "start": 18432, "length": 67090432, "depth": 0, "zero": true, "data": false}] | ||
46 | + | ||
47 | +=== -n to a non-zero image === | ||
48 | + | ||
49 | +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 | ||
50 | +Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864 | ||
51 | +wrote 65536/65536 bytes at offset 0 | ||
52 | +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) | ||
53 | +Images are identical. | ||
54 | *** done | ||
55 | -- | ||
56 | 2.21.0 | ||
57 | |||
58 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | The result of a sync=full mirror should always be the equal to the | ||
2 | input. Therefore, existing images should be treated as potentially | ||
3 | non-zero and thus should be explicitly initialized to be zero | ||
4 | beforehand. | ||
5 | 1 | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | Message-id: 20190724171239.8764-12-mreitz@redhat.com | ||
8 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
9 | --- | ||
10 | tests/qemu-iotests/041 | 62 +++++++++++++++++++++++++++++++++++--- | ||
11 | tests/qemu-iotests/041.out | 4 +-- | ||
12 | 2 files changed, 60 insertions(+), 6 deletions(-) | ||
13 | |||
14 | diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 | ||
15 | index XXXXXXX..XXXXXXX 100755 | ||
16 | --- a/tests/qemu-iotests/041 | ||
17 | +++ b/tests/qemu-iotests/041 | ||
18 | @@ -XXX,XX +XXX,XX @@ class TestUnbackedSource(iotests.QMPTestCase): | ||
19 | def setUp(self): | ||
20 | qemu_img('create', '-f', iotests.imgfmt, test_img, | ||
21 | str(TestUnbackedSource.image_len)) | ||
22 | - self.vm = iotests.VM().add_drive(test_img) | ||
23 | + self.vm = iotests.VM() | ||
24 | self.vm.launch() | ||
25 | + result = self.vm.qmp('blockdev-add', node_name='drive0', | ||
26 | + driver=iotests.imgfmt, | ||
27 | + file={ | ||
28 | + 'driver': 'file', | ||
29 | + 'filename': test_img, | ||
30 | + }) | ||
31 | + self.assert_qmp(result, 'return', {}) | ||
32 | |||
33 | def tearDown(self): | ||
34 | self.vm.shutdown() | ||
35 | @@ -XXX,XX +XXX,XX @@ class TestUnbackedSource(iotests.QMPTestCase): | ||
36 | |||
37 | def test_absolute_paths_full(self): | ||
38 | self.assert_no_active_block_jobs() | ||
39 | - result = self.vm.qmp('drive-mirror', device='drive0', | ||
40 | + result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0', | ||
41 | sync='full', target=target_img, | ||
42 | mode='absolute-paths') | ||
43 | self.assert_qmp(result, 'return', {}) | ||
44 | @@ -XXX,XX +XXX,XX @@ class TestUnbackedSource(iotests.QMPTestCase): | ||
45 | |||
46 | def test_absolute_paths_top(self): | ||
47 | self.assert_no_active_block_jobs() | ||
48 | - result = self.vm.qmp('drive-mirror', device='drive0', | ||
49 | + result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0', | ||
50 | sync='top', target=target_img, | ||
51 | mode='absolute-paths') | ||
52 | self.assert_qmp(result, 'return', {}) | ||
53 | @@ -XXX,XX +XXX,XX @@ class TestUnbackedSource(iotests.QMPTestCase): | ||
54 | |||
55 | def test_absolute_paths_none(self): | ||
56 | self.assert_no_active_block_jobs() | ||
57 | - result = self.vm.qmp('drive-mirror', device='drive0', | ||
58 | + result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0', | ||
59 | sync='none', target=target_img, | ||
60 | mode='absolute-paths') | ||
61 | self.assert_qmp(result, 'return', {}) | ||
62 | self.complete_and_wait() | ||
63 | self.assert_no_active_block_jobs() | ||
64 | |||
65 | + def test_existing_full(self): | ||
66 | + qemu_img('create', '-f', iotests.imgfmt, target_img, | ||
67 | + str(self.image_len)) | ||
68 | + qemu_io('-c', 'write -P 42 0 64k', target_img) | ||
69 | + | ||
70 | + self.assert_no_active_block_jobs() | ||
71 | + result = self.vm.qmp('drive-mirror', job_id='drive0', device='drive0', | ||
72 | + sync='full', target=target_img, mode='existing') | ||
73 | + self.assert_qmp(result, 'return', {}) | ||
74 | + self.complete_and_wait() | ||
75 | + self.assert_no_active_block_jobs() | ||
76 | + | ||
77 | + result = self.vm.qmp('blockdev-del', node_name='drive0') | ||
78 | + self.assert_qmp(result, 'return', {}) | ||
79 | + | ||
80 | + self.assertTrue(iotests.compare_images(test_img, target_img), | ||
81 | + 'target image does not match source after mirroring') | ||
82 | + | ||
83 | + def test_blockdev_full(self): | ||
84 | + qemu_img('create', '-f', iotests.imgfmt, target_img, | ||
85 | + str(self.image_len)) | ||
86 | + qemu_io('-c', 'write -P 42 0 64k', target_img) | ||
87 | + | ||
88 | + result = self.vm.qmp('blockdev-add', node_name='target', | ||
89 | + driver=iotests.imgfmt, | ||
90 | + file={ | ||
91 | + 'driver': 'file', | ||
92 | + 'filename': target_img, | ||
93 | + }) | ||
94 | + self.assert_qmp(result, 'return', {}) | ||
95 | + | ||
96 | + self.assert_no_active_block_jobs() | ||
97 | + result = self.vm.qmp('blockdev-mirror', job_id='drive0', device='drive0', | ||
98 | + sync='full', target='target') | ||
99 | + self.assert_qmp(result, 'return', {}) | ||
100 | + self.complete_and_wait() | ||
101 | + self.assert_no_active_block_jobs() | ||
102 | + | ||
103 | + result = self.vm.qmp('blockdev-del', node_name='drive0') | ||
104 | + self.assert_qmp(result, 'return', {}) | ||
105 | + | ||
106 | + result = self.vm.qmp('blockdev-del', node_name='target') | ||
107 | + self.assert_qmp(result, 'return', {}) | ||
108 | + | ||
109 | + self.assertTrue(iotests.compare_images(test_img, target_img), | ||
110 | + 'target image does not match source after mirroring') | ||
111 | + | ||
112 | class TestGranularity(iotests.QMPTestCase): | ||
113 | image_len = 10 * 1024 * 1024 # MB | ||
114 | |||
115 | diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/tests/qemu-iotests/041.out | ||
118 | +++ b/tests/qemu-iotests/041.out | ||
119 | @@ -XXX,XX +XXX,XX @@ | ||
120 | -........................................................................................ | ||
121 | +.......................................................................................... | ||
122 | ---------------------------------------------------------------------- | ||
123 | -Ran 88 tests | ||
124 | +Ran 90 tests | ||
125 | |||
126 | OK | ||
127 | -- | ||
128 | 2.21.0 | ||
129 | |||
130 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Fixes: 69f47505ee66afaa513305de0c1895a224e52c45 | ||
2 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
3 | Message-id: 20190725155512.9827-3-mreitz@redhat.com | ||
4 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
5 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
6 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
7 | --- | ||
8 | block/vmdk.c | 3 +++ | ||
9 | 1 file changed, 3 insertions(+) | ||
10 | 1 | ||
11 | diff --git a/block/vmdk.c b/block/vmdk.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/block/vmdk.c | ||
14 | +++ b/block/vmdk.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn vmdk_co_block_status(BlockDriverState *bs, | ||
16 | if (!extent->compressed) { | ||
17 | ret |= BDRV_BLOCK_OFFSET_VALID; | ||
18 | *map = cluster_offset + index_in_cluster; | ||
19 | + if (extent->flat) { | ||
20 | + ret |= BDRV_BLOCK_RECURSE; | ||
21 | + } | ||
22 | } | ||
23 | *file = extent->file->bs; | ||
24 | break; | ||
25 | -- | ||
26 | 2.21.0 | ||
27 | |||
28 | diff view generated by jsdifflib |