1 | The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81: | 1 | The following changes since commit 754f756cc4c6d9d14b7230c62b5bb20f9d655888: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100) | 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 | https://gitlab.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 9f460c64e13897117f35ffb61f6f5e0102cabc70: | 9 | for you to fetch changes up to 348a0740afc5b313599533eb69bbb2b95d2f1bba: |
10 | 10 | ||
11 | block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100) | 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 | - New @force parameter for blockdev-change-medium | ||
16 | - Improvements to the iotests to help with debugging | ||
17 | - Fix iotest 108 on systems without user_allow_other in fuse.conf | ||
15 | 18 | ||
16 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
20 | Denis V. Lunev (1): | ||
21 | block: add 'force' parameter to 'blockdev-change-medium' command | ||
17 | 22 | ||
18 | Akihiko Odaki (3): | 23 | Hanna Reitz (1): |
19 | block/file-posix: Optimize for macOS | 24 | iotests/108: Fix when missing user_allow_other |
20 | block: Add backend_defaults property | ||
21 | block/io: Merge discard request alignments | ||
22 | 25 | ||
23 | Stefan Hajnoczi (2): | 26 | John Snow (12): |
24 | util/async: add a human-readable name to BHs for debugging | 27 | iotests: replace calls to log(qemu_io(...)) with qemu_io_log() |
25 | util/async: print leaked BH name when AioContext finalizes | 28 | iotests/163: Fix broken qemu-io invocation |
29 | iotests: Don't check qemu_io() output for specific error strings | ||
30 | iotests/040: Don't check image pattern on zero-length image | ||
31 | iotests/040: Fix TestCommitWithFilters test | ||
32 | iotests: create generic qemu_tool() function | ||
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 | ||
26 | 40 | ||
27 | include/block/aio.h | 31 ++++++++++++++++++++++--- | 41 | qapi/block.json | 6 ++ |
28 | include/hw/block/block.h | 3 +++ | 42 | block/qapi-sysemu.c | 3 +- |
29 | include/qemu/main-loop.h | 4 +++- | 43 | monitor/hmp-cmds.c | 4 +- |
30 | block/file-posix.c | 27 ++++++++++++++++++++-- | 44 | hmp-commands.hx | 11 ++- |
31 | block/io.c | 2 ++ | 45 | tests/qemu-iotests/030 | 85 +++++++++++-------- |
32 | hw/block/block.c | 42 ++++++++++++++++++++++++++++++---- | 46 | tests/qemu-iotests/040 | 53 +++++++----- |
33 | tests/unit/ptimer-test-stubs.c | 2 +- | 47 | tests/qemu-iotests/056 | 2 +- |
34 | util/async.c | 25 ++++++++++++++++---- | 48 | tests/qemu-iotests/108 | 2 +- |
35 | util/main-loop.c | 4 ++-- | 49 | tests/qemu-iotests/149 | 6 +- |
36 | tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++ | 50 | tests/qemu-iotests/163 | 5 +- |
37 | 10 files changed, 161 insertions(+), 17 deletions(-) | 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(-) | ||
38 | 70 | ||
39 | -- | 71 | -- |
40 | 2.31.1 | 72 | 2.35.1 |
41 | diff view generated by jsdifflib |
1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> | 1 | From: "Denis V. Lunev" <den@openvz.org> |
---|---|---|---|
2 | 2 | ||
3 | This commit introduces "punch hole" operation and optimizes transfer | 3 | 'blockdev-change-medium' is a convinient wrapper for the following |
4 | block size for macOS. | 4 | sequence of commands: |
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. | ||
5 | 15 | ||
6 | Thanks to Konstantin Nazarov for detailed analysis of a flaw in an | 16 | This situation is could be resolved 'blockdev-open-tray' by passing |
7 | old version of this change: | 17 | flag 'force' inside. Thus is seems reasonable to add the same |
8 | https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667 | 18 | capability for 'blockdev-change-medium' too. |
9 | 19 | ||
10 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> | 20 | Signed-off-by: Denis V. Lunev <den@openvz.org> |
11 | Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com | 21 | Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> |
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 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 | block/file-posix.c | 27 +++++++++++++++++++++++++-- | 31 | qapi/block.json | 6 ++++++ |
15 | 1 file changed, 25 insertions(+), 2 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/block/file-posix.c b/block/file-posix.c | 38 | diff --git a/qapi/block.json b/qapi/block.json |
18 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/block/file-posix.c | 40 | --- a/qapi/block.json |
20 | +++ b/block/file-posix.c | 41 | +++ b/qapi/block.json |
21 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ |
22 | #if defined(HAVE_HOST_BLOCK_DEVICE) | 43 | # @read-only-mode: change the read-only mode of the device; defaults |
23 | #include <paths.h> | 44 | # to 'retain' |
24 | #include <sys/param.h> | 45 | # |
25 | +#include <sys/mount.h> | 46 | +# @force: if false (the default), an eject request through blockdev-open-tray |
26 | #include <IOKit/IOKitLib.h> | 47 | +# will be sent to the guest if it has locked the tray (and the tray |
27 | #include <IOKit/IOBSD.h> | 48 | +# will not be opened immediately); if true, the tray will be opened |
28 | #include <IOKit/storage/IOMediaBSDClient.h> | 49 | +# regardless of whether it is locked. (since 7.1) |
29 | @@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) | 50 | +# |
30 | return; | 51 | # Features: |
52 | # @deprecated: Member @device is deprecated. Use @id instead. | ||
53 | # | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | '*id': 'str', | ||
56 | 'filename': 'str', | ||
57 | '*format': 'str', | ||
58 | + '*force': 'bool', | ||
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); | ||
31 | } | 103 | } |
32 | 104 | ||
33 | +#if defined(__APPLE__) && (__MACH__) | 105 | diff --git a/hmp-commands.hx b/hmp-commands.hx |
34 | + struct statfs buf; | 106 | index XXXXXXX..XXXXXXX 100644 |
107 | --- a/hmp-commands.hx | ||
108 | +++ b/hmp-commands.hx | ||
109 | @@ -XXX,XX +XXX,XX @@ ERST | ||
110 | |||
111 | { | ||
112 | .name = "change", | ||
113 | - .args_type = "device:B,target:F,arg:s?,read-only-mode:s?", | ||
114 | - .params = "device filename [format [read-only-mode]]", | ||
115 | - .help = "change a removable medium, optional format", | ||
116 | + .args_type = "device:B,force:-f,target:F,arg:s?,read-only-mode:s?", | ||
117 | + .params = "device [-f] filename [format [read-only-mode]]", | ||
118 | + .help = "change a removable medium, optional format, use -f to force the operation", | ||
119 | .cmd = hmp_change, | ||
120 | }, | ||
121 | |||
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. | ||
35 | + | 134 | + |
36 | + if (!fstatfs(s->fd, &buf)) { | 135 | *format* is optional. |
37 | + bs->bl.opt_transfer = buf.f_iosize; | 136 | |
38 | + bs->bl.pdiscard_alignment = buf.f_bsize; | 137 | *read-only-mode* may be used to change the read-only status of the device. |
39 | + } | 138 | diff --git a/ui/cocoa.m b/ui/cocoa.m |
40 | +#endif | 139 | index XXXXXXX..XXXXXXX 100644 |
41 | + | 140 | --- a/ui/cocoa.m |
42 | if (bs->sg || S_ISBLK(st.st_mode)) { | 141 | +++ b/ui/cocoa.m |
43 | int ret = hdev_get_max_hw_transfer(s->fd, &st); | 142 | @@ -XXX,XX +XXX,XX @@ - (void)changeDeviceMedia:(id)sender |
44 | 143 | [file cStringUsingEncoding: | |
45 | @@ -XXX,XX +XXX,XX @@ out: | 144 | NSASCIIStringEncoding], |
46 | } | 145 | true, "raw", |
47 | } | 146 | + true, false, |
48 | 147 | false, 0, | |
49 | +#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD) | 148 | &err); |
50 | static int translate_err(int err) | 149 | }); |
51 | { | ||
52 | if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP || | ||
53 | @@ -XXX,XX +XXX,XX @@ static int translate_err(int err) | ||
54 | } | ||
55 | return err; | ||
56 | } | ||
57 | +#endif | ||
58 | |||
59 | #ifdef CONFIG_FALLOCATE | ||
60 | static int do_fallocate(int fd, int mode, off_t offset, off_t len) | ||
61 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque) | ||
62 | } | ||
63 | } while (errno == EINTR); | ||
64 | |||
65 | - ret = -errno; | ||
66 | + ret = translate_err(-errno); | ||
67 | #endif | ||
68 | } else { | ||
69 | #ifdef CONFIG_FALLOCATE_PUNCH_HOLE | ||
70 | ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, | ||
71 | aiocb->aio_offset, aiocb->aio_nbytes); | ||
72 | + ret = translate_err(-errno); | ||
73 | +#elif defined(__APPLE__) && (__MACH__) | ||
74 | + fpunchhole_t fpunchhole; | ||
75 | + fpunchhole.fp_flags = 0; | ||
76 | + fpunchhole.reserved = 0; | ||
77 | + fpunchhole.fp_offset = aiocb->aio_offset; | ||
78 | + fpunchhole.fp_length = aiocb->aio_nbytes; | ||
79 | + if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) == -1) { | ||
80 | + ret = errno == ENODEV ? -ENOTSUP : -errno; | ||
81 | + } else { | ||
82 | + ret = 0; | ||
83 | + } | ||
84 | #endif | ||
85 | } | ||
86 | |||
87 | - ret = translate_err(ret); | ||
88 | if (ret == -ENOTSUP) { | ||
89 | s->has_discard = false; | ||
90 | } | ||
91 | -- | 150 | -- |
92 | 2.31.1 | 151 | 2.35.1 |
93 | 152 | ||
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 |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | qemu-io fails on read/write beyond end-of-file on raw images, so skip | ||
4 | these invocations when running the zero-length image tests. | ||
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-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(-) | ||
14 | |||
15 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 | ||
16 | index XXXXXXX..XXXXXXX 100755 | ||
17 | --- a/tests/qemu-iotests/040 | ||
18 | +++ b/tests/qemu-iotests/040 | ||
19 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
20 | qemu_img('create', '-f', iotests.imgfmt, | ||
21 | '-o', 'backing_file=%s' % mid_img, | ||
22 | '-F', iotests.imgfmt, test_img) | ||
23 | - qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) | ||
24 | - qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', mid_img) | ||
25 | + if self.image_len: | ||
26 | + qemu_io('-f', 'raw', '-c', 'write -P 0xab 0 524288', backing_img) | ||
27 | + qemu_io('-f', iotests.imgfmt, '-c', 'write -P 0xef 524288 524288', | ||
28 | + mid_img) | ||
29 | self.vm = iotests.VM().add_drive(test_img, "node-name=top,backing.node-name=mid,backing.backing.node-name=base", interface="none") | ||
30 | self.vm.add_device('virtio-scsi') | ||
31 | self.vm.add_device("scsi-hd,id=scsi0,drive=drive0") | ||
32 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
33 | |||
34 | def test_commit(self): | ||
35 | self.run_commit_test(mid_img, backing_img) | ||
36 | + if not self.image_len: | ||
37 | + return | ||
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 | def test_commit_node(self): | ||
42 | self.run_commit_test("mid", "base", node_names=True) | ||
43 | + if not self.image_len: | ||
44 | + return | ||
45 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
46 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
47 | |||
48 | @@ -XXX,XX +XXX,XX @@ class TestSingleDrive(ImageCommitTestCase): | ||
49 | |||
50 | def test_top_is_active(self): | ||
51 | self.run_commit_test(test_img, backing_img, need_ready=True) | ||
52 | + if not self.image_len: | ||
53 | + return | ||
54 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
55 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
56 | |||
57 | def test_top_is_default_active(self): | ||
58 | self.run_default_commit_test() | ||
59 | + if not self.image_len: | ||
60 | + return | ||
61 | qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 524288', backing_img) | ||
62 | qemu_io('-f', 'raw', '-c', 'read -P 0xef 524288 524288', backing_img) | ||
63 | |||
64 | -- | ||
65 | 2.35.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Without this change, asserting that qemu_io always returns 0 causes this | ||
4 | test to fail in a way we happened not to be catching previously: | ||
5 | |||
6 | qemu.utils.VerboseProcessError: Command | ||
7 | '('/home/jsnow/src/qemu/bin/git/tests/qemu-iotests/../../qemu-io', | ||
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 | ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
18 | |||
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. | ||
28 | |||
29 | When starting the commit job, we can specify a custom backing file | ||
30 | string to write into said image file, so let’s use that feature to write | ||
31 | the plain filename of the backing chain’s next actual image file there. | ||
32 | |||
33 | Explicitly provide the backing file so that opening the file outside of | ||
34 | QEMU (Where we will not have throttle groups) will succeed. | ||
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> | ||
40 | --- | ||
41 | tests/qemu-iotests/040 | 6 ++++-- | ||
42 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
43 | |||
44 | diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 | ||
45 | index XXXXXXX..XXXXXXX 100755 | ||
46 | --- a/tests/qemu-iotests/040 | ||
47 | +++ b/tests/qemu-iotests/040 | ||
48 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): | ||
49 | job_id='commit', | ||
50 | device='top-filter', | ||
51 | top_node='cow-2', | ||
52 | - base_node='cow-1') | ||
53 | + base_node='cow-1', | ||
54 | + backing_file=self.img1) | ||
55 | self.assert_qmp(result, 'return', {}) | ||
56 | self.wait_until_completed(drive='commit') | ||
57 | |||
58 | @@ -XXX,XX +XXX,XX @@ class TestCommitWithFilters(iotests.QMPTestCase): | ||
59 | job_id='commit', | ||
60 | device='top-filter', | ||
61 | top_node='cow-1', | ||
62 | - base_node='cow-0') | ||
63 | + base_node='cow-0', | ||
64 | + backing_file=self.img0) | ||
65 | self.assert_qmp(result, 'return', {}) | ||
66 | self.wait_until_completed(drive='commit') | ||
67 | |||
68 | -- | ||
69 | 2.35.1 | ||
70 | |||
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 |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Modify this test to use assertRaises for its negative testing of | ||
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. | ||
8 | |||
9 | If we get the CalledProcessError exception but the output is not what we | ||
10 | expect, we re-raise the original CalledProcessError. | ||
11 | |||
12 | Tidy. | ||
13 | |||
14 | (Note: Yes, you can reference "with" objects after that block ends; it | ||
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> | ||
25 | --- | ||
26 | .../qemu-iotests/tests/migration-permissions | 28 +++++++++---------- | ||
27 | 1 file changed, 14 insertions(+), 14 deletions(-) | ||
28 | |||
29 | diff --git a/tests/qemu-iotests/tests/migration-permissions b/tests/qemu-iotests/tests/migration-permissions | ||
30 | index XXXXXXX..XXXXXXX 100755 | ||
31 | --- a/tests/qemu-iotests/tests/migration-permissions | ||
32 | +++ b/tests/qemu-iotests/tests/migration-permissions | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | # | ||
35 | |||
36 | import os | ||
37 | +from subprocess import CalledProcessError | ||
38 | + | ||
39 | import iotests | ||
40 | from iotests import imgfmt, qemu_img_create, qemu_io | ||
41 | |||
42 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): | ||
43 | def test_post_migration_permissions(self): | ||
44 | # Try to access the image R/W, which should fail because virtio-blk | ||
45 | # has not been configured with share-rw=on | ||
46 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout | ||
47 | - if not log.strip(): | ||
48 | - print('ERROR (pre-migration): qemu-io should not be able to ' | ||
49 | - 'access this image, but it reported no error') | ||
50 | - else: | ||
51 | - # This is the expected output | ||
52 | - assert 'Is another process using the image' in log | ||
53 | + emsg = ('ERROR (pre-migration): qemu-io should not be able to ' | ||
54 | + 'access this image, but it reported no error') | ||
55 | + with self.assertRaises(CalledProcessError, msg=emsg) as ctx: | ||
56 | + qemu_io('-f', imgfmt, '-c', 'quit', test_img) | ||
57 | + if 'Is another process using the image' not in ctx.exception.stdout: | ||
58 | + raise ctx.exception | ||
59 | |||
60 | # Now migrate the VM | ||
61 | self.vm_s.qmp('migrate', uri=f'unix:{mig_sock}') | ||
62 | @@ -XXX,XX +XXX,XX @@ class TestMigrationPermissions(iotests.QMPTestCase): | ||
63 | |||
64 | # Try the same qemu-io access again, verifying that the WRITE | ||
65 | # permission remains unshared | ||
66 | - log = qemu_io('-f', imgfmt, '-c', 'quit', test_img, check=False).stdout | ||
67 | - if not log.strip(): | ||
68 | - print('ERROR (post-migration): qemu-io should not be able to ' | ||
69 | - 'access this image, but it reported no error') | ||
70 | - else: | ||
71 | - # This is the expected output | ||
72 | - assert 'Is another process using the image' in log | ||
73 | + emsg = ('ERROR (post-migration): qemu-io should not be able to ' | ||
74 | + 'access this image, but it reported no error') | ||
75 | + with self.assertRaises(CalledProcessError, msg=emsg) as ctx: | ||
76 | + qemu_io('-f', imgfmt, '-c', 'quit', test_img) | ||
77 | + if 'Is another process using the image' not in ctx.exception.stdout: | ||
78 | + raise ctx.exception | ||
79 | |||
80 | |||
81 | if __name__ == '__main__': | ||
82 | -- | ||
83 | 2.35.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | This test expects failure ... but only sometimes. When? Why? | ||
4 | |||
5 | It's for reads of a region not defined by a bitmap. Adjust the test to | ||
6 | be more explicit about what it expects to fail and why. | ||
7 | |||
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-10-jsnow@redhat.com> | ||
12 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
13 | --- | ||
14 | tests/qemu-iotests/tests/image-fleecing | 28 +++++++++++++++++-------- | ||
15 | 1 file changed, 19 insertions(+), 9 deletions(-) | ||
16 | |||
17 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing | ||
18 | index XXXXXXX..XXXXXXX 100755 | ||
19 | --- a/tests/qemu-iotests/tests/image-fleecing | ||
20 | +++ b/tests/qemu-iotests/tests/image-fleecing | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | # | ||
23 | # Creator/Owner: John Snow <jsnow@redhat.com> | ||
24 | |||
25 | +from subprocess import CalledProcessError | ||
26 | + | ||
27 | import iotests | ||
28 | -from iotests import log, qemu_img, qemu_io, qemu_io_silent, \ | ||
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 ---') | ||
71 | -- | ||
72 | 2.35.1 | diff view generated by jsdifflib |
1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> | 3 | I know we just added it, sorry. This is done in favor of qemu_io() which |
4 | Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com | 4 | *also* returns the console output and status, but with more robust error |
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | handling on failure. |
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-11-jsnow@redhat.com> | ||
11 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
6 | --- | 12 | --- |
7 | block/io.c | 2 ++ | 13 | tests/qemu-iotests/iotests.py | 3 --- |
8 | 1 file changed, 2 insertions(+) | 14 | 1 file changed, 3 deletions(-) |
9 | 15 | ||
10 | diff --git a/block/io.c b/block/io.c | 16 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py |
11 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/block/io.c | 18 | --- a/tests/qemu-iotests/iotests.py |
13 | +++ b/block/io.c | 19 | +++ b/tests/qemu-iotests/iotests.py |
14 | @@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) | 20 | @@ -XXX,XX +XXX,XX @@ def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True |
15 | 21 | return qemu_tool(*qemu_io_wrap_args(args), | |
16 | static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) | 22 | check=check, combine_stdio=combine_stdio) |
17 | { | 23 | |
18 | + dst->pdiscard_alignment = MAX(dst->pdiscard_alignment, | 24 | -def qemu_io_pipe_and_status(*args): |
19 | + src->pdiscard_alignment); | 25 | - return qemu_tool_pipe_and_status('qemu-io', qemu_io_wrap_args(args)) |
20 | dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer); | 26 | - |
21 | dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer); | 27 | def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
22 | dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer, | 28 | result = qemu_io(*args, check=False) |
29 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) | ||
23 | -- | 30 | -- |
24 | 2.31.1 | 31 | 2.35.1 |
25 | diff view generated by jsdifflib |
1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | backend_defaults property allow users to control if default block | 3 | Like qemu-img, qemu-io returning 0 should be the norm and not the |
4 | properties should be decided with backend information. | 4 | exception. Remove all calls to qemu_io_silent that just assert the |
5 | return code is zero (That's every last call, as it turns out), and | ||
6 | replace them with a normal qemu_io() call. | ||
5 | 7 | ||
6 | If it is off, any backend information will be discarded, which is | 8 | qemu_io_silent_check() appeared to have been unused already. |
7 | suitable if you plan to perform live migration to a different disk backend. | ||
8 | 9 | ||
9 | If it is on, a block device may utilize backend information more | 10 | Signed-off-by: John Snow <jsnow@redhat.com> |
10 | aggressively. | 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> | ||
15 | --- | ||
16 | tests/qemu-iotests/216 | 12 +++++----- | ||
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(-) | ||
11 | 27 | ||
12 | By default, it is auto, which uses backend information for block | 28 | diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216 |
13 | sizes and ignores the others, which is consistent with the older | 29 | index XXXXXXX..XXXXXXX 100755 |
14 | versions. | 30 | --- a/tests/qemu-iotests/216 |
15 | 31 | +++ b/tests/qemu-iotests/216 | |
16 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> | 32 | @@ -XXX,XX +XXX,XX @@ |
17 | Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com | 33 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> |
18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 34 | |
19 | --- | 35 | import iotests |
20 | include/hw/block/block.h | 3 +++ | 36 | -from iotests import log, qemu_img, qemu_io_silent |
21 | hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++---- | 37 | +from iotests import log, qemu_img, qemu_io |
22 | tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++ | 38 | |
23 | 3 files changed, 79 insertions(+), 4 deletions(-) | 39 | # Need backing file support |
24 | 40 | iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'], | |
25 | diff --git a/include/hw/block/block.h b/include/hw/block/block.h | 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 | ||
26 | index XXXXXXX..XXXXXXX 100644 | 223 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/block/block.h | 224 | --- a/tests/qemu-iotests/iotests.py |
28 | +++ b/include/hw/block/block.h | 225 | +++ b/tests/qemu-iotests/iotests.py |
29 | @@ -XXX,XX +XXX,XX @@ | 226 | @@ -XXX,XX +XXX,XX @@ def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
30 | 227 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) | |
31 | typedef struct BlockConf { | 228 | return result |
32 | BlockBackend *blk; | 229 | |
33 | + OnOffAuto backend_defaults; | 230 | -def qemu_io_silent(*args): |
34 | uint32_t physical_block_size; | 231 | - '''Run qemu-io and return the exit code, suppressing stdout''' |
35 | uint32_t logical_block_size; | 232 | - args = qemu_io_wrap_args(args) |
36 | uint32_t min_io_size; | 233 | - result = subprocess.run(args, stdout=subprocess.DEVNULL, check=False) |
37 | @@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) | 234 | - if result.returncode < 0: |
38 | } | 235 | - sys.stderr.write('qemu-io received signal %i: %s\n' % |
39 | 236 | - (-result.returncode, ' '.join(args))) | |
40 | #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \ | 237 | - return result.returncode |
41 | + DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \ | 238 | - |
42 | + _conf.backend_defaults, ON_OFF_AUTO_AUTO), \ | 239 | -def qemu_io_silent_check(*args): |
43 | DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ | 240 | - '''Run qemu-io and return the true if subprocess returned 0''' |
44 | _conf.logical_block_size), \ | 241 | - args = qemu_io_wrap_args(args) |
45 | DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ | 242 | - result = subprocess.run(args, stdout=subprocess.DEVNULL, |
46 | diff --git a/hw/block/block.c b/hw/block/block.c | 243 | - stderr=subprocess.STDOUT, check=False) |
47 | index XXXXXXX..XXXXXXX 100644 | 244 | - return result.returncode == 0 |
48 | --- a/hw/block/block.c | 245 | - |
49 | +++ b/hw/block/block.c | 246 | class QemuIoInteractive: |
50 | @@ -XXX,XX +XXX,XX @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp) | 247 | def __init__(self, *args): |
51 | { | 248 | self.args = qemu_io_wrap_args(args) |
52 | BlockBackend *blk = conf->blk; | 249 | diff --git a/tests/qemu-iotests/tests/image-fleecing b/tests/qemu-iotests/tests/image-fleecing |
53 | BlockSizes blocksizes; | 250 | index XXXXXXX..XXXXXXX 100755 |
54 | - int backend_ret; | 251 | --- a/tests/qemu-iotests/tests/image-fleecing |
55 | + BlockDriverState *bs; | 252 | +++ b/tests/qemu-iotests/tests/image-fleecing |
56 | + bool use_blocksizes; | 253 | @@ -XXX,XX +XXX,XX @@ |
57 | + bool use_bs; | 254 | from subprocess import CalledProcessError |
58 | + | 255 | |
59 | + switch (conf->backend_defaults) { | 256 | import iotests |
60 | + case ON_OFF_AUTO_AUTO: | 257 | -from iotests import log, qemu_img, qemu_io, qemu_io_silent |
61 | + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); | 258 | +from iotests import log, qemu_img, qemu_io |
62 | + use_bs = false; | 259 | |
63 | + break; | 260 | iotests.script_initialize( |
64 | + | 261 | supported_fmts=['qcow2'], |
65 | + case ON_OFF_AUTO_ON: | 262 | @@ -XXX,XX +XXX,XX @@ def do_test(vm, use_cbw, use_snapshot_access_filter, base_img_path, |
66 | + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); | 263 | for p in overwrite + remainder: |
67 | + bs = blk_bs(blk); | 264 | cmd = 'read -P%s %s %s' % p |
68 | + use_bs = bs; | 265 | log(cmd) |
69 | + break; | 266 | - assert qemu_io_silent(base_img_path, '-c', cmd) == 0 |
70 | + | 267 | + qemu_io(base_img_path, '-c', cmd) |
71 | + case ON_OFF_AUTO_OFF: | 268 | |
72 | + use_blocksizes = false; | 269 | log('') |
73 | + use_bs = false; | 270 | log('Done') |
74 | + break; | 271 | diff --git a/tests/qemu-iotests/tests/mirror-ready-cancel-error b/tests/qemu-iotests/tests/mirror-ready-cancel-error |
75 | + | 272 | index XXXXXXX..XXXXXXX 100755 |
76 | + default: | 273 | --- a/tests/qemu-iotests/tests/mirror-ready-cancel-error |
77 | + abort(); | 274 | +++ b/tests/qemu-iotests/tests/mirror-ready-cancel-error |
78 | + } | 275 | @@ -XXX,XX +XXX,XX @@ class TestMirrorReadyCancelError(iotests.QMPTestCase): |
79 | 276 | # Ensure that mirror will copy something before READY so the | |
80 | - backend_ret = blk_probe_blocksizes(blk, &blocksizes); | 277 | # target format layer will forward the pre-READY flush to its |
81 | /* fill in detected values if they are not defined via qemu command line */ | 278 | # file child |
82 | if (!conf->physical_block_size) { | 279 | - assert iotests.qemu_io_silent('-c', 'write -P 1 0 64k', source) == 0 |
83 | - if (!backend_ret) { | 280 | + iotests.qemu_io('-c', 'write -P 1 0 64k', source) |
84 | + if (use_blocksizes) { | 281 | |
85 | conf->physical_block_size = blocksizes.phys; | 282 | self.vm = iotests.VM() |
86 | } else { | 283 | self.vm.launch() |
87 | conf->physical_block_size = BDRV_SECTOR_SIZE; | 284 | diff --git a/tests/qemu-iotests/tests/stream-error-on-reset b/tests/qemu-iotests/tests/stream-error-on-reset |
88 | } | 285 | index XXXXXXX..XXXXXXX 100755 |
89 | } | 286 | --- a/tests/qemu-iotests/tests/stream-error-on-reset |
90 | if (!conf->logical_block_size) { | 287 | +++ b/tests/qemu-iotests/tests/stream-error-on-reset |
91 | - if (!backend_ret) { | 288 | @@ -XXX,XX +XXX,XX @@ |
92 | + if (use_blocksizes) { | 289 | |
93 | conf->logical_block_size = blocksizes.log; | 290 | import os |
94 | } else { | 291 | import iotests |
95 | conf->logical_block_size = BDRV_SECTOR_SIZE; | 292 | -from iotests import imgfmt, qemu_img_create, qemu_io_silent, QMPTestCase |
96 | } | 293 | +from iotests import imgfmt, qemu_img_create, qemu_io, QMPTestCase |
97 | } | 294 | |
98 | + if (use_bs) { | 295 | |
99 | + if (!conf->opt_io_size) { | 296 | image_size = 1 * 1024 * 1024 |
100 | + conf->opt_io_size = bs->bl.opt_transfer; | 297 | @@ -XXX,XX +XXX,XX @@ class TestStreamErrorOnReset(QMPTestCase): |
101 | + } | 298 | - top image is attached to a virtio-scsi device |
102 | + if (conf->discard_granularity == -1) { | 299 | """ |
103 | + if (bs->bl.pdiscard_alignment) { | 300 | qemu_img_create('-f', imgfmt, base, str(image_size)) |
104 | + conf->discard_granularity = bs->bl.pdiscard_alignment; | 301 | - assert qemu_io_silent('-c', f'write 0 {data_size}', base) == 0 |
105 | + } else if (bs->bl.request_alignment != 1) { | 302 | + qemu_io('-c', f'write 0 {data_size}', base) |
106 | + conf->discard_granularity = bs->bl.request_alignment; | 303 | qemu_img_create('-f', imgfmt, top, str(image_size)) |
107 | + } | 304 | |
108 | + } | 305 | self.vm = iotests.VM() |
109 | + } | ||
110 | |||
111 | if (conf->logical_block_size > conf->physical_block_size) { | ||
112 | error_setg(errp, | ||
113 | diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/tests/qemu-iotests/172.out | ||
116 | +++ b/tests/qemu-iotests/172.out | ||
117 | @@ -XXX,XX +XXX,XX @@ Testing: | ||
118 | dev: floppy, id "" | ||
119 | unit = 0 (0x0) | ||
120 | drive = "floppy0" | ||
121 | + backend_defaults = "auto" | ||
122 | logical_block_size = 512 (512 B) | ||
123 | physical_block_size = 512 (512 B) | ||
124 | min_io_size = 0 (0 B) | ||
125 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 | ||
126 | dev: floppy, id "" | ||
127 | unit = 0 (0x0) | ||
128 | drive = "floppy0" | ||
129 | + backend_defaults = "auto" | ||
130 | logical_block_size = 512 (512 B) | ||
131 | physical_block_size = 512 (512 B) | ||
132 | min_io_size = 0 (0 B) | ||
133 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 | ||
134 | dev: floppy, id "" | ||
135 | unit = 1 (0x1) | ||
136 | drive = "floppy1" | ||
137 | + backend_defaults = "auto" | ||
138 | logical_block_size = 512 (512 B) | ||
139 | physical_block_size = 512 (512 B) | ||
140 | min_io_size = 0 (0 B) | ||
141 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 | ||
142 | dev: floppy, id "" | ||
143 | unit = 0 (0x0) | ||
144 | drive = "floppy0" | ||
145 | + backend_defaults = "auto" | ||
146 | logical_block_size = 512 (512 B) | ||
147 | physical_block_size = 512 (512 B) | ||
148 | min_io_size = 0 (0 B) | ||
149 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 | ||
150 | dev: floppy, id "" | ||
151 | unit = 1 (0x1) | ||
152 | drive = "floppy1" | ||
153 | + backend_defaults = "auto" | ||
154 | logical_block_size = 512 (512 B) | ||
155 | physical_block_size = 512 (512 B) | ||
156 | min_io_size = 0 (0 B) | ||
157 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 | ||
158 | dev: floppy, id "" | ||
159 | unit = 0 (0x0) | ||
160 | drive = "floppy0" | ||
161 | + backend_defaults = "auto" | ||
162 | logical_block_size = 512 (512 B) | ||
163 | physical_block_size = 512 (512 B) | ||
164 | min_io_size = 0 (0 B) | ||
165 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb | ||
166 | dev: floppy, id "" | ||
167 | unit = 1 (0x1) | ||
168 | drive = "floppy1" | ||
169 | + backend_defaults = "auto" | ||
170 | logical_block_size = 512 (512 B) | ||
171 | physical_block_size = 512 (512 B) | ||
172 | min_io_size = 0 (0 B) | ||
173 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb | ||
174 | dev: floppy, id "" | ||
175 | unit = 0 (0x0) | ||
176 | drive = "floppy0" | ||
177 | + backend_defaults = "auto" | ||
178 | logical_block_size = 512 (512 B) | ||
179 | physical_block_size = 512 (512 B) | ||
180 | min_io_size = 0 (0 B) | ||
181 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 | ||
182 | dev: floppy, id "" | ||
183 | unit = 0 (0x0) | ||
184 | drive = "floppy0" | ||
185 | + backend_defaults = "auto" | ||
186 | logical_block_size = 512 (512 B) | ||
187 | physical_block_size = 512 (512 B) | ||
188 | min_io_size = 0 (0 B) | ||
189 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 | ||
190 | dev: floppy, id "" | ||
191 | unit = 1 (0x1) | ||
192 | drive = "floppy1" | ||
193 | + backend_defaults = "auto" | ||
194 | logical_block_size = 512 (512 B) | ||
195 | physical_block_size = 512 (512 B) | ||
196 | min_io_size = 0 (0 B) | ||
197 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 | ||
198 | dev: floppy, id "" | ||
199 | unit = 0 (0x0) | ||
200 | drive = "floppy0" | ||
201 | + backend_defaults = "auto" | ||
202 | logical_block_size = 512 (512 B) | ||
203 | physical_block_size = 512 (512 B) | ||
204 | min_io_size = 0 (0 B) | ||
205 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t | ||
206 | dev: floppy, id "" | ||
207 | unit = 1 (0x1) | ||
208 | drive = "floppy1" | ||
209 | + backend_defaults = "auto" | ||
210 | logical_block_size = 512 (512 B) | ||
211 | physical_block_size = 512 (512 B) | ||
212 | min_io_size = 0 (0 B) | ||
213 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t | ||
214 | dev: floppy, id "" | ||
215 | unit = 0 (0x0) | ||
216 | drive = "floppy0" | ||
217 | + backend_defaults = "auto" | ||
218 | logical_block_size = 512 (512 B) | ||
219 | physical_block_size = 512 (512 B) | ||
220 | min_io_size = 0 (0 B) | ||
221 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 | ||
222 | dev: floppy, id "" | ||
223 | unit = 0 (0x0) | ||
224 | drive = "none0" | ||
225 | + backend_defaults = "auto" | ||
226 | logical_block_size = 512 (512 B) | ||
227 | physical_block_size = 512 (512 B) | ||
228 | min_io_size = 0 (0 B) | ||
229 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1 | ||
230 | dev: floppy, id "" | ||
231 | unit = 1 (0x1) | ||
232 | drive = "none0" | ||
233 | + backend_defaults = "auto" | ||
234 | logical_block_size = 512 (512 B) | ||
235 | physical_block_size = 512 (512 B) | ||
236 | min_io_size = 0 (0 B) | ||
237 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco | ||
238 | dev: floppy, id "" | ||
239 | unit = 1 (0x1) | ||
240 | drive = "none1" | ||
241 | + backend_defaults = "auto" | ||
242 | logical_block_size = 512 (512 B) | ||
243 | physical_block_size = 512 (512 B) | ||
244 | min_io_size = 0 (0 B) | ||
245 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco | ||
246 | dev: floppy, id "" | ||
247 | unit = 0 (0x0) | ||
248 | drive = "none0" | ||
249 | + backend_defaults = "auto" | ||
250 | logical_block_size = 512 (512 B) | ||
251 | physical_block_size = 512 (512 B) | ||
252 | min_io_size = 0 (0 B) | ||
253 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
254 | dev: floppy, id "" | ||
255 | unit = 1 (0x1) | ||
256 | drive = "none0" | ||
257 | + backend_defaults = "auto" | ||
258 | logical_block_size = 512 (512 B) | ||
259 | physical_block_size = 512 (512 B) | ||
260 | min_io_size = 0 (0 B) | ||
261 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
262 | dev: floppy, id "" | ||
263 | unit = 0 (0x0) | ||
264 | drive = "floppy0" | ||
265 | + backend_defaults = "auto" | ||
266 | logical_block_size = 512 (512 B) | ||
267 | physical_block_size = 512 (512 B) | ||
268 | min_io_size = 0 (0 B) | ||
269 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
270 | dev: floppy, id "" | ||
271 | unit = 1 (0x1) | ||
272 | drive = "none0" | ||
273 | + backend_defaults = "auto" | ||
274 | logical_block_size = 512 (512 B) | ||
275 | physical_block_size = 512 (512 B) | ||
276 | min_io_size = 0 (0 B) | ||
277 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
278 | dev: floppy, id "" | ||
279 | unit = 0 (0x0) | ||
280 | drive = "floppy0" | ||
281 | + backend_defaults = "auto" | ||
282 | logical_block_size = 512 (512 B) | ||
283 | physical_block_size = 512 (512 B) | ||
284 | min_io_size = 0 (0 B) | ||
285 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
286 | dev: floppy, id "" | ||
287 | unit = 0 (0x0) | ||
288 | drive = "none0" | ||
289 | + backend_defaults = "auto" | ||
290 | logical_block_size = 512 (512 B) | ||
291 | physical_block_size = 512 (512 B) | ||
292 | min_io_size = 0 (0 B) | ||
293 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
294 | dev: floppy, id "" | ||
295 | unit = 1 (0x1) | ||
296 | drive = "floppy1" | ||
297 | + backend_defaults = "auto" | ||
298 | logical_block_size = 512 (512 B) | ||
299 | physical_block_size = 512 (512 B) | ||
300 | min_io_size = 0 (0 B) | ||
301 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
302 | dev: floppy, id "" | ||
303 | unit = 0 (0x0) | ||
304 | drive = "none0" | ||
305 | + backend_defaults = "auto" | ||
306 | logical_block_size = 512 (512 B) | ||
307 | physical_block_size = 512 (512 B) | ||
308 | min_io_size = 0 (0 B) | ||
309 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
310 | dev: floppy, id "" | ||
311 | unit = 1 (0x1) | ||
312 | drive = "floppy1" | ||
313 | + backend_defaults = "auto" | ||
314 | logical_block_size = 512 (512 B) | ||
315 | physical_block_size = 512 (512 B) | ||
316 | min_io_size = 0 (0 B) | ||
317 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
318 | dev: floppy, id "" | ||
319 | unit = 1 (0x1) | ||
320 | drive = "none0" | ||
321 | + backend_defaults = "auto" | ||
322 | logical_block_size = 512 (512 B) | ||
323 | physical_block_size = 512 (512 B) | ||
324 | min_io_size = 0 (0 B) | ||
325 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
326 | dev: floppy, id "" | ||
327 | unit = 0 (0x0) | ||
328 | drive = "floppy0" | ||
329 | + backend_defaults = "auto" | ||
330 | logical_block_size = 512 (512 B) | ||
331 | physical_block_size = 512 (512 B) | ||
332 | min_io_size = 0 (0 B) | ||
333 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
334 | dev: floppy, id "" | ||
335 | unit = 1 (0x1) | ||
336 | drive = "none0" | ||
337 | + backend_defaults = "auto" | ||
338 | logical_block_size = 512 (512 B) | ||
339 | physical_block_size = 512 (512 B) | ||
340 | min_io_size = 0 (0 B) | ||
341 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
342 | dev: floppy, id "" | ||
343 | unit = 0 (0x0) | ||
344 | drive = "floppy0" | ||
345 | + backend_defaults = "auto" | ||
346 | logical_block_size = 512 (512 B) | ||
347 | physical_block_size = 512 (512 B) | ||
348 | min_io_size = 0 (0 B) | ||
349 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device | ||
350 | dev: floppy, id "" | ||
351 | unit = 0 (0x0) | ||
352 | drive = "none0" | ||
353 | + backend_defaults = "auto" | ||
354 | logical_block_size = 512 (512 B) | ||
355 | physical_block_size = 512 (512 B) | ||
356 | min_io_size = 0 (0 B) | ||
357 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy | ||
358 | dev: floppy, id "" | ||
359 | unit = 0 (0x0) | ||
360 | drive = "" | ||
361 | + backend_defaults = "auto" | ||
362 | logical_block_size = 512 (512 B) | ||
363 | physical_block_size = 512 (512 B) | ||
364 | min_io_size = 0 (0 B) | ||
365 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=120 | ||
366 | dev: floppy, id "" | ||
367 | unit = 0 (0x0) | ||
368 | drive = "" | ||
369 | + backend_defaults = "auto" | ||
370 | logical_block_size = 512 (512 B) | ||
371 | physical_block_size = 512 (512 B) | ||
372 | min_io_size = 0 (0 B) | ||
373 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=144 | ||
374 | dev: floppy, id "" | ||
375 | unit = 0 (0x0) | ||
376 | drive = "" | ||
377 | + backend_defaults = "auto" | ||
378 | logical_block_size = 512 (512 B) | ||
379 | physical_block_size = 512 (512 B) | ||
380 | min_io_size = 0 (0 B) | ||
381 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=288 | ||
382 | dev: floppy, id "" | ||
383 | unit = 0 (0x0) | ||
384 | drive = "" | ||
385 | + backend_defaults = "auto" | ||
386 | logical_block_size = 512 (512 B) | ||
387 | physical_block_size = 512 (512 B) | ||
388 | min_io_size = 0 (0 B) | ||
389 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t | ||
390 | dev: floppy, id "" | ||
391 | unit = 0 (0x0) | ||
392 | drive = "none0" | ||
393 | + backend_defaults = "auto" | ||
394 | logical_block_size = 512 (512 B) | ||
395 | physical_block_size = 512 (512 B) | ||
396 | min_io_size = 0 (0 B) | ||
397 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t | ||
398 | dev: floppy, id "" | ||
399 | unit = 0 (0x0) | ||
400 | drive = "none0" | ||
401 | + backend_defaults = "auto" | ||
402 | logical_block_size = 512 (512 B) | ||
403 | physical_block_size = 512 (512 B) | ||
404 | min_io_size = 0 (0 B) | ||
405 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical | ||
406 | dev: floppy, id "" | ||
407 | unit = 0 (0x0) | ||
408 | drive = "none0" | ||
409 | + backend_defaults = "auto" | ||
410 | logical_block_size = 512 (512 B) | ||
411 | physical_block_size = 512 (512 B) | ||
412 | min_io_size = 0 (0 B) | ||
413 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica | ||
414 | dev: floppy, id "" | ||
415 | unit = 0 (0x0) | ||
416 | drive = "none0" | ||
417 | + backend_defaults = "auto" | ||
418 | logical_block_size = 512 (512 B) | ||
419 | physical_block_size = 512 (512 B) | ||
420 | min_io_size = 0 (0 B) | ||
421 | -- | 306 | -- |
422 | 2.31.1 | 307 | 2.35.1 |
423 | diff view generated by jsdifflib |
1 | BHs must be deleted before the AioContext is finalized. If not, it's a | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | bug and probably indicates that some part of the program still expects | ||
3 | the BH to run in the future. That can lead to memory leaks, inconsistent | ||
4 | state, or just hangs. | ||
5 | 2 | ||
6 | Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize() | 3 | Just like qemu_img_log(), upgrade qemu_io_log() to enforce a return code |
7 | is difficult to debug because the assertion failure contains no | 4 | of zero by default. |
8 | information about the BH! | ||
9 | 5 | ||
10 | Use the QEMUBH name field added in the previous patch to show a useful | 6 | Tests that use qemu_io_log(): 242 245 255 274 303 307 nbd-reconnect-on-open |
11 | error when a leaked BH is detected. | ||
12 | 7 | ||
13 | Suggested-by: Eric Ernst <eric.g.ernst@gmail.com> | 8 | Signed-off-by: John Snow <jsnow@redhat.com> |
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 9 | Reviewed-by: Eric Blake <eblake@redhat.com> |
15 | Message-Id: <20210414200247.917496-3-stefanha@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> | ||
16 | --- | 13 | --- |
17 | util/async.c | 16 ++++++++++++++-- | 14 | tests/qemu-iotests/iotests.py | 5 +++-- |
18 | 1 file changed, 14 insertions(+), 2 deletions(-) | 15 | tests/qemu-iotests/tests/nbd-reconnect-on-open | 2 +- |
16 | 2 files changed, 4 insertions(+), 3 deletions(-) | ||
19 | 17 | ||
20 | diff --git a/util/async.c b/util/async.c | 18 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py |
21 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/util/async.c | 20 | --- a/tests/qemu-iotests/iotests.py |
23 | +++ b/util/async.c | 21 | +++ b/tests/qemu-iotests/iotests.py |
24 | @@ -XXX,XX +XXX,XX @@ aio_ctx_finalize(GSource *source) | 22 | @@ -XXX,XX +XXX,XX @@ def qemu_io(*args: str, check: bool = True, combine_stdio: bool = True |
25 | assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list)); | 23 | return qemu_tool(*qemu_io_wrap_args(args), |
26 | 24 | check=check, combine_stdio=combine_stdio) | |
27 | while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) { | 25 | |
28 | - /* qemu_bh_delete() must have been called on BHs in this AioContext */ | 26 | -def qemu_io_log(*args: str) -> 'subprocess.CompletedProcess[str]': |
29 | - assert(flags & BH_DELETED); | 27 | - result = qemu_io(*args, check=False) |
30 | + /* | 28 | +def qemu_io_log(*args: str, check: bool = True |
31 | + * qemu_bh_delete() must have been called on BHs in this AioContext. In | 29 | + ) -> 'subprocess.CompletedProcess[str]': |
32 | + * many cases memory leaks, hangs, or inconsistent state occur when a | 30 | + result = qemu_io(*args, check=check) |
33 | + * BH is leaked because something still expects it to run. | 31 | log(result.stdout, filters=[filter_testfiles, filter_qemu_io]) |
34 | + * | 32 | return result |
35 | + * If you hit this, fix the lifecycle of the BH so that | 33 | |
36 | + * qemu_bh_delete() and any associated cleanup is called before the | 34 | diff --git a/tests/qemu-iotests/tests/nbd-reconnect-on-open b/tests/qemu-iotests/tests/nbd-reconnect-on-open |
37 | + * AioContext is finalized. | 35 | index XXXXXXX..XXXXXXX 100755 |
38 | + */ | 36 | --- a/tests/qemu-iotests/tests/nbd-reconnect-on-open |
39 | + if (unlikely(!(flags & BH_DELETED))) { | 37 | +++ b/tests/qemu-iotests/tests/nbd-reconnect-on-open |
40 | + fprintf(stderr, "%s: BH '%s' leaked, aborting...\n", | 38 | @@ -XXX,XX +XXX,XX @@ def check_fail_to_connect(open_timeout): |
41 | + __func__, bh->name); | 39 | log(f'Check fail to connect with {open_timeout} seconds of timeout') |
42 | + abort(); | 40 | |
43 | + } | 41 | start_t = time.time() |
44 | 42 | - qemu_io_log(*create_args(open_timeout)) | |
45 | g_free(bh); | 43 | + qemu_io_log(*create_args(open_timeout), check=False) |
46 | } | 44 | delta_t = time.time() - start_t |
45 | |||
46 | max_delta = open_timeout + 0.2 | ||
47 | -- | 47 | -- |
48 | 2.31.1 | 48 | 2.35.1 |
49 | diff view generated by jsdifflib |
1 | It can be difficult to debug issues with BHs in production environments. | 1 | FUSE exports' allow-other option defaults to "auto", which means that it |
---|---|---|---|
2 | Although BHs can usually be identified by looking up their ->cb() | 2 | will try passing allow_other as a mount option, and fall back to not |
3 | function pointer, this requires debug information for the program. It is | 3 | using it when an error occurs. We make no effort to hide fusermount's |
4 | also not possible to print human-readable diagnostics about BHs because | 4 | error message (because it would be difficult, and because users might |
5 | they have no identifier. | 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. | ||
6 | 9 | ||
7 | This patch adds a name to each BH. The name is not unique per instance | 10 | We do not need allow_other here, though, so we can just pass |
8 | but differentiates between cb() functions, which is usually enough. It's | 11 | allow-other=off to fix that. |
9 | done by changing aio_bh_new() and friends to macros that stringify cb. | ||
10 | 12 | ||
11 | The next patch will use the name field when reporting leaked BHs. | 13 | Reported-by: Markus Armbruster <armbru@redhat.com> |
14 | Signed-off-by: Hanna Reitz <hreitz@redhat.com> | ||
15 | Message-Id: <20220421142435.569600-1-hreitz@redhat.com> | ||
16 | Tested-by: Markus Armbruster <armbru@redhat.com> | ||
17 | Tested-by: Eric Blake <eblake@redhat.com> | ||
18 | --- | ||
19 | tests/qemu-iotests/108 | 2 +- | ||
20 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
12 | 21 | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 22 | diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108 |
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 23 | index XXXXXXX..XXXXXXX 100755 |
15 | Message-Id: <20210414200247.917496-2-stefanha@redhat.com> | 24 | --- a/tests/qemu-iotests/108 |
16 | --- | 25 | +++ b/tests/qemu-iotests/108 |
17 | include/block/aio.h | 31 ++++++++++++++++++++++++++++--- | 26 | @@ -XXX,XX +XXX,XX @@ else |
18 | include/qemu/main-loop.h | 4 +++- | 27 | |
19 | tests/unit/ptimer-test-stubs.c | 2 +- | 28 | $QSD \ |
20 | util/async.c | 9 +++++++-- | 29 | --blockdev file,node-name=export-node,filename="$TEST_IMG" \ |
21 | util/main-loop.c | 4 ++-- | 30 | - --export fuse,id=fuse-export,node-name=export-node,mountpoint="$export_mp",writable=on,growable=off \ |
22 | 5 files changed, 41 insertions(+), 9 deletions(-) | 31 | + --export fuse,id=fuse-export,node-name=export-node,mountpoint="$export_mp",writable=on,growable=off,allow-other=off \ |
23 | 32 | --pidfile "$TEST_DIR/qsd.pid" \ | |
24 | diff --git a/include/block/aio.h b/include/block/aio.h | 33 | --daemonize |
25 | index XXXXXXX..XXXXXXX 100644 | 34 | fi |
26 | --- a/include/block/aio.h | ||
27 | +++ b/include/block/aio.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx); | ||
29 | /* Relinquish ownership of the AioContext. */ | ||
30 | void aio_context_release(AioContext *ctx); | ||
31 | |||
32 | +/** | ||
33 | + * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will | ||
34 | + * run only once and as soon as possible. | ||
35 | + * | ||
36 | + * @name: A human-readable identifier for debugging purposes. | ||
37 | + */ | ||
38 | +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
39 | + const char *name); | ||
40 | + | ||
41 | /** | ||
42 | * aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run | ||
43 | * only once and as soon as possible. | ||
44 | + * | ||
45 | + * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the | ||
46 | + * name string. | ||
47 | */ | ||
48 | -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque); | ||
49 | +#define aio_bh_schedule_oneshot(ctx, cb, opaque) \ | ||
50 | + aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb))) | ||
51 | |||
52 | /** | ||
53 | - * aio_bh_new: Allocate a new bottom half structure. | ||
54 | + * aio_bh_new_full: Allocate a new bottom half structure. | ||
55 | * | ||
56 | * Bottom halves are lightweight callbacks whose invocation is guaranteed | ||
57 | * to be wait-free, thread-safe and signal-safe. The #QEMUBH structure | ||
58 | * is opaque and must be allocated prior to its use. | ||
59 | + * | ||
60 | + * @name: A human-readable identifier for debugging purposes. | ||
61 | */ | ||
62 | -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque); | ||
63 | +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
64 | + const char *name); | ||
65 | + | ||
66 | +/** | ||
67 | + * aio_bh_new: Allocate a new bottom half structure | ||
68 | + * | ||
69 | + * A convenience wrapper for aio_bh_new_full() that uses the cb as the name | ||
70 | + * string. | ||
71 | + */ | ||
72 | +#define aio_bh_new(ctx, cb, opaque) \ | ||
73 | + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb))) | ||
74 | |||
75 | /** | ||
76 | * aio_notify: Force processing of pending events. | ||
77 | diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/include/qemu/main-loop.h | ||
80 | +++ b/include/qemu/main-loop.h | ||
81 | @@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms); | ||
82 | |||
83 | void qemu_fd_register(int fd); | ||
84 | |||
85 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); | ||
86 | +#define qemu_bh_new(cb, opaque) \ | ||
87 | + qemu_bh_new_full((cb), (opaque), (stringify(cb))) | ||
88 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name); | ||
89 | void qemu_bh_schedule_idle(QEMUBH *bh); | ||
90 | |||
91 | enum { | ||
92 | diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/tests/unit/ptimer-test-stubs.c | ||
95 | +++ b/tests/unit/ptimer-test-stubs.c | ||
96 | @@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask) | ||
97 | return deadline; | ||
98 | } | ||
99 | |||
100 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | ||
101 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) | ||
102 | { | ||
103 | QEMUBH *bh = g_new(QEMUBH, 1); | ||
104 | |||
105 | diff --git a/util/async.c b/util/async.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/util/async.c | ||
108 | +++ b/util/async.c | ||
109 | @@ -XXX,XX +XXX,XX @@ enum { | ||
110 | |||
111 | struct QEMUBH { | ||
112 | AioContext *ctx; | ||
113 | + const char *name; | ||
114 | QEMUBHFunc *cb; | ||
115 | void *opaque; | ||
116 | QSLIST_ENTRY(QEMUBH) next; | ||
117 | @@ -XXX,XX +XXX,XX @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags) | ||
118 | return bh; | ||
119 | } | ||
120 | |||
121 | -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
122 | +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, | ||
123 | + void *opaque, const char *name) | ||
124 | { | ||
125 | QEMUBH *bh; | ||
126 | bh = g_new(QEMUBH, 1); | ||
127 | @@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
128 | .ctx = ctx, | ||
129 | .cb = cb, | ||
130 | .opaque = opaque, | ||
131 | + .name = name, | ||
132 | }; | ||
133 | aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT); | ||
134 | } | ||
135 | |||
136 | -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
137 | +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
138 | + const char *name) | ||
139 | { | ||
140 | QEMUBH *bh; | ||
141 | bh = g_new(QEMUBH, 1); | ||
142 | @@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
143 | .ctx = ctx, | ||
144 | .cb = cb, | ||
145 | .opaque = opaque, | ||
146 | + .name = name, | ||
147 | }; | ||
148 | return bh; | ||
149 | } | ||
150 | diff --git a/util/main-loop.c b/util/main-loop.c | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/util/main-loop.c | ||
153 | +++ b/util/main-loop.c | ||
154 | @@ -XXX,XX +XXX,XX @@ void main_loop_wait(int nonblocking) | ||
155 | |||
156 | /* Functions to operate on the main QEMU AioContext. */ | ||
157 | |||
158 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | ||
159 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) | ||
160 | { | ||
161 | - return aio_bh_new(qemu_aio_context, cb, opaque); | ||
162 | + return aio_bh_new_full(qemu_aio_context, cb, opaque, name); | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | -- | 35 | -- |
167 | 2.31.1 | 36 | 2.35.1 |
168 | diff view generated by jsdifflib |