1 | The following changes since commit e47f81b617684c4546af286d307b69014a83538a: | 1 | The following changes since commit 754f756cc4c6d9d14b7230c62b5bb20f9d655888: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2019-02-07 18:53:25 +0000) | 3 | Merge tag 'pull-target-arm-20220422-1' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-04-22 08:03:18 -0700) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/hreitz/qemu.git tags/pull-block-2022-04-25 |
8 | 8 | ||
9 | for you to fetch changes up to 55140166667bb555c5d05165b93b25557d2e6397: | 9 | for you to fetch changes up to 348a0740afc5b313599533eb69bbb2b95d2f1bba: |
10 | 10 | ||
11 | tests/virtio-blk: add test for WRITE_ZEROES command (2019-02-11 11:58:17 +0800) | 11 | iotests/108: Fix when missing user_allow_other (2022-04-25 14:46:45 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Block patches: |
15 | 15 | - New @force parameter for blockdev-change-medium | |
16 | User-visible changes: | 16 | - Improvements to the iotests to help with debugging |
17 | 17 | - Fix iotest 108 on systems without user_allow_other in fuse.conf | |
18 | * virtio-blk: DISCARD and WRITE_ZEROES support | ||
19 | 18 | ||
20 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
20 | Denis V. Lunev (1): | ||
21 | block: add 'force' parameter to 'blockdev-change-medium' command | ||
21 | 22 | ||
22 | Peter Xu (1): | 23 | Hanna Reitz (1): |
23 | iothread: fix iothread hang when stop too soon | 24 | iotests/108: Fix when missing user_allow_other |
24 | 25 | ||
25 | Stefano Garzarella (7): | 26 | John Snow (12): |
26 | virtio-blk: cleanup using VirtIOBlock *s and VirtIODevice *vdev | 27 | iotests: replace calls to log(qemu_io(...)) with qemu_io_log() |
27 | virtio-blk: add acct_failed param to virtio_blk_handle_rw_error() | 28 | iotests/163: Fix broken qemu-io invocation |
28 | virtio-blk: add host_features field in VirtIOBlock | 29 | iotests: Don't check qemu_io() output for specific error strings |
29 | virtio-blk: add "discard" and "write-zeroes" properties | 30 | iotests/040: Don't check image pattern on zero-length image |
30 | virtio-blk: add DISCARD and WRITE_ZEROES features | 31 | iotests/040: Fix TestCommitWithFilters test |
31 | tests/virtio-blk: change assert on data_size in virtio_blk_request() | 32 | iotests: create generic qemu_tool() function |
32 | tests/virtio-blk: add test for WRITE_ZEROES command | 33 | iotests: rebase qemu_io() on top of qemu_tool() |
34 | iotests/migration-permissions: use assertRaises() for qemu_io() | ||
35 | negative test | ||
36 | iotests/image-fleecing: switch to qemu_io() | ||
37 | iotests: remove qemu_io_pipe_and_status() | ||
38 | iotests: remove qemu_io_silent() and qemu_io_silent_check(). | ||
39 | iotests: make qemu_io_log() check return codes by default | ||
33 | 40 | ||
34 | Vladimir Sementsov-Ogievskiy (1): | 41 | qapi/block.json | 6 ++ |
35 | qemugdb/coroutine: fix arch_prctl has unknown return type | 42 | block/qapi-sysemu.c | 3 +- |
36 | 43 | monitor/hmp-cmds.c | 4 +- | |
37 | include/hw/virtio/virtio-blk.h | 5 +- | 44 | hmp-commands.hx | 11 ++- |
38 | hw/block/virtio-blk.c | 236 +++++++++++++++++++++++++++++---- | 45 | tests/qemu-iotests/030 | 85 +++++++++++-------- |
39 | hw/core/machine.c | 2 + | 46 | tests/qemu-iotests/040 | 53 +++++++----- |
40 | iothread.c | 6 +- | 47 | tests/qemu-iotests/056 | 2 +- |
41 | tests/virtio-blk-test.c | 75 ++++++++++- | 48 | tests/qemu-iotests/108 | 2 +- |
42 | scripts/qemugdb/coroutine.py | 2 +- | 49 | tests/qemu-iotests/149 | 6 +- |
43 | 6 files changed, 297 insertions(+), 29 deletions(-) | 50 | tests/qemu-iotests/163 | 5 +- |
51 | tests/qemu-iotests/205 | 4 +- | ||
52 | tests/qemu-iotests/216 | 12 +-- | ||
53 | tests/qemu-iotests/218 | 5 +- | ||
54 | tests/qemu-iotests/224 | 4 +- | ||
55 | tests/qemu-iotests/242 | 6 +- | ||
56 | tests/qemu-iotests/245 | 17 ++-- | ||
57 | tests/qemu-iotests/255 | 4 +- | ||
58 | tests/qemu-iotests/258 | 11 ++- | ||
59 | tests/qemu-iotests/298 | 17 ++-- | ||
60 | tests/qemu-iotests/303 | 4 +- | ||
61 | tests/qemu-iotests/310 | 22 ++--- | ||
62 | tests/qemu-iotests/iotests.py | 69 ++++++++------- | ||
63 | tests/qemu-iotests/tests/image-fleecing | 30 ++++--- | ||
64 | .../qemu-iotests/tests/migration-permissions | 28 +++--- | ||
65 | .../tests/mirror-ready-cancel-error | 2 +- | ||
66 | .../qemu-iotests/tests/nbd-reconnect-on-open | 2 +- | ||
67 | .../qemu-iotests/tests/stream-error-on-reset | 4 +- | ||
68 | ui/cocoa.m | 1 + | ||
69 | 28 files changed, 231 insertions(+), 188 deletions(-) | ||
44 | 70 | ||
45 | -- | 71 | -- |
46 | 2.20.1 | 72 | 2.35.1 |
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: "Denis V. Lunev" <den@openvz.org> |
---|---|---|---|
2 | 2 | ||
3 | We add acct_failed param in order to use virtio_blk_handle_rw_error() | 3 | 'blockdev-change-medium' is a convinient wrapper for the following |
4 | also when is not required to call block_acct_failed(). (eg. a discard | 4 | sequence of commands: |
5 | operation is failed) | 5 | * blockdev-open-tray |
6 | * blockdev-remove-medium | ||
7 | * blockdev-insert-medium | ||
8 | * blockdev-close-tray | ||
9 | and should be used f.e. to change ISO image inside the CD-ROM tray. | ||
10 | Though the guest could lock the tray and some linux guests like | ||
11 | CentOS 8.5 actually does that. In this case the execution if this | ||
12 | command results in the error like the following: | ||
13 | Device 'scsi0-0-1-0' is locked and force was not specified, | ||
14 | wait for tray to open and try again. | ||
6 | 15 | ||
7 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 16 | This situation is could be resolved 'blockdev-open-tray' by passing |
8 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 17 | flag 'force' inside. Thus is seems reasonable to add the same |
9 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 18 | capability for 'blockdev-change-medium' too. |
10 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | 19 | |
11 | Message-id: 20190208134950.187665-2-sgarzare@redhat.com | 20 | Signed-off-by: Denis V. Lunev <den@openvz.org> |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 21 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> |
22 | Acked-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com> | ||
23 | CC: Kevin Wolf <kwolf@redhat.com> | ||
24 | CC: Hanna Reitz <hreitz@redhat.com> | ||
25 | CC: Eric Blake <eblake@redhat.com> | ||
26 | CC: Markus Armbruster <armbru@redhat.com> | ||
27 | Message-Id: <20220412221846.280723-1-den@openvz.org> | ||
28 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
29 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | 30 | --- |
14 | hw/block/virtio-blk.c | 10 ++++++---- | 31 | qapi/block.json | 6 ++++++ |
15 | 1 file changed, 6 insertions(+), 4 deletions(-) | 32 | block/qapi-sysemu.c | 3 ++- |
33 | monitor/hmp-cmds.c | 4 +++- | ||
34 | hmp-commands.hx | 11 +++++++---- | ||
35 | ui/cocoa.m | 1 + | ||
36 | 5 files changed, 19 insertions(+), 6 deletions(-) | ||
16 | 37 | ||
17 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 38 | diff --git a/qapi/block.json b/qapi/block.json |
18 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/block/virtio-blk.c | 40 | --- a/qapi/block.json |
20 | +++ b/hw/block/virtio-blk.c | 41 | +++ b/qapi/block.json |
21 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) | 42 | @@ -XXX,XX +XXX,XX @@ |
22 | } | 43 | # @read-only-mode: change the read-only mode of the device; defaults |
23 | 44 | # to 'retain' | |
24 | static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, | 45 | # |
25 | - bool is_read) | 46 | +# @force: if false (the default), an eject request through blockdev-open-tray |
26 | + bool is_read, bool acct_failed) | 47 | +# will be sent to the guest if it has locked the tray (and the tray |
27 | { | 48 | +# will not be opened immediately); if true, the tray will be opened |
28 | VirtIOBlock *s = req->dev; | 49 | +# regardless of whether it is locked. (since 7.1) |
29 | BlockErrorAction action = blk_get_error_action(s->blk, is_read, error); | 50 | +# |
30 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, | 51 | # Features: |
31 | s->rq = req; | 52 | # @deprecated: Member @device is deprecated. Use @id instead. |
32 | } else if (action == BLOCK_ERROR_ACTION_REPORT) { | 53 | # |
33 | virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); | 54 | @@ -XXX,XX +XXX,XX @@ |
34 | - block_acct_failed(blk_get_stats(s->blk), &req->acct); | 55 | '*id': 'str', |
35 | + if (acct_failed) { | 56 | 'filename': 'str', |
36 | + block_acct_failed(blk_get_stats(s->blk), &req->acct); | 57 | '*format': 'str', |
37 | + } | 58 | + '*force': 'bool', |
38 | virtio_blk_free_request(req); | 59 | '*read-only-mode': 'BlockdevChangeReadOnlyMode' } } |
60 | |||
61 | |||
62 | diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/block/qapi-sysemu.c | ||
65 | +++ b/block/qapi-sysemu.c | ||
66 | @@ -XXX,XX +XXX,XX @@ void qmp_blockdev_change_medium(bool has_device, const char *device, | ||
67 | bool has_id, const char *id, | ||
68 | const char *filename, | ||
69 | bool has_format, const char *format, | ||
70 | + bool has_force, bool force, | ||
71 | bool has_read_only, | ||
72 | BlockdevChangeReadOnlyMode read_only, | ||
73 | Error **errp) | ||
74 | @@ -XXX,XX +XXX,XX @@ void qmp_blockdev_change_medium(bool has_device, const char *device, | ||
75 | |||
76 | rc = do_open_tray(has_device ? device : NULL, | ||
77 | has_id ? id : NULL, | ||
78 | - false, &err); | ||
79 | + force, &err); | ||
80 | if (rc && rc != -ENOSYS) { | ||
81 | error_propagate(errp, err); | ||
82 | goto fail; | ||
83 | diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/monitor/hmp-cmds.c | ||
86 | +++ b/monitor/hmp-cmds.c | ||
87 | @@ -XXX,XX +XXX,XX @@ void hmp_change(Monitor *mon, const QDict *qdict) | ||
88 | const char *target = qdict_get_str(qdict, "target"); | ||
89 | const char *arg = qdict_get_try_str(qdict, "arg"); | ||
90 | const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); | ||
91 | + bool force = qdict_get_try_bool(qdict, "force", false); | ||
92 | BlockdevChangeReadOnlyMode read_only_mode = 0; | ||
93 | Error *err = NULL; | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ void hmp_change(Monitor *mon, const QDict *qdict) | ||
96 | } | ||
97 | |||
98 | qmp_blockdev_change_medium(true, device, false, NULL, target, | ||
99 | - !!arg, arg, !!read_only, read_only_mode, | ||
100 | + !!arg, arg, true, force, | ||
101 | + !!read_only, read_only_mode, | ||
102 | &err); | ||
39 | } | 103 | } |
40 | 104 | ||
41 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_rw_complete(void *opaque, int ret) | 105 | diff --git a/hmp-commands.hx b/hmp-commands.hx |
42 | * the memory until the request is completed (which will | 106 | index XXXXXXX..XXXXXXX 100644 |
43 | * happen on the other side of the migration). | 107 | --- a/hmp-commands.hx |
44 | */ | 108 | +++ b/hmp-commands.hx |
45 | - if (virtio_blk_handle_rw_error(req, -ret, is_read)) { | 109 | @@ -XXX,XX +XXX,XX @@ ERST |
46 | + if (virtio_blk_handle_rw_error(req, -ret, is_read, true)) { | 110 | |
47 | continue; | 111 | { |
48 | } | 112 | .name = "change", |
49 | } | 113 | - .args_type = "device:B,target:F,arg:s?,read-only-mode:s?", |
50 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_flush_complete(void *opaque, int ret) | 114 | - .params = "device filename [format [read-only-mode]]", |
51 | 115 | - .help = "change a removable medium, optional format", | |
52 | aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); | 116 | + .args_type = "device:B,force:-f,target:F,arg:s?,read-only-mode:s?", |
53 | if (ret) { | 117 | + .params = "device [-f] filename [format [read-only-mode]]", |
54 | - if (virtio_blk_handle_rw_error(req, -ret, 0)) { | 118 | + .help = "change a removable medium, optional format, use -f to force the operation", |
55 | + if (virtio_blk_handle_rw_error(req, -ret, 0, true)) { | 119 | .cmd = hmp_change, |
56 | goto out; | 120 | }, |
57 | } | 121 | |
58 | } | 122 | @@ -XXX,XX +XXX,XX @@ SRST |
123 | ``change`` *device* *setting* | ||
124 | Change the configuration of a device. | ||
125 | |||
126 | - ``change`` *diskdevice* *filename* [*format* [*read-only-mode*]] | ||
127 | + ``change`` *diskdevice* [-f] *filename* [*format* [*read-only-mode*]] | ||
128 | Change the medium for a removable disk device to point to *filename*. eg:: | ||
129 | |||
130 | (qemu) change ide1-cd0 /path/to/some.iso | ||
131 | |||
132 | + ``-f`` | ||
133 | + forces the operation even if the guest has locked the tray. | ||
134 | + | ||
135 | *format* is optional. | ||
136 | |||
137 | *read-only-mode* may be used to change the read-only status of the device. | ||
138 | diff --git a/ui/cocoa.m b/ui/cocoa.m | ||
139 | index XXXXXXX..XXXXXXX 100644 | ||
140 | --- a/ui/cocoa.m | ||
141 | +++ b/ui/cocoa.m | ||
142 | @@ -XXX,XX +XXX,XX @@ - (void)changeDeviceMedia:(id)sender | ||
143 | [file cStringUsingEncoding: | ||
144 | NSASCIIStringEncoding], | ||
145 | true, "raw", | ||
146 | + true, false, | ||
147 | false, 0, | ||
148 | &err); | ||
149 | }); | ||
59 | -- | 150 | -- |
60 | 2.20.1 | 151 | 2.35.1 |
61 | 152 | ||
62 | 153 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | This makes these callsites a little simpler, but the real motivation is | ||
4 | a forthcoming commit will change the return type of qemu_io(), so removing | ||
5 | users of the return value now is helpful. | ||
6 | |||
7 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
9 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | Message-Id: <20220418211504.943969-2-jsnow@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | ||
13 | tests/qemu-iotests/242 | 6 +++--- | ||
14 | tests/qemu-iotests/255 | 4 +--- | ||
15 | tests/qemu-iotests/303 | 4 ++-- | ||
16 | 3 files changed, 6 insertions(+), 8 deletions(-) | ||
17 | |||
18 | diff --git a/tests/qemu-iotests/242 b/tests/qemu-iotests/242 | ||
19 | index XXXXXXX..XXXXXXX 100755 | ||
20 | --- a/tests/qemu-iotests/242 | ||
21 | +++ b/tests/qemu-iotests/242 | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | import iotests | ||
24 | import json | ||
25 | import struct | ||
26 | -from iotests import qemu_img_create, qemu_io, qemu_img_info, \ | ||
27 | - file_path, img_info_log, log, filter_qemu_io | ||
28 | +from iotests import qemu_img_create, qemu_io_log, qemu_img_info, \ | ||
29 | + file_path, img_info_log, log | ||
30 | |||
31 | iotests.script_initialize(supported_fmts=['qcow2'], | ||
32 | supported_protocols=['file'], | ||
33 | @@ -XXX,XX +XXX,XX @@ def add_bitmap(bitmap_number, persistent, disabled): | ||
34 | |||
35 | def write_to_disk(offset, size): | ||
36 | write = 'write {} {}'.format(offset, size) | ||
37 | - log(qemu_io('-c', write, disk), filters=[filter_qemu_io]) | ||
38 | + qemu_io_log('-c', write, disk) | ||
39 | |||
40 | |||
41 | def toggle_flag(offset): | ||
42 | diff --git a/tests/qemu-iotests/255 b/tests/qemu-iotests/255 | ||
43 | index XXXXXXX..XXXXXXX 100755 | ||
44 | --- a/tests/qemu-iotests/255 | ||
45 | +++ b/tests/qemu-iotests/255 | ||
46 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('src.qcow2') as src_path, \ | ||
47 | iotests.qemu_img_create('-f', iotests.imgfmt, src_path, size_str) | ||
48 | iotests.qemu_img_create('-f', iotests.imgfmt, dst_path, size_str) | ||
49 | |||
50 | - iotests.log(iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 1M', | ||
51 | - src_path), | ||
52 | - filters=[iotests.filter_test_dir, iotests.filter_qemu_io]) | ||
53 | + iotests.qemu_io_log('-f', iotests.imgfmt, '-c', 'write 0 1M', src_path), | ||
54 | |||
55 | vm.add_object('throttle-group,x-bps-read=4096,id=throttle0') | ||
56 | |||
57 | diff --git a/tests/qemu-iotests/303 b/tests/qemu-iotests/303 | ||
58 | index XXXXXXX..XXXXXXX 100755 | ||
59 | --- a/tests/qemu-iotests/303 | ||
60 | +++ b/tests/qemu-iotests/303 | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | |||
63 | import iotests | ||
64 | import subprocess | ||
65 | -from iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_io, \ | ||
66 | +from iotests import qemu_img_create, qemu_io_log, file_path, log, \ | ||
67 | verify_qcow2_zstd_compression | ||
68 | |||
69 | iotests.script_initialize(supported_fmts=['qcow2'], | ||
70 | @@ -XXX,XX +XXX,XX @@ def create_bitmap(bitmap_number, disabled): | ||
71 | |||
72 | def write_to_disk(offset, size): | ||
73 | write = f'write {offset} {size}' | ||
74 | - log(qemu_io('-c', write, disk), filters=[filter_qemu_io]) | ||
75 | + qemu_io_log('-c', write, disk) | ||
76 | |||
77 | |||
78 | def add_bitmap(num, begin, end, disabled): | ||
79 | -- | ||
80 | 2.35.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | The 'read' commands to qemu-io were malformed, and this invocation only | ||
4 | worked by coincidence because the error messages were identical. Oops. | ||
5 | |||
6 | There's no point in checking the patterning of the reference image, so | ||
7 | just check the empty image by itself instead. | ||
8 | |||
9 | (Note: as of this commit, nothing actually enforces that this command | ||
10 | completes successfully, but a forthcoming commit in this series will | ||
11 | enforce that qemu_io() must have a zero status code.) | ||
12 | |||
13 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
14 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
15 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | Message-Id: <20220418211504.943969-3-jsnow@redhat.com> | ||
17 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
18 | --- | ||
19 | tests/qemu-iotests/163 | 5 +---- | ||
20 | 1 file changed, 1 insertion(+), 4 deletions(-) | ||
21 | |||
22 | diff --git a/tests/qemu-iotests/163 b/tests/qemu-iotests/163 | ||
23 | index XXXXXXX..XXXXXXX 100755 | ||
24 | --- a/tests/qemu-iotests/163 | ||
25 | +++ b/tests/qemu-iotests/163 | ||
26 | @@ -XXX,XX +XXX,XX @@ class ShrinkBaseClass(iotests.QMPTestCase): | ||
27 | qemu_img('resize', '-f', iotests.imgfmt, '--shrink', test_img, | ||
28 | self.shrink_size) | ||
29 | |||
30 | - self.assertEqual( | ||
31 | - qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, test_img), | ||
32 | - qemu_io('-c', 'read -P 0x00 %s'%self.shrink_size, check_img), | ||
33 | - "Verifying image content") | ||
34 | + qemu_io('-c', f"read -P 0x00 0 {self.shrink_size}", test_img) | ||
35 | |||
36 | self.image_verify() | ||
37 | |||
38 | -- | ||
39 | 2.35.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | A forthcoming commit updates qemu_io() to raise an exception on non-zero | ||
4 | return by default, and changes its return type. | ||
5 | |||
6 | In preparation, simplify some calls to qemu_io() that assert that | ||
7 | specific error message strings do not appear in qemu-io's | ||
8 | output. Asserting that all of these calls return a status code of zero | ||
9 | will be a more robust way to guard against failure. | ||
10 | |||
11 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
13 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
14 | Message-Id: <20220418211504.943969-4-jsnow@redhat.com> | ||
15 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
16 | --- | ||
17 | tests/qemu-iotests/040 | 33 ++++++++++++++++----------------- | ||
18 | tests/qemu-iotests/056 | 2 +- | ||
19 | 2 files changed, 17 insertions(+), 18 deletions(-) | ||
20 | |||
21 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 | ||
22 | index XXXXXXX..XXXXXXX 100755 | ||
23 | --- a/tests/qemu-iotests/040 | ||
24 | +++ b/tests/qemu-iotests/040 | ||
25 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
26 | |||
27 | def test_commit(self): | ||
28 | self.run_commit_test(mid_img, backing_img) | ||
29 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) | ||
30 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) | ||
31 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
32 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
33 | |||
34 | def test_commit_node(self): | ||
35 | self.run_commit_test("mid", "base", node_names=True) | ||
36 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) | ||
37 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) | ||
38 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
39 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
40 | |||
41 | @iotests.skip_if_unsupported(['throttle']) | ||
42 | def test_commit_with_filter_and_quit(self): | ||
43 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
44 | |||
45 | def test_top_is_active(self): | ||
46 | self.run_commit_test(test_img, backing_img, need_ready=True) | ||
47 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) | ||
48 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) | ||
49 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
50 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
51 | |||
52 | def test_top_is_default_active(self): | ||
53 | self.run_default_commit_test() | ||
54 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img).find("verification failed")) | ||
55 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img).find("verification failed")) | ||
56 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
57 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
58 | |||
59 | def test_top_and_base_reversed(self): | ||
60 | self.assert_no_active_block_jobs() | ||
61 | @@ -XXX,XX +XXX,XX @@ class TestRelativePaths(ImageCommitTestCase): | ||
62 | |||
63 | def test_commit(self): | ||
64 | self.run_commit_test(self.mid_img, self.backing_img) | ||
65 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs).find("verification failed")) | ||
66 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed")) | ||
67 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs) | ||
68 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs) | ||
69 | |||
70 | def test_device_not_found(self): | ||
71 | result = self.vm.qmp('block-commit', device='nonexistent', top='%s' % self.mid_img) | ||
72 | @@ -XXX,XX +XXX,XX @@ class TestRelativePaths(ImageCommitTestCase): | ||
73 | |||
74 | def test_top_is_active(self): | ||
75 | self.run_commit_test(self.test_img, self.backing_img) | ||
76 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs).find("verification failed")) | ||
77 | - self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs).find("verification failed")) | ||
78 | + qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', self.backing_img_abs) | ||
79 | + qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', self.backing_img_abs) | ||
80 | |||
81 | def test_top_and_base_reversed(self): | ||
82 | self.assert_no_active_block_jobs() | ||
83 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): | ||
84 | |||
85 | def do_test_io(self, read_or_write): | ||
86 | for index, pattern_file in enumerate(self.pattern_files): | ||
87 | - result = qemu_io('-f', iotests.imgfmt, | ||
88 | - '-c', | ||
89 | - f'{read_or_write} -P {index + 1} {index}M 1M', | ||
90 | - pattern_file) | ||
91 | - self.assertFalse('Pattern verification failed' in result) | ||
92 | + qemu_io('-f', iotests.imgfmt, | ||
93 | + '-c', | ||
94 | + f'{read_or_write} -P {index + 1} {index}M 1M', | ||
95 | + pattern_file) | ||
96 | |||
97 | @iotests.skip_if_unsupported(['throttle']) | ||
98 | def setUp(self): | ||
99 | diff --git a/tests/qemu-iotests/056 b/tests/qemu-iotests/056 | ||
100 | index XXXXXXX..XXXXXXX 100755 | ||
101 | --- a/tests/qemu-iotests/056 | ||
102 | +++ b/tests/qemu-iotests/056 | ||
103 | @@ -XXX,XX +XXX,XX @@ class TestSyncModesNoneAndTop(iotests.QMPTestCase): | ||
104 | |||
105 | self.vm.shutdown() | ||
106 | time.sleep(1) | ||
107 | - self.assertEqual(-1, qemu_io('-c', 'read -P0x41 0 512', target_img).find("verification failed")) | ||
108 | + qemu_io('-c', 'read -P0x41 0 512', target_img) | ||
109 | |||
110 | class TestBeforeWriteNotifier(iotests.QMPTestCase): | ||
111 | def setUp(self): | ||
112 | -- | ||
113 | 2.35.1 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | This patch adds the support of DISCARD and WRITE_ZEROES commands, | 3 | qemu-io fails on read/write beyond end-of-file on raw images, so skip |
4 | that have been introduced in the virtio-blk protocol to have | 4 | these invocations when running the zero-length image tests. |
5 | better performance when using SSD backend. | ||
6 | 5 | ||
7 | We support only one segment per request since multiple segments | 6 | Signed-off-by: John Snow <jsnow@redhat.com> |
8 | are not widely used and there are no userspace APIs that allow | 7 | Reviewed-by: Eric Blake <eblake@redhat.com> |
9 | applications to submit multiple segments in a single call. | 8 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
9 | Message-Id: <20220418211504.943969-5-jsnow@redhat.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/040 | 14 ++++++++++++-- | ||
13 | 1 file changed, 12 insertions(+), 2 deletions(-) | ||
10 | 14 | ||
11 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 15 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 |
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 16 | index XXXXXXX..XXXXXXX 100755 |
13 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 17 | --- a/tests/qemu-iotests/040 |
14 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | 18 | +++ b/tests/qemu-iotests/040 |
15 | Message-id: 20190208134950.187665-5-sgarzare@redhat.com | 19 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): |
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 20 | qemu_img('create', '-f', iotests.imgfmt, |
17 | --- | 21 | '-o', 'backing_file=%s' % mid_img, |
18 | include/hw/virtio/virtio-blk.h | 2 + | 22 | '-F', iotests.imgfmt, test_img) |
19 | hw/block/virtio-blk.c | 184 +++++++++++++++++++++++++++++++++ | 23 | - qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) |
20 | 2 files changed, 186 insertions(+) | 24 | - qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) |
21 | 25 | + if self.image_len: | |
22 | diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h | 26 | + qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) |
23 | index XXXXXXX..XXXXXXX 100644 | 27 | + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', |
24 | --- a/include/hw/virtio/virtio-blk.h | 28 | + mid_img) |
25 | +++ b/include/hw/virtio/virtio-blk.h | 29 | self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none") |
26 | @@ -XXX,XX +XXX,XX @@ struct VirtIOBlkConf | 30 | self.vm.add_device('virtio-scsi') |
27 | uint32_t request_merging; | 31 | self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") |
28 | uint16_t num_queues; | 32 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): |
29 | uint16_t queue_size; | 33 | |
30 | + uint32_t max_discard_sectors; | 34 | def test_commit(self): |
31 | + uint32_t max_write_zeroes_sectors; | 35 | self.run_commit_test(mid_img, backing_img) |
32 | }; | 36 | + if not self.image_len: |
33 | 37 | + return | |
34 | struct VirtIOBlockDataPlane; | 38 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) |
35 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 39 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) |
36 | index XXXXXXX..XXXXXXX 100644 | 40 | |
37 | --- a/hw/block/virtio-blk.c | 41 | def test_commit_node(self): |
38 | +++ b/hw/block/virtio-blk.c | 42 | self.run_commit_test("mid", "base", node_names=True) |
39 | @@ -XXX,XX +XXX,XX @@ out: | 43 | + if not self.image_len: |
40 | aio_context_release(blk_get_aio_context(s->conf.conf.blk)); | 44 | + return |
41 | } | 45 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) |
42 | 46 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | |
43 | +static void virtio_blk_discard_write_zeroes_complete(void *opaque, int ret) | 47 | |
44 | +{ | 48 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): |
45 | + VirtIOBlockReq *req = opaque; | 49 | |
46 | + VirtIOBlock *s = req->dev; | 50 | def test_top_is_active(self): |
47 | + bool is_write_zeroes = (virtio_ldl_p(VIRTIO_DEVICE(s), &req->out.type) & | 51 | self.run_commit_test(test_img, backing_img, need_ready=True) |
48 | + ~VIRTIO_BLK_T_BARRIER) == VIRTIO_BLK_T_WRITE_ZEROES; | 52 | + if not self.image_len: |
49 | + | 53 | + return |
50 | + aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); | 54 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) |
51 | + if (ret) { | 55 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) |
52 | + if (virtio_blk_handle_rw_error(req, -ret, false, is_write_zeroes)) { | 56 | |
53 | + goto out; | 57 | def test_top_is_default_active(self): |
54 | + } | 58 | self.run_default_commit_test() |
55 | + } | 59 | + if not self.image_len: |
56 | + | 60 | + return |
57 | + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); | 61 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) |
58 | + if (is_write_zeroes) { | 62 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) |
59 | + block_acct_done(blk_get_stats(s->blk), &req->acct); | ||
60 | + } | ||
61 | + virtio_blk_free_request(req); | ||
62 | + | ||
63 | +out: | ||
64 | + aio_context_release(blk_get_aio_context(s->conf.conf.blk)); | ||
65 | +} | ||
66 | + | ||
67 | #ifdef __linux__ | ||
68 | |||
69 | typedef struct { | ||
70 | @@ -XXX,XX +XXX,XX @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, | ||
71 | return true; | ||
72 | } | ||
73 | |||
74 | +static uint8_t virtio_blk_handle_discard_write_zeroes(VirtIOBlockReq *req, | ||
75 | + struct virtio_blk_discard_write_zeroes *dwz_hdr, bool is_write_zeroes) | ||
76 | +{ | ||
77 | + VirtIOBlock *s = req->dev; | ||
78 | + VirtIODevice *vdev = VIRTIO_DEVICE(s); | ||
79 | + uint64_t sector; | ||
80 | + uint32_t num_sectors, flags, max_sectors; | ||
81 | + uint8_t err_status; | ||
82 | + int bytes; | ||
83 | + | ||
84 | + sector = virtio_ldq_p(vdev, &dwz_hdr->sector); | ||
85 | + num_sectors = virtio_ldl_p(vdev, &dwz_hdr->num_sectors); | ||
86 | + flags = virtio_ldl_p(vdev, &dwz_hdr->flags); | ||
87 | + max_sectors = is_write_zeroes ? s->conf.max_write_zeroes_sectors : | ||
88 | + s->conf.max_discard_sectors; | ||
89 | + | ||
90 | + /* | ||
91 | + * max_sectors is at most BDRV_REQUEST_MAX_SECTORS, this check | ||
92 | + * make us sure that "num_sectors << BDRV_SECTOR_BITS" can fit in | ||
93 | + * the integer variable. | ||
94 | + */ | ||
95 | + if (unlikely(num_sectors > max_sectors)) { | ||
96 | + err_status = VIRTIO_BLK_S_IOERR; | ||
97 | + goto err; | ||
98 | + } | ||
99 | + | ||
100 | + bytes = num_sectors << BDRV_SECTOR_BITS; | ||
101 | + | ||
102 | + if (unlikely(!virtio_blk_sect_range_ok(s, sector, bytes))) { | ||
103 | + err_status = VIRTIO_BLK_S_IOERR; | ||
104 | + goto err; | ||
105 | + } | ||
106 | + | ||
107 | + /* | ||
108 | + * The device MUST set the status byte to VIRTIO_BLK_S_UNSUPP for discard | ||
109 | + * and write zeroes commands if any unknown flag is set. | ||
110 | + */ | ||
111 | + if (unlikely(flags & ~VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP)) { | ||
112 | + err_status = VIRTIO_BLK_S_UNSUPP; | ||
113 | + goto err; | ||
114 | + } | ||
115 | + | ||
116 | + if (is_write_zeroes) { /* VIRTIO_BLK_T_WRITE_ZEROES */ | ||
117 | + int blk_aio_flags = 0; | ||
118 | + | ||
119 | + if (flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP) { | ||
120 | + blk_aio_flags |= BDRV_REQ_MAY_UNMAP; | ||
121 | + } | ||
122 | + | ||
123 | + block_acct_start(blk_get_stats(s->blk), &req->acct, bytes, | ||
124 | + BLOCK_ACCT_WRITE); | ||
125 | + | ||
126 | + blk_aio_pwrite_zeroes(s->blk, sector << BDRV_SECTOR_BITS, | ||
127 | + bytes, blk_aio_flags, | ||
128 | + virtio_blk_discard_write_zeroes_complete, req); | ||
129 | + } else { /* VIRTIO_BLK_T_DISCARD */ | ||
130 | + /* | ||
131 | + * The device MUST set the status byte to VIRTIO_BLK_S_UNSUPP for | ||
132 | + * discard commands if the unmap flag is set. | ||
133 | + */ | ||
134 | + if (unlikely(flags & VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP)) { | ||
135 | + err_status = VIRTIO_BLK_S_UNSUPP; | ||
136 | + goto err; | ||
137 | + } | ||
138 | + | ||
139 | + blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, bytes, | ||
140 | + virtio_blk_discard_write_zeroes_complete, req); | ||
141 | + } | ||
142 | + | ||
143 | + return VIRTIO_BLK_S_OK; | ||
144 | + | ||
145 | +err: | ||
146 | + if (is_write_zeroes) { | ||
147 | + block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_WRITE); | ||
148 | + } | ||
149 | + return err_status; | ||
150 | +} | ||
151 | + | ||
152 | static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) | ||
153 | { | ||
154 | uint32_t type; | ||
155 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) | ||
156 | virtio_blk_free_request(req); | ||
157 | break; | ||
158 | } | ||
159 | + /* | ||
160 | + * VIRTIO_BLK_T_DISCARD and VIRTIO_BLK_T_WRITE_ZEROES are defined with | ||
161 | + * VIRTIO_BLK_T_OUT flag set. We masked this flag in the switch statement, | ||
162 | + * so we must mask it for these requests, then we will check if it is set. | ||
163 | + */ | ||
164 | + case VIRTIO_BLK_T_DISCARD & ~VIRTIO_BLK_T_OUT: | ||
165 | + case VIRTIO_BLK_T_WRITE_ZEROES & ~VIRTIO_BLK_T_OUT: | ||
166 | + { | ||
167 | + struct virtio_blk_discard_write_zeroes dwz_hdr; | ||
168 | + size_t out_len = iov_size(out_iov, out_num); | ||
169 | + bool is_write_zeroes = (type & ~VIRTIO_BLK_T_BARRIER) == | ||
170 | + VIRTIO_BLK_T_WRITE_ZEROES; | ||
171 | + uint8_t err_status; | ||
172 | + | ||
173 | + /* | ||
174 | + * Unsupported if VIRTIO_BLK_T_OUT is not set or the request contains | ||
175 | + * more than one segment. | ||
176 | + */ | ||
177 | + if (unlikely(!(type & VIRTIO_BLK_T_OUT) || | ||
178 | + out_len > sizeof(dwz_hdr))) { | ||
179 | + virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); | ||
180 | + virtio_blk_free_request(req); | ||
181 | + return 0; | ||
182 | + } | ||
183 | + | ||
184 | + if (unlikely(iov_to_buf(out_iov, out_num, 0, &dwz_hdr, | ||
185 | + sizeof(dwz_hdr)) != sizeof(dwz_hdr))) { | ||
186 | + virtio_error(vdev, "virtio-blk discard/write_zeroes header" | ||
187 | + " too short"); | ||
188 | + return -1; | ||
189 | + } | ||
190 | + | ||
191 | + err_status = virtio_blk_handle_discard_write_zeroes(req, &dwz_hdr, | ||
192 | + is_write_zeroes); | ||
193 | + if (err_status != VIRTIO_BLK_S_OK) { | ||
194 | + virtio_blk_req_complete(req, err_status); | ||
195 | + virtio_blk_free_request(req); | ||
196 | + } | ||
197 | + | ||
198 | + break; | ||
199 | + } | ||
200 | default: | ||
201 | virtio_blk_req_complete(req, VIRTIO_BLK_S_UNSUPP); | ||
202 | virtio_blk_free_request(req); | ||
203 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) | ||
204 | blkcfg.alignment_offset = 0; | ||
205 | blkcfg.wce = blk_enable_write_cache(s->blk); | ||
206 | virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues); | ||
207 | + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD)) { | ||
208 | + virtio_stl_p(vdev, &blkcfg.max_discard_sectors, | ||
209 | + s->conf.max_discard_sectors); | ||
210 | + virtio_stl_p(vdev, &blkcfg.discard_sector_alignment, | ||
211 | + blk_size >> BDRV_SECTOR_BITS); | ||
212 | + /* | ||
213 | + * We support only one segment per request since multiple segments | ||
214 | + * are not widely used and there are no userspace APIs that allow | ||
215 | + * applications to submit multiple segments in a single call. | ||
216 | + */ | ||
217 | + virtio_stl_p(vdev, &blkcfg.max_discard_seg, 1); | ||
218 | + } | ||
219 | + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES)) { | ||
220 | + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_sectors, | ||
221 | + s->conf.max_write_zeroes_sectors); | ||
222 | + blkcfg.write_zeroes_may_unmap = 1; | ||
223 | + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); | ||
224 | + } | ||
225 | memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); | ||
226 | } | ||
227 | |||
228 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) | ||
229 | return; | ||
230 | } | ||
231 | |||
232 | + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && | ||
233 | + (!conf->max_discard_sectors || | ||
234 | + conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { | ||
235 | + error_setg(errp, "invalid max-discard-sectors property (%" PRIu32 ")" | ||
236 | + ", must be between 1 and %d", | ||
237 | + conf->max_discard_sectors, (int)BDRV_REQUEST_MAX_SECTORS); | ||
238 | + return; | ||
239 | + } | ||
240 | + | ||
241 | + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES) && | ||
242 | + (!conf->max_write_zeroes_sectors || | ||
243 | + conf->max_write_zeroes_sectors > BDRV_REQUEST_MAX_SECTORS)) { | ||
244 | + error_setg(errp, "invalid max-write-zeroes-sectors property (%" PRIu32 | ||
245 | + "), must be between 1 and %d", | ||
246 | + conf->max_write_zeroes_sectors, | ||
247 | + (int)BDRV_REQUEST_MAX_SECTORS); | ||
248 | + return; | ||
249 | + } | ||
250 | + | ||
251 | virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, | ||
252 | sizeof(struct virtio_blk_config)); | ||
253 | |||
254 | @@ -XXX,XX +XXX,XX @@ static Property virtio_blk_properties[] = { | ||
255 | VIRTIO_BLK_F_DISCARD, true), | ||
256 | DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features, | ||
257 | VIRTIO_BLK_F_WRITE_ZEROES, true), | ||
258 | + DEFINE_PROP_UINT32("max-discard-sectors", VirtIOBlock, | ||
259 | + conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS), | ||
260 | + DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock, | ||
261 | + conf.max_write_zeroes_sectors, BDRV_REQUEST_MAX_SECTORS), | ||
262 | DEFINE_PROP_END_OF_LIST(), | ||
263 | }; | ||
264 | 63 | ||
265 | -- | 64 | -- |
266 | 2.20.1 | 65 | 2.35.1 |
267 | |||
268 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In order to avoid migration issues, we enable DISCARD and | 3 | Without this change, asserting that qemu_io always returns 0 causes this |
4 | WRITE_ZEROES features only for machine type >= 4.0 | 4 | test to fail in a way we happened not to be catching previously: |
5 | 5 | ||
6 | As discussed with Michael S. Tsirkin and Stefan Hajnoczi on the | 6 | qemu.utils.VerboseProcessError: Command |
7 | list [1], DISCARD operation should not have security implications | 7 | '('/home/jsnow/src/qemu/bin/git/tests/qemu-iotests/../../qemu-io', |
8 | (eg. page cache attacks), so we can enable it by default. | 8 | '--cache', 'writeback', '--aio', 'threads', '-f', 'qcow2', '-c', |
9 | 'read -P 4 3M 1M', | ||
10 | '/home/jsnow/src/qemu/bin/git/tests/qemu-iotests/scratch/3.img')' | ||
11 | returned non-zero exit status 1. | ||
12 | ┏━ output ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
13 | ┃ qemu-io: can't open device | ||
14 | ┃ /home/jsnow/src/qemu/bin/git/tests/qemu-iotests/scratch/3.img: | ||
15 | ┃ Could not open backing file: Could not open backing file: Throttle | ||
16 | ┃ group 'tg' does not exist | ||
17 | ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
9 | 18 | ||
10 | [1] https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00504.html | 19 | The commit jobs changes the backing file string stored in the image file |
20 | header belonging to the node above the commit’s top node to point to the | ||
21 | commit target (the base node). QEMU tries to be as accurate as | ||
22 | possible, and so in these test cases will include the filter that is | ||
23 | part of the block graph in that backing file string (by virtue of making | ||
24 | it a json:{} description of the post-commit subgraph). This makes | ||
25 | little sense outside of QEMU, though: Specifically, the throttle node in | ||
26 | that subgraph will dearly miss its supposedly associated throttle group | ||
27 | object. | ||
11 | 28 | ||
12 | Suggested-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | 29 | When starting the commit job, we can specify a custom backing file |
13 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 30 | string to write into said image file, so let’s use that feature to write |
14 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 31 | the plain filename of the backing chain’s next actual image file there. |
15 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 32 | |
16 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | 33 | Explicitly provide the backing file so that opening the file outside of |
17 | Message-id: 20190208134950.187665-4-sgarzare@redhat.com | 34 | QEMU (Where we will not have throttle groups) will succeed. |
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 35 | |
36 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
37 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
38 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
39 | Message-Id: <20220418211504.943969-6-jsnow@redhat.com> | ||
19 | --- | 40 | --- |
20 | hw/block/virtio-blk.c | 4 ++++ | 41 | tests/qemu-iotests/040 | 6 ++++-- |
21 | hw/core/machine.c | 2 ++ | 42 | 1 file changed, 4 insertions(+), 2 deletions(-) |
22 | 2 files changed, 6 insertions(+) | ||
23 | 43 | ||
24 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 44 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 |
25 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100755 |
26 | --- a/hw/block/virtio-blk.c | 46 | --- a/tests/qemu-iotests/040 |
27 | +++ b/hw/block/virtio-blk.c | 47 | +++ b/tests/qemu-iotests/040 |
28 | @@ -XXX,XX +XXX,XX @@ static Property virtio_blk_properties[] = { | 48 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): |
29 | DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128), | 49 | job_id='commit', |
30 | DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, | 50 | device='top-filter', |
31 | IOThread *), | 51 | top_node='cow-2', |
32 | + DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features, | 52 | - base_node='cow-1') |
33 | + VIRTIO_BLK_F_DISCARD, true), | 53 | + base_node='cow-1', |
34 | + DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features, | 54 | + backing_file=self.img1) |
35 | + VIRTIO_BLK_F_WRITE_ZEROES, true), | 55 | self.assert_qmp(result, 'return', {}) |
36 | DEFINE_PROP_END_OF_LIST(), | 56 | self.wait_until_completed(drive='commit') |
37 | }; | 57 | |
38 | 58 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): | |
39 | diff --git a/hw/core/machine.c b/hw/core/machine.c | 59 | job_id='commit', |
40 | index XXXXXXX..XXXXXXX 100644 | 60 | device='top-filter', |
41 | --- a/hw/core/machine.c | 61 | top_node='cow-1', |
42 | +++ b/hw/core/machine.c | 62 | - base_node='cow-0') |
43 | @@ -XXX,XX +XXX,XX @@ GlobalProperty hw_compat_3_1[] = { | 63 | + base_node='cow-0', |
44 | { "usb-kbd", "serial", "42" }, | 64 | + backing_file=self.img0) |
45 | { "usb-mouse", "serial", "42" }, | 65 | self.assert_qmp(result, 'return', {}) |
46 | { "usb-kbd", "serial", "42" }, | 66 | self.wait_until_completed(drive='commit') |
47 | + { "virtio-blk-device", "discard", "false" }, | ||
48 | + { "virtio-blk-device", "write-zeroes", "false" }, | ||
49 | }; | ||
50 | const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1); | ||
51 | 67 | ||
52 | -- | 68 | -- |
53 | 2.20.1 | 69 | 2.35.1 |
54 | 70 | ||
55 | 71 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | reimplement qemu_img() in terms of qemu_tool() in preparation for doing | ||
4 | the same with qemu_io(). | ||
5 | |||
6 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
7 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
8 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
9 | Message-Id: <20220418211504.943969-7-jsnow@redhat.com> | ||
10 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | --- | ||
12 | tests/qemu-iotests/iotests.py | 32 +++++++++++++++++++++----------- | ||
13 | 1 file changed, 21 insertions(+), 11 deletions(-) | ||
14 | |||
15 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/tests/qemu-iotests/iotests.py | ||
18 | +++ b/tests/qemu-iotests/iotests.py | ||
19 | @@ -XXX,XX +XXX,XX @@ def qemu_img_create_prepare_args(args: List[str]) -> List[str]: | ||
20 | |||
21 | return result | ||
22 | |||
23 | -def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True | ||
24 | - ) -> 'subprocess.CompletedProcess[str]': | ||
25 | - """ | ||
26 | - Run qemu_img and return the status code and console output. | ||
27 | |||
28 | - This function always prepends QEMU_IMG_OPTIONS and may further alter | ||
29 | - the args for 'create' commands. | ||
30 | +def qemu_tool(*args: str, check: bool = True, combine_stdio: bool = True | ||
31 | + ) -> 'subprocess.CompletedProcess[str]': | ||
32 | + """ | ||
33 | + Run a qemu tool and return its status code and console output. | ||
34 | |||
35 | - :param args: command-line arguments to qemu-img. | ||
36 | + :param args: full command line to run. | ||
37 | :param check: Enforce a return code of zero. | ||
38 | :param combine_stdio: set to False to keep stdout/stderr separated. | ||
39 | |||
40 | @@ -XXX,XX +XXX,XX @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True | ||
41 | properties. If streams are not combined, it will also have a | ||
42 | stderr property. | ||
43 | """ | ||
44 | - full_args = qemu_img_args + qemu_img_create_prepare_args(list(args)) | ||
45 | - | ||
46 | subp = subprocess.run( | ||
47 | - full_args, | ||
48 | + args, | ||
49 | stdout=subprocess.PIPE, | ||
50 | stderr=subprocess.STDOUT if combine_stdio else subprocess.PIPE, | ||
51 | universal_newlines=True, | ||
52 | @@ -XXX,XX +XXX,XX @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True | ||
53 | |||
54 | if check and subp.returncode or (subp.returncode < 0): | ||
55 | raise VerboseProcessError( | ||
56 | - subp.returncode, full_args, | ||
57 | + subp.returncode, args, | ||
58 | output=subp.stdout, | ||
59 | stderr=subp.stderr, | ||
60 | ) | ||
61 | @@ -XXX,XX +XXX,XX @@ def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True | ||
62 | return subp | ||
63 | |||
64 | |||
65 | +def qemu_img(*args: str, check: bool = True, combine_stdio: bool = True | ||
66 | + ) -> 'subprocess.CompletedProcess[str]': | ||
67 | + """ | ||
68 | + Run QEMU_IMG_PROG and return its status code and console output. | ||
69 | + | ||
70 | + This function always prepends QEMU_IMG_OPTIONS and may further alter | ||
71 | + the args for 'create' commands. | ||
72 | + | ||
73 | + See `qemu_tool()` for greater detail. | ||
74 | + """ | ||
75 | + full_args = qemu_img_args + qemu_img_create_prepare_args(list(args)) | ||
76 | + return qemu_tool(*full_args, check=check, combine_stdio=combine_stdio) | ||
77 | + | ||
78 | + | ||
79 | def ordered_qmp(qmsg, conv_keys=True): | ||
80 | # Dictionaries are not ordered prior to 3.6, therefore: | ||
81 | if isinstance(qmsg, list): | ||
82 | -- | ||
83 | 2.35.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: John Snow <jsnow@redhat.com> | |
2 | |||
3 | Rework qemu_io() to be analogous to qemu_img(); a function that requires | ||
4 | a return code of zero by default unless disabled explicitly. | ||
5 | |||
6 | Tests that use qemu_io(): | ||
7 | 030 040 041 044 055 056 093 124 129 132 136 148 149 151 152 163 165 205 | ||
8 | 209 219 236 245 248 254 255 257 260 264 280 298 300 302 304 | ||
9 | image-fleecing migrate-bitmaps-postcopy-test migrate-bitmaps-test | ||
10 | migrate-during-backup migration-permissions | ||
11 | |||
12 | Test that use qemu_io_log(): | ||
13 | 242 245 255 274 303 307 nbd-reconnect-on-open | ||
14 | |||
15 | Copy-pastables for testing/verification: | ||
16 | |||
17 | ./check -qcow2 030 040 041 044 055 056 124 129 132 151 152 163 165 209 \ | ||
18 | 219 236 242 245 248 254 255 257 260 264 274 \ | ||
19 | 280 298 300 302 303 304 307 image-fleecing \ | ||
20 | migrate-bitmaps-postcopy-test migrate-bitmaps-test \ | ||
21 | migrate-during-backup nbd-reconnect-on-open | ||
22 | ./check -raw 093 136 148 migration-permissions | ||
23 | ./check -nbd 205 | ||
24 | |||
25 | # ./configure configure --disable-gnutls --enable-gcrypt | ||
26 | # this ALSO requires passwordless sudo. | ||
27 | ./check -luks 149 | ||
28 | |||
29 | # Just the tests that were edited in this commit: | ||
30 | ./check -qcow2 030 040 242 245 | ||
31 | ./check -raw migration-permissions | ||
32 | ./check -nbd 205 | ||
33 | ./check -luks 149 | ||
34 | |||
35 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
36 | Message-Id: <20220418211504.943969-8-jsnow@redhat.com> | ||
37 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
38 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
39 | --- | ||
40 | tests/qemu-iotests/030 | 85 +++++++++++-------- | ||
41 | tests/qemu-iotests/149 | 6 +- | ||
42 | tests/qemu-iotests/205 | 4 +- | ||
43 | tests/qemu-iotests/245 | 17 ++-- | ||
44 | tests/qemu-iotests/iotests.py | 19 +++-- | ||
45 | .../qemu-iotests/tests/migration-permissions | 4 +- | ||
46 | 6 files changed, 81 insertions(+), 54 deletions(-) | ||
47 | |||
48 | diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 | ||
49 | index XXXXXXX..XXXXXXX 100755 | ||
50 | --- a/tests/qemu-iotests/030 | ||
51 | +++ b/tests/qemu-iotests/030 | ||
52 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase): | ||
53 | self.assert_no_active_block_jobs() | ||
54 | self.vm.shutdown() | ||
55 | |||
56 | - self.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img), | ||
57 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), | ||
58 | - 'image file map does not match backing file after streaming') | ||
59 | + self.assertEqual( | ||
60 | + qemu_io('-f', 'raw', '-c', 'map', backing_img).stdout, | ||
61 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img).stdout, | ||
62 | + 'image file map does not match backing file after streaming') | ||
63 | |||
64 | def test_stream_intermediate(self): | ||
65 | self.assert_no_active_block_jobs() | ||
66 | |||
67 | - self.assertNotEqual(qemu_io('-f', 'raw', '-rU', '-c', 'map', backing_img), | ||
68 | - qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', mid_img), | ||
69 | - 'image file map matches backing file before streaming') | ||
70 | + self.assertNotEqual( | ||
71 | + qemu_io('-f', 'raw', '-rU', '-c', 'map', backing_img).stdout, | ||
72 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', mid_img).stdout, | ||
73 | + 'image file map matches backing file before streaming') | ||
74 | |||
75 | result = self.vm.qmp('block-stream', device='mid', job_id='stream-mid') | ||
76 | self.assert_qmp(result, 'return', {}) | ||
77 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase): | ||
78 | self.assert_no_active_block_jobs() | ||
79 | self.vm.shutdown() | ||
80 | |||
81 | - self.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img), | ||
82 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img), | ||
83 | - 'image file map does not match backing file after streaming') | ||
84 | + self.assertEqual( | ||
85 | + qemu_io('-f', 'raw', '-c', 'map', backing_img).stdout, | ||
86 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img).stdout, | ||
87 | + 'image file map does not match backing file after streaming') | ||
88 | |||
89 | def test_stream_pause(self): | ||
90 | self.assert_no_active_block_jobs() | ||
91 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase): | ||
92 | self.assert_no_active_block_jobs() | ||
93 | self.vm.shutdown() | ||
94 | |||
95 | - self.assertEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img), | ||
96 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), | ||
97 | - 'image file map does not match backing file after streaming') | ||
98 | + self.assertEqual( | ||
99 | + qemu_io('-f', 'raw', '-c', 'map', backing_img).stdout, | ||
100 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img).stdout, | ||
101 | + 'image file map does not match backing file after streaming') | ||
102 | |||
103 | def test_stream_no_op(self): | ||
104 | self.assert_no_active_block_jobs() | ||
105 | |||
106 | # The image map is empty before the operation | ||
107 | - empty_map = qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', test_img) | ||
108 | + empty_map = qemu_io( | ||
109 | + '-f', iotests.imgfmt, '-rU', '-c', 'map', test_img).stdout | ||
110 | |||
111 | # This is a no-op: no data should ever be copied from the base image | ||
112 | result = self.vm.qmp('block-stream', device='drive0', base=mid_img) | ||
113 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase): | ||
114 | self.assert_no_active_block_jobs() | ||
115 | self.vm.shutdown() | ||
116 | |||
117 | - self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), | ||
118 | - empty_map, 'image file map changed after a no-op') | ||
119 | + self.assertEqual( | ||
120 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img).stdout, | ||
121 | + empty_map, 'image file map changed after a no-op') | ||
122 | |||
123 | def test_stream_partial(self): | ||
124 | self.assert_no_active_block_jobs() | ||
125 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(iotests.QMPTestCase): | ||
126 | self.assert_no_active_block_jobs() | ||
127 | self.vm.shutdown() | ||
128 | |||
129 | - self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img), | ||
130 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img), | ||
131 | - 'image file map does not match backing file after streaming') | ||
132 | + self.assertEqual( | ||
133 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', mid_img).stdout, | ||
134 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img).stdout, | ||
135 | + 'image file map does not match backing file after streaming') | ||
136 | |||
137 | def test_device_not_found(self): | ||
138 | result = self.vm.qmp('block-stream', device='nonexistent') | ||
139 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
140 | |||
141 | # Check that the maps don't match before the streaming operations | ||
142 | for i in range(2, self.num_imgs, 2): | ||
143 | - self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i]), | ||
144 | - qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i-1]), | ||
145 | - 'image file map matches backing file before streaming') | ||
146 | + self.assertNotEqual( | ||
147 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i]).stdout, | ||
148 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[i-1]).stdout, | ||
149 | + 'image file map matches backing file before streaming') | ||
150 | |||
151 | # Create all streaming jobs | ||
152 | pending_jobs = [] | ||
153 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
154 | |||
155 | # Check that all maps match now | ||
156 | for i in range(2, self.num_imgs, 2): | ||
157 | - self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i]), | ||
158 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i-1]), | ||
159 | - 'image file map does not match backing file after streaming') | ||
160 | + self.assertEqual( | ||
161 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i]).stdout, | ||
162 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[i-1]).stdout, | ||
163 | + 'image file map does not match backing file after streaming') | ||
164 | |||
165 | # Test that it's not possible to perform two block-stream | ||
166 | # operations if there are nodes involved in both. | ||
167 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
168 | def test_stream_base_node_name(self): | ||
169 | self.assert_no_active_block_jobs() | ||
170 | |||
171 | - self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[4]), | ||
172 | - qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[3]), | ||
173 | - 'image file map matches backing file before streaming') | ||
174 | + self.assertNotEqual( | ||
175 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[4]).stdout, | ||
176 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.imgs[3]).stdout, | ||
177 | + 'image file map matches backing file before streaming') | ||
178 | |||
179 | # Error: the base node does not exist | ||
180 | result = self.vm.qmp('block-stream', device='node4', base_node='none', job_id='stream') | ||
181 | @@ -XXX,XX +XXX,XX @@ class TestParallelOps(iotests.QMPTestCase): | ||
182 | self.assert_no_active_block_jobs() | ||
183 | self.vm.shutdown() | ||
184 | |||
185 | - self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[4]), | ||
186 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[3]), | ||
187 | - 'image file map matches backing file after streaming') | ||
188 | + self.assertEqual( | ||
189 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[4]).stdout, | ||
190 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.imgs[3]).stdout, | ||
191 | + 'image file map matches backing file after streaming') | ||
192 | |||
193 | class TestQuorum(iotests.QMPTestCase): | ||
194 | num_children = 3 | ||
195 | @@ -XXX,XX +XXX,XX @@ class TestQuorum(iotests.QMPTestCase): | ||
196 | os.remove(img) | ||
197 | |||
198 | def test_stream_quorum(self): | ||
199 | - self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.children[0]), | ||
200 | - qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.backing[0]), | ||
201 | - 'image file map matches backing file before streaming') | ||
202 | + self.assertNotEqual( | ||
203 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.children[0]).stdout, | ||
204 | + qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', self.backing[0]).stdout, | ||
205 | + 'image file map matches backing file before streaming') | ||
206 | |||
207 | self.assert_no_active_block_jobs() | ||
208 | |||
209 | @@ -XXX,XX +XXX,XX @@ class TestQuorum(iotests.QMPTestCase): | ||
210 | self.assert_no_active_block_jobs() | ||
211 | self.vm.shutdown() | ||
212 | |||
213 | - self.assertEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', self.children[0]), | ||
214 | - qemu_io('-f', iotests.imgfmt, '-c', 'map', self.backing[0]), | ||
215 | - 'image file map does not match backing file after streaming') | ||
216 | + self.assertEqual( | ||
217 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.children[0]).stdout, | ||
218 | + qemu_io('-f', iotests.imgfmt, '-c', 'map', self.backing[0]).stdout, | ||
219 | + 'image file map does not match backing file after streaming') | ||
220 | |||
221 | class TestSmallerBackingFile(iotests.QMPTestCase): | ||
222 | backing_len = 1 * 1024 * 1024 # MB | ||
223 | diff --git a/tests/qemu-iotests/149 b/tests/qemu-iotests/149 | ||
224 | index XXXXXXX..XXXXXXX 100755 | ||
225 | --- a/tests/qemu-iotests/149 | ||
226 | +++ b/tests/qemu-iotests/149 | ||
227 | @@ -XXX,XX +XXX,XX @@ def qemu_io_write_pattern(config, pattern, offset_mb, size_mb, dev=False): | ||
228 | args = ["-c", "write -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)] | ||
229 | args.extend(qemu_io_image_args(config, dev)) | ||
230 | iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir]) | ||
231 | - iotests.log(check_cipher_support(config, iotests.qemu_io(*args)), | ||
232 | + output = iotests.qemu_io(*args, check=False).stdout | ||
233 | + iotests.log(check_cipher_support(config, output), | ||
234 | filters=[iotests.filter_test_dir, iotests.filter_qemu_io]) | ||
235 | |||
236 | |||
237 | @@ -XXX,XX +XXX,XX @@ def qemu_io_read_pattern(config, pattern, offset_mb, size_mb, dev=False): | ||
238 | args = ["-c", "read -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)] | ||
239 | args.extend(qemu_io_image_args(config, dev)) | ||
240 | iotests.log("qemu-io " + " ".join(args), filters=[iotests.filter_test_dir]) | ||
241 | - iotests.log(check_cipher_support(config, iotests.qemu_io(*args)), | ||
242 | + output = iotests.qemu_io(*args, check=False).stdout | ||
243 | + iotests.log(check_cipher_support(config, output), | ||
244 | filters=[iotests.filter_test_dir, iotests.filter_qemu_io]) | ||
245 | |||
246 | |||
247 | diff --git a/tests/qemu-iotests/205 b/tests/qemu-iotests/205 | ||
248 | index XXXXXXX..XXXXXXX 100755 | ||
249 | --- a/tests/qemu-iotests/205 | ||
250 | +++ b/tests/qemu-iotests/205 | ||
251 | @@ -XXX,XX +XXX,XX @@ class TestNbdServerRemove(iotests.QMPTestCase): | ||
252 | |||
253 | def do_test_connect_after_remove(self, mode=None): | ||
254 | args = ('-r', '-f', 'raw', '-c', 'read 0 512', nbd_uri) | ||
255 | - self.assertReadOk(qemu_io(*args)) | ||
256 | + self.assertReadOk(qemu_io(*args).stdout) | ||
257 | |||
258 | result = self.remove_export('exp', mode) | ||
259 | self.assert_qmp(result, 'return', {}) | ||
260 | |||
261 | self.assertExportNotFound('exp') | ||
262 | - self.assertConnectFailed(qemu_io(*args)) | ||
263 | + self.assertConnectFailed(qemu_io(*args, check=False).stdout) | ||
264 | |||
265 | def test_connect_after_remove_default(self): | ||
266 | self.do_test_connect_after_remove() | ||
267 | diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 | ||
268 | index XXXXXXX..XXXXXXX 100755 | ||
269 | --- a/tests/qemu-iotests/245 | ||
270 | +++ b/tests/qemu-iotests/245 | ||
271 | @@ -XXX,XX +XXX,XX @@ | ||
272 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
273 | # | ||
274 | |||
275 | +import copy | ||
276 | +import json | ||
277 | import os | ||
278 | import re | ||
279 | +from subprocess import CalledProcessError | ||
280 | + | ||
281 | import iotests | ||
282 | -import copy | ||
283 | -import json | ||
284 | from iotests import qemu_img, qemu_io | ||
285 | |||
286 | hd_path = [ | ||
287 | @@ -XXX,XX +XXX,XX @@ class TestBlockdevReopen(iotests.QMPTestCase): | ||
288 | |||
289 | # Reopen an image several times changing some of its options | ||
290 | def test_reopen(self): | ||
291 | - # Check whether the filesystem supports O_DIRECT | ||
292 | - if 'O_DIRECT' in qemu_io('-f', 'raw', '-t', 'none', '-c', 'quit', hd_path[0]): | ||
293 | - supports_direct = False | ||
294 | - else: | ||
295 | + try: | ||
296 | + qemu_io('-f', 'raw', '-t', 'none', '-c', 'quit', hd_path[0]) | ||
297 | supports_direct = True | ||
298 | + except CalledProcessError as exc: | ||
299 | + if 'O_DIRECT' in exc.stdout: | ||
300 | + supports_direct = False | ||
301 | + else: | ||
302 | + raise | ||
303 | |||
304 | # Open the hd1 image passing all backing options | ||
305 | opts = hd_opts(1) | ||
306 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
307 | index XXXXXXX..XXXXXXX 100644 | ||
308 | --- a/tests/qemu-iotests/iotests.py | ||
309 | +++ b/tests/qemu-iotests/iotests.py | ||
310 | @@ -XXX,XX +XXX,XX @@ def qemu_io_wrap_args(args: Sequence[str]) -> List[str]: | ||
311 | def qemu_io_popen(*args): | ||
312 | return qemu_tool_popen(qemu_io_wrap_args(args)) | ||
313 | |||
314 | -def qemu_io(*args): | ||
315 | - '''Run qemu-io and return the stdout data''' | ||
316 | - return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args))[0] | ||
317 | +def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True | ||
318 | + ) -> 'subprocess.CompletedProcess[str]': | ||
319 | + """ | ||
320 | + Run QEMU_IO_PROG and return the status code and console output. | ||
321 | + | ||
322 | + This function always prepends either QEMU_IO_OPTIONS or | ||
323 | + QEMU_IO_OPTIONS_NO_FMT. | ||
324 | + """ | ||
325 | + return qemu_tool(*qemu_io_wrap_args(args), | ||
326 | + check=check, combine_stdio=combine_stdio) | ||
327 | |||
328 | def qemu_io_pipe_and_status(*args): | ||
329 | return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args)) | ||
330 | |||
331 | -def qemu_io_log(*args): | ||
332 | - result = qemu_io(*args) | ||
333 | - log(result, filters=[filter_testfiles, filter_qemu_io]) | ||
334 | +def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': | ||
335 | + result = qemu_io(*args, check=False) | ||
336 | + log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) | ||
337 | return result | ||
338 | |||
339 | def qemu_io_silent(*args): | ||
340 | diff --git a/tests/qemu-iotests/tests/migration-permissions b/tests/qemu-iotests/tests/migration-permissions | ||
341 | index XXXXXXX..XXXXXXX 100755 | ||
342 | --- a/tests/qemu-iotests/tests/migration-permissions | ||
343 | +++ b/tests/qemu-iotests/tests/migration-permissions | ||
344 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): | ||
345 | def test_post_migration_permissions(self): | ||
346 | # Try to access the image R/W, which should fail because virtio-blk | ||
347 | # has not been configured with share-rw=on | ||
348 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img) | ||
349 | + log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout | ||
350 | if not log.strip(): | ||
351 | print('ERROR (pre-migration): qemu-io should not be able to ' | ||
352 | 'access this image, but it reported no error') | ||
353 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): | ||
354 | |||
355 | # Try the same qemu-io access again, verifying that the WRITE | ||
356 | # permission remains unshared | ||
357 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img) | ||
358 | + log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout | ||
359 | if not log.strip(): | ||
360 | print('ERROR (post-migration): qemu-io should not be able to ' | ||
361 | 'access this image, but it reported no error') | ||
362 | -- | ||
363 | 2.35.1 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | If the WRITE_ZEROES feature is enabled, we check this command | 3 | Modify this test to use assertRaises for its negative testing of |
4 | in the test_basic(). | 4 | qemu_io. If the exception raised does not match the one we tell it to |
5 | expect, we get *that* exception unhandled. If we get no exception, we | ||
6 | get a unittest assertion failure and the provided emsg printed to | ||
7 | screen. | ||
5 | 8 | ||
6 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 9 | If we get the CalledProcessError exception but the output is not what we |
7 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | expect, we re-raise the original CalledProcessError. |
8 | Acked-by: Thomas Huth <thuth@redhat.com> | 11 | |
9 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 12 | Tidy. |
10 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | 13 | |
11 | Message-id: 20190208134950.187665-7-sgarzare@redhat.com | 14 | (Note: Yes, you can reference "with" objects after that block ends; it |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 15 | just means that ctx.__exit__(...) will have been called on it. It does |
16 | not *actually* go out of scope. unittests expects you to want to inspect | ||
17 | the Exception object, so they leave it defined post-exit.) | ||
18 | |||
19 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
20 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
21 | Tested-by: Eric Blake <eblake@redhat.com> | ||
22 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
23 | Message-Id: <20220418211504.943969-9-jsnow@redhat.com> | ||
24 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | 25 | --- |
14 | tests/virtio-blk-test.c | 60 +++++++++++++++++++++++++++++++++++++++++ | 26 | .../qemu-iotests/tests/migration-permissions | 28 +++++++++---------- |
15 | 1 file changed, 60 insertions(+) | 27 | 1 file changed, 14 insertions(+), 14 deletions(-) |
16 | 28 | ||
17 | diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c | 29 | diff --git a/tests/qemu-iotests/tests/migration-permissions b/tests/qemu-iotests/tests/migration-permissions |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100755 |
19 | --- a/tests/virtio-blk-test.c | 31 | --- a/tests/qemu-iotests/tests/migration-permissions |
20 | +++ b/tests/virtio-blk-test.c | 32 | +++ b/tests/qemu-iotests/tests/migration-permissions |
21 | @@ -XXX,XX +XXX,XX @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc, | 33 | @@ -XXX,XX +XXX,XX @@ |
22 | 34 | # | |
23 | guest_free(alloc, req_addr); | 35 | |
24 | 36 | import os | |
25 | + if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) { | 37 | +from subprocess import CalledProcessError |
26 | + struct virtio_blk_discard_write_zeroes dwz_hdr; | ||
27 | + void *expected; | ||
28 | + | 38 | + |
29 | + /* | 39 | import iotests |
30 | + * WRITE_ZEROES request on the same sector of previous test where | 40 | from iotests import imgfmt, qemu_img_create, qemu_io |
31 | + * we wrote "TEST". | 41 | |
32 | + */ | 42 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): |
33 | + req.type = VIRTIO_BLK_T_WRITE_ZEROES; | 43 | def test_post_migration_permissions(self): |
34 | + req.data = (char *) &dwz_hdr; | 44 | # Try to access the image R/W, which should fail because virtio-blk |
35 | + dwz_hdr.sector = 0; | 45 | # has not been configured with share-rw=on |
36 | + dwz_hdr.num_sectors = 1; | 46 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout |
37 | + dwz_hdr.flags = 0; | 47 | - if not log.strip(): |
38 | + | 48 | - print('ERROR (pre-migration): qemu-io should not be able to ' |
39 | + req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr)); | 49 | - 'access this image, but it reported no error') |
40 | + | 50 | - else: |
41 | + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); | 51 | - # This is the expected output |
42 | + qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true); | 52 | - assert 'Is another process using the image' in log |
43 | + qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false); | 53 | + emsg = ('ERROR (pre-migration): qemu-io should not be able to ' |
44 | + | 54 | + 'access this image, but it reported no error') |
45 | + qvirtqueue_kick(dev, vq, free_head); | 55 | + with self.assertRaises(CalledProcessError, msg=emsg) as ctx: |
46 | + | 56 | + qemu_io('-f', imgfmt, '-c', 'quit', test_img) |
47 | + qvirtio_wait_used_elem(dev, vq, free_head, NULL, | 57 | + if 'Is another process using the image' not in ctx.exception.stdout: |
48 | + QVIRTIO_BLK_TIMEOUT_US); | 58 | + raise ctx.exception |
49 | + status = readb(req_addr + 16 + sizeof(dwz_hdr)); | 59 | |
50 | + g_assert_cmpint(status, ==, 0); | 60 | # Now migrate the VM |
51 | + | 61 | self.vm_s.qmp('migrate', uri=f'unix:{mig_sock}') |
52 | + guest_free(alloc, req_addr); | 62 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): |
53 | + | 63 | |
54 | + /* Read request to check if the sector contains all zeroes */ | 64 | # Try the same qemu-io access again, verifying that the WRITE |
55 | + req.type = VIRTIO_BLK_T_IN; | 65 | # permission remains unshared |
56 | + req.ioprio = 1; | 66 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout |
57 | + req.sector = 0; | 67 | - if not log.strip(): |
58 | + req.data = g_malloc0(512); | 68 | - print('ERROR (post-migration): qemu-io should not be able to ' |
59 | + | 69 | - 'access this image, but it reported no error') |
60 | + req_addr = virtio_blk_request(alloc, dev, &req, 512); | 70 | - else: |
61 | + | 71 | - # This is the expected output |
62 | + g_free(req.data); | 72 | - assert 'Is another process using the image' in log |
63 | + | 73 | + emsg = ('ERROR (post-migration): qemu-io should not be able to ' |
64 | + free_head = qvirtqueue_add(vq, req_addr, 16, false, true); | 74 | + 'access this image, but it reported no error') |
65 | + qvirtqueue_add(vq, req_addr + 16, 512, true, true); | 75 | + with self.assertRaises(CalledProcessError, msg=emsg) as ctx: |
66 | + qvirtqueue_add(vq, req_addr + 528, 1, true, false); | 76 | + qemu_io('-f', imgfmt, '-c', 'quit', test_img) |
67 | + | 77 | + if 'Is another process using the image' not in ctx.exception.stdout: |
68 | + qvirtqueue_kick(dev, vq, free_head); | 78 | + raise ctx.exception |
69 | + | 79 | |
70 | + qvirtio_wait_used_elem(dev, vq, free_head, NULL, | 80 | |
71 | + QVIRTIO_BLK_TIMEOUT_US); | 81 | if __name__ == '__main__': |
72 | + status = readb(req_addr + 528); | ||
73 | + g_assert_cmpint(status, ==, 0); | ||
74 | + | ||
75 | + data = g_malloc(512); | ||
76 | + expected = g_malloc0(512); | ||
77 | + memread(req_addr + 16, data, 512); | ||
78 | + g_assert_cmpmem(data, 512, expected, 512); | ||
79 | + g_free(expected); | ||
80 | + g_free(data); | ||
81 | + | ||
82 | + guest_free(alloc, req_addr); | ||
83 | + } | ||
84 | + | ||
85 | if (features & (1u << VIRTIO_F_ANY_LAYOUT)) { | ||
86 | /* Write and read with 2 descriptor layout */ | ||
87 | /* Write request */ | ||
88 | -- | 82 | -- |
89 | 2.20.1 | 83 | 2.35.1 |
90 | |||
91 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The size of data in the virtio_blk_request must be a multiple | 3 | This test expects failure ... but only sometimes. When? Why? |
4 | of 512 bytes for IN and OUT requests, or a multiple of the size | ||
5 | of struct virtio_blk_discard_write_zeroes for DISCARD and | ||
6 | WRITE_ZEROES requests. | ||
7 | 4 | ||
8 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | 5 | It's for reads of a region not defined by a bitmap. Adjust the test to |
9 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | 6 | be more explicit about what it expects to fail and why. |
10 | Reviewed-by: Thomas Huth <thuth@redhat.com> | 7 | |
11 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 8 | Signed-off-by: John Snow <jsnow@redhat.com> |
12 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | 9 | Reviewed-by: Eric Blake <eblake@redhat.com> |
13 | Message-id: 20190208134950.187665-6-sgarzare@redhat.com | 10 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> |
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Message-Id: <20220418211504.943969-10-jsnow@redhat.com> |
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
15 | --- | 13 | --- |
16 | tests/virtio-blk-test.c | 15 ++++++++++++++- | 14 | tests/qemu-iotests/tests/image-fleecing | 28 +++++++++++++++++-------- |
17 | 1 file changed, 14 insertions(+), 1 deletion(-) | 15 | 1 file changed, 19 insertions(+), 9 deletions(-) |
18 | 16 | ||
19 | diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c | 17 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing |
20 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100755 |
21 | --- a/tests/virtio-blk-test.c | 19 | --- a/tests/qemu-iotests/tests/image-fleecing |
22 | +++ b/tests/virtio-blk-test.c | 20 | +++ b/tests/qemu-iotests/tests/image-fleecing |
23 | @@ -XXX,XX +XXX,XX @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d, | 21 | @@ -XXX,XX +XXX,XX @@ |
24 | uint64_t addr; | 22 | # |
25 | uint8_t status = 0xFF; | 23 | # Creator/Owner: John Snow <jsnow@redhat.com> |
26 | 24 | ||
27 | - g_assert_cmpuint(data_size % 512, ==, 0); | 25 | +from subprocess import CalledProcessError |
28 | + switch (req->type) { | ||
29 | + case VIRTIO_BLK_T_IN: | ||
30 | + case VIRTIO_BLK_T_OUT: | ||
31 | + g_assert_cmpuint(data_size % 512, ==, 0); | ||
32 | + break; | ||
33 | + case VIRTIO_BLK_T_DISCARD: | ||
34 | + case VIRTIO_BLK_T_WRITE_ZEROES: | ||
35 | + g_assert_cmpuint(data_size % | ||
36 | + sizeof(struct virtio_blk_discard_write_zeroes), ==, 0); | ||
37 | + break; | ||
38 | + default: | ||
39 | + g_assert_cmpuint(data_size, ==, 0); | ||
40 | + } | ||
41 | + | 26 | + |
42 | addr = guest_alloc(alloc, sizeof(*req) + data_size); | 27 | import iotests |
43 | 28 | -from iotests import log, qemu_img, qemu_io, qemu_io_silent, \ | |
44 | virtio_blk_fix_request(d, req); | 29 | - qemu_io_pipe_and_status |
30 | +from iotests import log, qemu_img, qemu_io, qemu_io_silent | ||
31 | |||
32 | iotests.script_initialize( | ||
33 | supported_fmts=['qcow2'], | ||
34 | @@ -XXX,XX +XXX,XX @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, | ||
35 | for p in patterns + zeroes: | ||
36 | cmd = 'read -P%s %s %s' % p | ||
37 | log(cmd) | ||
38 | - out, ret = qemu_io_pipe_and_status('-r', '-f', 'raw', '-c', cmd, | ||
39 | - nbd_uri) | ||
40 | - if ret != 0: | ||
41 | - print(out) | ||
42 | + | ||
43 | + try: | ||
44 | + qemu_io('-r', '-f', 'raw', '-c', cmd, nbd_uri) | ||
45 | + except CalledProcessError as exc: | ||
46 | + if bitmap and p in zeroes: | ||
47 | + log(exc.stdout) | ||
48 | + else: | ||
49 | + raise | ||
50 | |||
51 | log('') | ||
52 | log('--- Testing COW ---') | ||
53 | @@ -XXX,XX +XXX,XX @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, | ||
54 | args += [target_img_path] | ||
55 | else: | ||
56 | args += ['-f', 'raw', nbd_uri] | ||
57 | - out, ret = qemu_io_pipe_and_status(*args) | ||
58 | - if ret != 0: | ||
59 | - print(out) | ||
60 | + | ||
61 | + try: | ||
62 | + qemu_io(*args) | ||
63 | + except CalledProcessError as exc: | ||
64 | + if bitmap and p in zeroes: | ||
65 | + log(exc.stdout) | ||
66 | + else: | ||
67 | + raise | ||
68 | |||
69 | log('') | ||
70 | log('--- Cleanup ---') | ||
45 | -- | 71 | -- |
46 | 2.20.1 | 72 | 2.35.1 |
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Since configurable features for virtio-blk are growing, this patch | 3 | I know we just added it, sorry. This is done in favor of qemu_io() which |
4 | adds host_features field in the struct VirtIOBlock. (as in virtio-net) | 4 | *also* returns the console output and status, but with more robust error |
5 | In this way, we can avoid to add new fields for new properties and | 5 | handling on failure. |
6 | we can directly set VIRTIO_BLK_F* flags in the host_features. | ||
7 | 6 | ||
8 | We update "config-wce" and "scsi" property definition to use the new | 7 | Signed-off-by: John Snow <jsnow@redhat.com> |
9 | host_features field without change the behaviour. | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> |
9 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
10 | Message-Id: <20220418211504.943969-11-jsnow@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | ||
13 | tests/qemu-iotests/iotests.py | 3 --- | ||
14 | 1 file changed, 3 deletions(-) | ||
10 | 15 | ||
11 | Suggested-by: Michael S. Tsirkin <mst@redhat.com> | 16 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py |
12 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | ||
14 | Acked-by: Pankaj Gupta <pagupta@redhat.com> | ||
15 | Message-id: 20190208134950.187665-3-sgarzare@redhat.com | ||
16 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | --- | ||
18 | include/hw/virtio/virtio-blk.h | 3 +-- | ||
19 | hw/block/virtio-blk.c | 16 +++++++++------- | ||
20 | 2 files changed, 10 insertions(+), 9 deletions(-) | ||
21 | |||
22 | diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/virtio/virtio-blk.h | 18 | --- a/tests/qemu-iotests/iotests.py |
25 | +++ b/include/hw/virtio/virtio-blk.h | 19 | +++ b/tests/qemu-iotests/iotests.py |
26 | @@ -XXX,XX +XXX,XX @@ struct VirtIOBlkConf | 20 | @@ -XXX,XX +XXX,XX @@ def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True |
27 | BlockConf conf; | 21 | return qemu_tool(*qemu_io_wrap_args(args), |
28 | IOThread *iothread; | 22 | check=check, combine_stdio=combine_stdio) |
29 | char *serial; | 23 | |
30 | - uint32_t scsi; | 24 | -def qemu_io_pipe_and_status(*args): |
31 | - uint32_t config_wce; | 25 | - return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args)) |
32 | uint32_t request_merging; | 26 | - |
33 | uint16_t num_queues; | 27 | def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
34 | uint16_t queue_size; | 28 | result = qemu_io(*args, check=False) |
35 | @@ -XXX,XX +XXX,XX @@ typedef struct VirtIOBlock { | 29 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) |
36 | bool dataplane_disabled; | ||
37 | bool dataplane_started; | ||
38 | struct VirtIOBlockDataPlane *dataplane; | ||
39 | + uint64_t host_features; | ||
40 | } VirtIOBlock; | ||
41 | |||
42 | typedef struct VirtIOBlockReq { | ||
43 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/hw/block/virtio-blk.c | ||
46 | +++ b/hw/block/virtio-blk.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req) | ||
48 | */ | ||
49 | scsi = (void *)elem->in_sg[elem->in_num - 2].iov_base; | ||
50 | |||
51 | - if (!blk->conf.scsi) { | ||
52 | + if (!virtio_has_feature(blk->host_features, VIRTIO_BLK_F_SCSI)) { | ||
53 | status = VIRTIO_BLK_S_UNSUPP; | ||
54 | goto fail; | ||
55 | } | ||
56 | @@ -XXX,XX +XXX,XX @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features, | ||
57 | { | ||
58 | VirtIOBlock *s = VIRTIO_BLK(vdev); | ||
59 | |||
60 | + /* Firstly sync all virtio-blk possible supported features */ | ||
61 | + features |= s->host_features; | ||
62 | + | ||
63 | virtio_add_feature(&features, VIRTIO_BLK_F_SEG_MAX); | ||
64 | virtio_add_feature(&features, VIRTIO_BLK_F_GEOMETRY); | ||
65 | virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY); | ||
66 | virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); | ||
67 | if (virtio_has_feature(features, VIRTIO_F_VERSION_1)) { | ||
68 | - if (s->conf.scsi) { | ||
69 | + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_SCSI)) { | ||
70 | error_setg(errp, "Please set scsi=off for virtio-blk devices in order to use virtio 1.0"); | ||
71 | return 0; | ||
72 | } | ||
73 | @@ -XXX,XX +XXX,XX @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features, | ||
74 | virtio_add_feature(&features, VIRTIO_BLK_F_SCSI); | ||
75 | } | ||
76 | |||
77 | - if (s->conf.config_wce) { | ||
78 | - virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE); | ||
79 | - } | ||
80 | if (blk_enable_write_cache(s->blk)) { | ||
81 | virtio_add_feature(&features, VIRTIO_BLK_F_WCE); | ||
82 | } | ||
83 | @@ -XXX,XX +XXX,XX @@ static Property virtio_blk_properties[] = { | ||
84 | DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf), | ||
85 | DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf), | ||
86 | DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial), | ||
87 | - DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true), | ||
88 | + DEFINE_PROP_BIT64("config-wce", VirtIOBlock, host_features, | ||
89 | + VIRTIO_BLK_F_CONFIG_WCE, true), | ||
90 | #ifdef __linux__ | ||
91 | - DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, false), | ||
92 | + DEFINE_PROP_BIT64("scsi", VirtIOBlock, host_features, | ||
93 | + VIRTIO_BLK_F_SCSI, false), | ||
94 | #endif | ||
95 | DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0, | ||
96 | true), | ||
97 | -- | 30 | -- |
98 | 2.20.1 | 31 | 2.35.1 |
99 | |||
100 | diff view generated by jsdifflib |
1 | From: Stefano Garzarella <sgarzare@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In several part we still using req->dev or VIRTIO_DEVICE(req->dev) | 3 | Like qemu-img, qemu-io returning 0 should be the norm and not the |
4 | when we have already defined s and vdev pointers: | 4 | exception. Remove all calls to qemu_io_silent that just assert the |
5 | VirtIOBlock *s = req->dev; | 5 | return code is zero (That's every last call, as it turns out), and |
6 | VirtIODevice *vdev = VIRTIO_DEVICE(s); | 6 | replace them with a normal qemu_io() call. |
7 | 7 | ||
8 | Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> | 8 | qemu_io_silent_check() appeared to have been unused already. |
9 | Reviewed-by: Liam Merwick <liam.merwick@oracle.com> | 9 | |
10 | Message-id: 20190208142347.214815-1-sgarzare@redhat.com | 10 | Signed-off-by: John Snow <jsnow@redhat.com> |
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 11 | Reviewed-by: Eric Blake <eblake@redhat.com> |
12 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | Message-Id: <20220418211504.943969-12-jsnow@redhat.com> | ||
14 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
12 | --- | 15 | --- |
13 | hw/block/virtio-blk.c | 22 +++++++++------------- | 16 | tests/qemu-iotests/216 | 12 +++++----- |
14 | 1 file changed, 9 insertions(+), 13 deletions(-) | 17 | tests/qemu-iotests/218 | 5 ++--- |
18 | tests/qemu-iotests/224 | 4 ++-- | ||
19 | tests/qemu-iotests/258 | 11 +++++----- | ||
20 | tests/qemu-iotests/298 | 17 ++++++-------- | ||
21 | tests/qemu-iotests/310 | 22 +++++++++---------- | ||
22 | tests/qemu-iotests/iotests.py | 16 -------------- | ||
23 | tests/qemu-iotests/tests/image-fleecing | 4 ++-- | ||
24 | .../tests/mirror-ready-cancel-error | 2 +- | ||
25 | .../qemu-iotests/tests/stream-error-on-reset | 4 ++-- | ||
26 | 10 files changed, 38 insertions(+), 59 deletions(-) | ||
15 | 27 | ||
16 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | 28 | diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216 |
29 | index XXXXXXX..XXXXXXX 100755 | ||
30 | --- a/tests/qemu-iotests/216 | ||
31 | +++ b/tests/qemu-iotests/216 | ||
32 | @@ -XXX,XX +XXX,XX @@ | ||
33 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> | ||
34 | |||
35 | import iotests | ||
36 | -from iotests import log, qemu_img, qemu_io_silent | ||
37 | +from iotests import log, qemu_img, qemu_io | ||
38 | |||
39 | # Need backing file support | ||
40 | iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'], | ||
41 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base.img') as base_img_path, \ | ||
42 | log('') | ||
43 | |||
44 | qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') | ||
45 | - assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0 | ||
46 | + qemu_io(base_img_path, '-c', 'write -P 1 0M 1M') | ||
47 | qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, | ||
48 | '-F', iotests.imgfmt, top_img_path) | ||
49 | - assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0 | ||
50 | + qemu_io(top_img_path, '-c', 'write -P 2 1M 1M') | ||
51 | |||
52 | log('Done') | ||
53 | |||
54 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base.img') as base_img_path, \ | ||
55 | log('--- Checking COR result ---') | ||
56 | log('') | ||
57 | |||
58 | - assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') == 0 | ||
59 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') == 0 | ||
60 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0 | ||
61 | + qemu_io(base_img_path, '-c', 'discard 0 64M') | ||
62 | + qemu_io(top_img_path, '-c', 'read -P 1 0M 1M') | ||
63 | + qemu_io(top_img_path, '-c', 'read -P 2 1M 1M') | ||
64 | |||
65 | log('Done') | ||
66 | diff --git a/tests/qemu-iotests/218 b/tests/qemu-iotests/218 | ||
67 | index XXXXXXX..XXXXXXX 100755 | ||
68 | --- a/tests/qemu-iotests/218 | ||
69 | +++ b/tests/qemu-iotests/218 | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> | ||
72 | |||
73 | import iotests | ||
74 | -from iotests import log, qemu_img, qemu_io_silent | ||
75 | +from iotests import log, qemu_img, qemu_io | ||
76 | |||
77 | iotests.script_initialize(supported_fmts=['qcow2', 'raw']) | ||
78 | |||
79 | @@ -XXX,XX +XXX,XX @@ with iotests.VM() as vm, \ | ||
80 | iotests.FilePath('src.img') as src_img_path: | ||
81 | |||
82 | qemu_img('create', '-f', iotests.imgfmt, src_img_path, '64M') | ||
83 | - assert qemu_io_silent('-f', iotests.imgfmt, src_img_path, | ||
84 | - '-c', 'write -P 42 0M 64M') == 0 | ||
85 | + qemu_io('-f', iotests.imgfmt, src_img_path, '-c', 'write -P 42 0M 64M') | ||
86 | |||
87 | vm.launch() | ||
88 | |||
89 | diff --git a/tests/qemu-iotests/224 b/tests/qemu-iotests/224 | ||
90 | index XXXXXXX..XXXXXXX 100755 | ||
91 | --- a/tests/qemu-iotests/224 | ||
92 | +++ b/tests/qemu-iotests/224 | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> | ||
95 | |||
96 | import iotests | ||
97 | -from iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \ | ||
98 | +from iotests import log, qemu_img, qemu_io, filter_qmp_testfiles, \ | ||
99 | filter_qmp_imgfmt | ||
100 | import json | ||
101 | |||
102 | @@ -XXX,XX +XXX,XX @@ for filter_node_name in False, True: | ||
103 | '-F', iotests.imgfmt, top_img_path) | ||
104 | |||
105 | # Something to commit | ||
106 | - assert qemu_io_silent(mid_img_path, '-c', 'write -P 1 0 1M') == 0 | ||
107 | + qemu_io(mid_img_path, '-c', 'write -P 1 0 1M') | ||
108 | |||
109 | vm.launch() | ||
110 | |||
111 | diff --git a/tests/qemu-iotests/258 b/tests/qemu-iotests/258 | ||
112 | index XXXXXXX..XXXXXXX 100755 | ||
113 | --- a/tests/qemu-iotests/258 | ||
114 | +++ b/tests/qemu-iotests/258 | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> | ||
117 | |||
118 | import iotests | ||
119 | -from iotests import log, qemu_img, qemu_io_silent, \ | ||
120 | +from iotests import log, qemu_img, qemu_io, \ | ||
121 | filter_qmp_testfiles, filter_qmp_imgfmt | ||
122 | |||
123 | # Returns a node for blockdev-add | ||
124 | @@ -XXX,XX +XXX,XX @@ def test_concurrent_finish(write_to_stream_node): | ||
125 | if write_to_stream_node: | ||
126 | # This is what (most of the time) makes commit finish | ||
127 | # earlier and then pull in stream | ||
128 | - assert qemu_io_silent(node2_path, | ||
129 | - '-c', 'write %iK 64K' % (65536 - 192), | ||
130 | - '-c', 'write %iK 64K' % (65536 - 64)) == 0 | ||
131 | + qemu_io(node2_path, | ||
132 | + '-c', 'write %iK 64K' % (65536 - 192), | ||
133 | + '-c', 'write %iK 64K' % (65536 - 64)) | ||
134 | |||
135 | stream_throttle='tg' | ||
136 | else: | ||
137 | # And this makes stream finish earlier | ||
138 | - assert qemu_io_silent(node1_path, | ||
139 | - '-c', 'write %iK 64K' % (65536 - 64)) == 0 | ||
140 | + qemu_io(node1_path, '-c', 'write %iK 64K' % (65536 - 64)) | ||
141 | |||
142 | commit_throttle='tg' | ||
143 | |||
144 | diff --git a/tests/qemu-iotests/298 b/tests/qemu-iotests/298 | ||
145 | index XXXXXXX..XXXXXXX 100755 | ||
146 | --- a/tests/qemu-iotests/298 | ||
147 | +++ b/tests/qemu-iotests/298 | ||
148 | @@ -XXX,XX +XXX,XX @@ class TestTruncate(iotests.QMPTestCase): | ||
149 | os.remove(refdisk) | ||
150 | |||
151 | def do_test(self, prealloc_mode, new_size): | ||
152 | - ret = iotests.qemu_io_silent('--image-opts', '-c', 'write 0 10M', '-c', | ||
153 | - f'truncate -m {prealloc_mode} {new_size}', | ||
154 | - drive_opts) | ||
155 | - self.assertEqual(ret, 0) | ||
156 | - | ||
157 | - ret = iotests.qemu_io_silent('-f', iotests.imgfmt, '-c', 'write 0 10M', | ||
158 | - '-c', | ||
159 | - f'truncate -m {prealloc_mode} {new_size}', | ||
160 | - refdisk) | ||
161 | - self.assertEqual(ret, 0) | ||
162 | + iotests.qemu_io('--image-opts', '-c', 'write 0 10M', '-c', | ||
163 | + f'truncate -m {prealloc_mode} {new_size}', | ||
164 | + drive_opts) | ||
165 | + | ||
166 | + iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 10M', | ||
167 | + '-c', f'truncate -m {prealloc_mode} {new_size}', | ||
168 | + refdisk) | ||
169 | |||
170 | stat = os.stat(disk) | ||
171 | refstat = os.stat(refdisk) | ||
172 | diff --git a/tests/qemu-iotests/310 b/tests/qemu-iotests/310 | ||
173 | index XXXXXXX..XXXXXXX 100755 | ||
174 | --- a/tests/qemu-iotests/310 | ||
175 | +++ b/tests/qemu-iotests/310 | ||
176 | @@ -XXX,XX +XXX,XX @@ | ||
177 | # | ||
178 | |||
179 | import iotests | ||
180 | -from iotests import log, qemu_img, qemu_io_silent | ||
181 | +from iotests import log, qemu_img, qemu_io | ||
182 | |||
183 | # Need backing file support | ||
184 | iotests.script_initialize(supported_fmts=['qcow2'], | ||
185 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base.img') as base_img_path, \ | ||
186 | log('') | ||
187 | |||
188 | qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') | ||
189 | - assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0 | ||
190 | - assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') == 0 | ||
191 | + qemu_io(base_img_path, '-c', 'write -P 1 0M 1M') | ||
192 | + qemu_io(base_img_path, '-c', 'write -P 1 3M 1M') | ||
193 | qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, | ||
194 | '-F', iotests.imgfmt, mid_img_path) | ||
195 | - assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M') == 0 | ||
196 | - assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 4M 1M') == 0 | ||
197 | + qemu_io(mid_img_path, '-c', 'write -P 3 2M 1M') | ||
198 | + qemu_io(mid_img_path, '-c', 'write -P 3 4M 1M') | ||
199 | qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, | ||
200 | '-F', iotests.imgfmt, top_img_path) | ||
201 | - assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0 | ||
202 | + qemu_io(top_img_path, '-c', 'write -P 2 1M 1M') | ||
203 | |||
204 | # 0 1 2 3 4 | ||
205 | # top 2 | ||
206 | @@ -XXX,XX +XXX,XX @@ with iotests.FilePath('base.img') as base_img_path, \ | ||
207 | # Detach backing to check that we can read the data from the top level now | ||
208 | qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path) | ||
209 | |||
210 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 0 0 1M') == 0 | ||
211 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0 | ||
212 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 3 2M 1M') == 0 | ||
213 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 0 3M 1M') == 0 | ||
214 | - assert qemu_io_silent(top_img_path, '-c', 'read -P 3 4M 1M') == 0 | ||
215 | + qemu_io(top_img_path, '-c', 'read -P 0 0 1M') | ||
216 | + qemu_io(top_img_path, '-c', 'read -P 2 1M 1M') | ||
217 | + qemu_io(top_img_path, '-c', 'read -P 3 2M 1M') | ||
218 | + qemu_io(top_img_path, '-c', 'read -P 0 3M 1M') | ||
219 | + qemu_io(top_img_path, '-c', 'read -P 3 4M 1M') | ||
220 | |||
221 | log('Done') | ||
222 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py | ||
17 | index XXXXXXX..XXXXXXX 100644 | 223 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/block/virtio-blk.c | 224 | --- a/tests/qemu-iotests/iotests.py |
19 | +++ b/hw/block/virtio-blk.c | 225 | +++ b/tests/qemu-iotests/iotests.py |
20 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) | 226 | @@ -XXX,XX +XXX,XX @@ def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
21 | static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, | 227 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) |
22 | bool is_read) | 228 | return result |
23 | { | 229 | |
24 | - BlockErrorAction action = blk_get_error_action(req->dev->blk, | 230 | -def qemu_io_silent(*args): |
25 | - is_read, error); | 231 | - '''Run qemu-io and return the exit code, suppressing stdout''' |
26 | VirtIOBlock *s = req->dev; | 232 | - args = qemu_io_wrap_args(args) |
27 | + BlockErrorAction action = blk_get_error_action(s->blk, is_read, error); | 233 | - result = subprocess.run(args, stdout=subprocess.DEVNULL, check=False) |
28 | 234 | - if result.returncode < 0: | |
29 | if (action == BLOCK_ERROR_ACTION_STOP) { | 235 | - sys.stderr.write('qemu-io received signal %i: %s\n' % |
30 | /* Break the link as the next request is going to be parsed from the | 236 | - (-result.returncode, ' '.join(args))) |
31 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_flush_complete(void *opaque, int ret) | 237 | - return result.returncode |
32 | } | 238 | - |
33 | 239 | -def qemu_io_silent_check(*args): | |
34 | virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); | 240 | - '''Run qemu-io and return the true if subprocess returned 0''' |
35 | - block_acct_done(blk_get_stats(req->dev->blk), &req->acct); | 241 | - args = qemu_io_wrap_args(args) |
36 | + block_acct_done(blk_get_stats(s->blk), &req->acct); | 242 | - result = subprocess.run(args, stdout=subprocess.DEVNULL, |
37 | virtio_blk_free_request(req); | 243 | - stderr=subprocess.STDOUT, check=False) |
38 | 244 | - return result.returncode == 0 | |
39 | out: | 245 | - |
40 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) | 246 | class QemuIoInteractive: |
41 | - sizeof(struct virtio_blk_inhdr); | 247 | def __init__(self, *args): |
42 | iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr)); | 248 | self.args = qemu_io_wrap_args(args) |
43 | 249 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing | |
44 | - type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type); | 250 | index XXXXXXX..XXXXXXX 100755 |
45 | + type = virtio_ldl_p(vdev, &req->out.type); | 251 | --- a/tests/qemu-iotests/tests/image-fleecing |
46 | 252 | +++ b/tests/qemu-iotests/tests/image-fleecing | |
47 | /* VIRTIO_BLK_T_OUT defines the command direction. VIRTIO_BLK_T_BARRIER | 253 | @@ -XXX,XX +XXX,XX @@ |
48 | * is an optional flag. Although a guest should not send this flag if | 254 | from subprocess import CalledProcessError |
49 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) | 255 | |
50 | case VIRTIO_BLK_T_IN: | 256 | import iotests |
51 | { | 257 | -from iotests import log, qemu_img, qemu_io, qemu_io_silent |
52 | bool is_write = type & VIRTIO_BLK_T_OUT; | 258 | +from iotests import log, qemu_img, qemu_io |
53 | - req->sector_num = virtio_ldq_p(VIRTIO_DEVICE(req->dev), | 259 | |
54 | - &req->out.sector); | 260 | iotests.script_initialize( |
55 | + req->sector_num = virtio_ldq_p(vdev, &req->out.sector); | 261 | supported_fmts=['qcow2'], |
56 | 262 | @@ -XXX,XX +XXX,XX @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, | |
57 | if (is_write) { | 263 | for p in overwrite + remainder: |
58 | qemu_iovec_init_external(&req->qiov, out_iov, out_num); | 264 | cmd = 'read -P%s %s %s' % p |
59 | @@ -XXX,XX +XXX,XX @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) | 265 | log(cmd) |
60 | req->qiov.size / BDRV_SECTOR_SIZE); | 266 | - assert qemu_io_silent(base_img_path, '-c', cmd) == 0 |
61 | } | 267 | + qemu_io(base_img_path, '-c', cmd) |
62 | 268 | ||
63 | - if (!virtio_blk_sect_range_ok(req->dev, req->sector_num, | 269 | log('') |
64 | - req->qiov.size)) { | 270 | log('Done') |
65 | + if (!virtio_blk_sect_range_ok(s, req->sector_num, req->qiov.size)) { | 271 | diff --git a/tests/qemu-iotests/tests/mirror-ready-cancel-error b/tests/qemu-iotests/tests/mirror-ready-cancel-error |
66 | virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR); | 272 | index XXXXXXX..XXXXXXX 100755 |
67 | - block_acct_invalid(blk_get_stats(req->dev->blk), | 273 | --- a/tests/qemu-iotests/tests/mirror-ready-cancel-error |
68 | + block_acct_invalid(blk_get_stats(s->blk), | 274 | +++ b/tests/qemu-iotests/tests/mirror-ready-cancel-error |
69 | is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ); | 275 | @@ -XXX,XX +XXX,XX @@ class TestMirrorReadyCancelError(iotests.QMPTestCase): |
70 | virtio_blk_free_request(req); | 276 | # Ensure that mirror will copy something before READY so the |
71 | return 0; | 277 | # target format layer will forward the pre-READY flush to its |
72 | } | 278 | # file child |
73 | 279 | - assert iotests.qemu_io_silent('-c', 'write -P 1 0 64k', source) == 0 | |
74 | - block_acct_start(blk_get_stats(req->dev->blk), | 280 | + iotests.qemu_io('-c', 'write -P 1 0 64k', source) |
75 | - &req->acct, req->qiov.size, | 281 | |
76 | + block_acct_start(blk_get_stats(s->blk), &req->acct, req->qiov.size, | 282 | self.vm = iotests.VM() |
77 | is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ); | 283 | self.vm.launch() |
78 | 284 | diff --git a/tests/qemu-iotests/tests/stream-error-on-reset b/tests/qemu-iotests/tests/stream-error-on-reset | |
79 | /* merge would exceed maximum number of requests or IO direction | 285 | index XXXXXXX..XXXXXXX 100755 |
80 | * changes */ | 286 | --- a/tests/qemu-iotests/tests/stream-error-on-reset |
81 | if (mrb->num_reqs > 0 && (mrb->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS || | 287 | +++ b/tests/qemu-iotests/tests/stream-error-on-reset |
82 | is_write != mrb->is_write || | 288 | @@ -XXX,XX +XXX,XX @@ |
83 | - !req->dev->conf.request_merging)) { | 289 | |
84 | - virtio_blk_submit_multireq(req->dev->blk, mrb); | 290 | import os |
85 | + !s->conf.request_merging)) { | 291 | import iotests |
86 | + virtio_blk_submit_multireq(s->blk, mrb); | 292 | -from iotests import imgfmt, qemu_img_create, qemu_io_silent, QMPTestCase |
87 | } | 293 | +from iotests import imgfmt, qemu_img_create, qemu_io, QMPTestCase |
88 | 294 | ||
89 | assert(mrb->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS); | 295 | |
296 | image_size = 1 * 1024 * 1024 | ||
297 | @@ -XXX,XX +XXX,XX @@ class TestStreamErrorOnReset(QMPTestCase): | ||
298 | - top image is attached to a virtio-scsi device | ||
299 | """ | ||
300 | qemu_img_create('-f', imgfmt, base, str(image_size)) | ||
301 | - assert qemu_io_silent('-c', f'write 0 {data_size}', base) == 0 | ||
302 | + qemu_io('-c', f'write 0 {data_size}', base) | ||
303 | qemu_img_create('-f', imgfmt, top, str(image_size)) | ||
304 | |||
305 | self.vm = iotests.VM() | ||
90 | -- | 306 | -- |
91 | 2.20.1 | 307 | 2.35.1 |
92 | |||
93 | diff view generated by jsdifflib |
1 | From: Peter Xu <peterx@redhat.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Lukas reported an hard to reproduce QMP iothread hang on s390 that | 3 | Just like qemu_img_log(), upgrade qemu_io_log() to enforce a return code |
4 | QEMU might hang at pthread_join() of the QMP monitor iothread before | 4 | of zero by default. |
5 | quitting: | ||
6 | 5 | ||
7 | Thread 1 | 6 | Tests that use qemu_io_log(): 242 245 255 274 303 307 nbd-reconnect-on-open |
8 | #0 0x000003ffad10932c in pthread_join | ||
9 | #1 0x0000000109e95750 in qemu_thread_join | ||
10 | at /home/thuth/devel/qemu/util/qemu-thread-posix.c:570 | ||
11 | #2 0x0000000109c95a1c in iothread_stop | ||
12 | #3 0x0000000109bb0874 in monitor_cleanup | ||
13 | #4 0x0000000109b55042 in main | ||
14 | 7 | ||
15 | While the iothread is still in the main loop: | 8 | Signed-off-by: John Snow <jsnow@redhat.com> |
9 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
10 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | ||
11 | Message-Id: <20220418211504.943969-13-jsnow@redhat.com> | ||
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/iotests.py | 5 +++-- | ||
15 | tests/qemu-iotests/tests/nbd-reconnect-on-open | 2 +- | ||
16 | 2 files changed, 4 insertions(+), 3 deletions(-) | ||
16 | 17 | ||
17 | Thread 4 | 18 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py |
18 | #0 0x000003ffad0010e4 in ?? | ||
19 | #1 0x000003ffad553958 in g_main_context_iterate.isra.19 | ||
20 | #2 0x000003ffad553d90 in g_main_loop_run | ||
21 | #3 0x0000000109c9585a in iothread_run | ||
22 | at /home/thuth/devel/qemu/iothread.c:74 | ||
23 | #4 0x0000000109e94752 in qemu_thread_start | ||
24 | at /home/thuth/devel/qemu/util/qemu-thread-posix.c:502 | ||
25 | #5 0x000003ffad10825a in start_thread | ||
26 | #6 0x000003ffad00dcf2 in thread_start | ||
27 | |||
28 | IMHO it's because there's a race between the main thread and iothread | ||
29 | when stopping the thread in following sequence: | ||
30 | |||
31 | main thread iothread | ||
32 | =========== ============== | ||
33 | aio_poll() | ||
34 | iothread_get_g_main_context | ||
35 | set iothread->worker_context | ||
36 | iothread_stop | ||
37 | schedule iothread_stop_bh | ||
38 | execute iothread_stop_bh [1] | ||
39 | set iothread->running=false | ||
40 | (since main_loop==NULL so | ||
41 | skip to quit main loop. | ||
42 | Note: although main_loop is | ||
43 | NULL but worker_context is | ||
44 | not!) | ||
45 | atomic_read(&iothread->worker_context) [2] | ||
46 | create main_loop object | ||
47 | g_main_loop_run() [3] | ||
48 | pthread_join() [4] | ||
49 | |||
50 | We can see that when execute iothread_stop_bh() at [1] it's possible | ||
51 | that main_loop is still NULL because it's only created until the first | ||
52 | check of the worker_context later at [2]. Then the iothread will hang | ||
53 | in the main loop [3] and it'll starve the main thread too [4]. | ||
54 | |||
55 | Here the simple solution should be that we check again the "running" | ||
56 | variable before check against worker_context. | ||
57 | |||
58 | CC: Thomas Huth <thuth@redhat.com> | ||
59 | CC: Dr. David Alan Gilbert <dgilbert@redhat.com> | ||
60 | CC: Stefan Hajnoczi <stefanha@redhat.com> | ||
61 | CC: Lukáš Doktor <ldoktor@redhat.com> | ||
62 | CC: Markus Armbruster <armbru@redhat.com> | ||
63 | CC: Eric Blake <eblake@redhat.com> | ||
64 | CC: Paolo Bonzini <pbonzini@redhat.com> | ||
65 | Reported-by: Lukáš Doktor <ldoktor@redhat.com> | ||
66 | Signed-off-by: Peter Xu <peterx@redhat.com> | ||
67 | Tested-by: Thomas Huth <thuth@redhat.com> | ||
68 | Message-id: 20190129051432.22023-1-peterx@redhat.com | ||
69 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
70 | --- | ||
71 | iothread.c | 6 +++++- | ||
72 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
73 | |||
74 | diff --git a/iothread.c b/iothread.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
76 | --- a/iothread.c | 20 | --- a/tests/qemu-iotests/iotests.py |
77 | +++ b/iothread.c | 21 | +++ b/tests/qemu-iotests/iotests.py |
78 | @@ -XXX,XX +XXX,XX @@ static void *iothread_run(void *opaque) | 22 | @@ -XXX,XX +XXX,XX @@ def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True |
79 | while (iothread->running) { | 23 | return qemu_tool(*qemu_io_wrap_args(args), |
80 | aio_poll(iothread->ctx, true); | 24 | check=check, combine_stdio=combine_stdio) |
81 | 25 | ||
82 | - if (atomic_read(&iothread->worker_context)) { | 26 | -def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
83 | + /* | 27 | - result = qemu_io(*args, check=False) |
84 | + * We must check the running state again in case it was | 28 | +def qemu_io_log(*args: str, check: bool = True |
85 | + * changed in previous aio_poll() | 29 | + ) -> 'subprocess.CompletedProcess[str]': |
86 | + */ | 30 | + result = qemu_io(*args, check=check) |
87 | + if (iothread->running && atomic_read(&iothread->worker_context)) { | 31 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) |
88 | GMainLoop *loop; | 32 | return result |
89 | 33 | ||
90 | g_main_context_push_thread_default(iothread->worker_context); | 34 | diff --git a/tests/qemu-iotests/tests/nbd-reconnect-on-open b/tests/qemu-iotests/tests/nbd-reconnect-on-open |
35 | index XXXXXXX..XXXXXXX 100755 | ||
36 | --- a/tests/qemu-iotests/tests/nbd-reconnect-on-open | ||
37 | +++ b/tests/qemu-iotests/tests/nbd-reconnect-on-open | ||
38 | @@ -XXX,XX +XXX,XX @@ def check_fail_to_connect(open_timeout): | ||
39 | log(f'Check fail to connect with {open_timeout} seconds of timeout') | ||
40 | |||
41 | start_t = time.time() | ||
42 | - qemu_io_log(*create_args(open_timeout)) | ||
43 | + qemu_io_log(*create_args(open_timeout), check=False) | ||
44 | delta_t = time.time() - start_t | ||
45 | |||
46 | max_delta = open_timeout + 0.2 | ||
91 | -- | 47 | -- |
92 | 2.20.1 | 48 | 2.35.1 |
93 | |||
94 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | FUSE exports' allow-other option defaults to "auto", which means that it |
---|---|---|---|
2 | will try passing allow_other as a mount option, and fall back to not | ||
3 | using it when an error occurs. We make no effort to hide fusermount's | ||
4 | error message (because it would be difficult, and because users might | ||
5 | want to know about the fallback occurring), and so when allow_other does | ||
6 | not work (primarily when /etc/fuse.conf does not contain | ||
7 | user_allow_other), this error message will appear and break the | ||
8 | reference output. | ||
2 | 9 | ||
3 | qemu coroutine command results in following error output: | 10 | We do not need allow_other here, though, so we can just pass |
11 | allow-other=off to fix that. | ||
4 | 12 | ||
5 | Python Exception <class 'gdb.error'> 'arch_prctl' has unknown return | 13 | Reported-by: Markus Armbruster <armbru@redhat.com> |
6 | type; cast the call to its declared return type: Error occurred in | 14 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> |
7 | Python command: 'arch_prctl' has unknown return type; cast the call to | 15 | Message-Id: <20220421142435.569600-1-hreitz@redhat.com> |
8 | its declared return type | 16 | Tested-by: Markus Armbruster <armbru@redhat.com> |
9 | 17 | Tested-by: Eric Blake <eblake@redhat.com> | |
10 | Fix it by giving it what it wants: arch_prctl return type. | ||
11 | |||
12 | Information on the topic: | ||
13 | https://sourceware.org/gdb/onlinedocs/gdb/Calling.html | ||
14 | |||
15 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | ||
16 | Message-id: 20190206151425.105871-1-vsementsov@virtuozzo.com | ||
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
18 | --- | 18 | --- |
19 | scripts/qemugdb/coroutine.py | 2 +- | 19 | tests/qemu-iotests/108 | 2 +- |
20 | 1 file changed, 1 insertion(+), 1 deletion(-) | 20 | 1 file changed, 1 insertion(+), 1 deletion(-) |
21 | 21 | ||
22 | diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py | 22 | diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108 |
23 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100755 |
24 | --- a/scripts/qemugdb/coroutine.py | 24 | --- a/tests/qemu-iotests/108 |
25 | +++ b/scripts/qemugdb/coroutine.py | 25 | +++ b/tests/qemu-iotests/108 |
26 | @@ -XXX,XX +XXX,XX @@ def get_fs_base(): | 26 | @@ -XXX,XX +XXX,XX @@ else |
27 | pthread_self().''' | 27 | |
28 | # %rsp - 120 is scratch space according to the SystemV ABI | 28 | $QSD \ |
29 | old = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)') | 29 | --blockdev file,node-name=export-node,filename="$TEST_IMG" \ |
30 | - gdb.execute('call arch_prctl(0x1003, $rsp - 120)', False, True) | 30 | - --export fuse,id=fuse-export,node-name=export-node,mountpoint="$export_mp",writable=on,growable=off \ |
31 | + gdb.execute('call (int)arch_prctl(0x1003, $rsp - 120)', False, True) | 31 | + --export fuse,id=fuse-export,node-name=export-node,mountpoint="$export_mp",writable=on,growable=off,allow-other=off \ |
32 | fs_base = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)') | 32 | --pidfile "$TEST_DIR/qsd.pid" \ |
33 | gdb.execute('set *(uint64_t*)($rsp - 120) = %s' % old, False, True) | 33 | --daemonize |
34 | return fs_base | 34 | fi |
35 | -- | 35 | -- |
36 | 2.20.1 | 36 | 2.35.1 |
37 | |||
38 | diff view generated by jsdifflib |