1 | The following changes since commit 36609b4fa36f0ac934874371874416f7533a5408: | 1 | The following changes since commit eaefea537b476cb853e2edbdc68e969ec777e4bb: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/palmer/tags/palmer-for-master-4.2-sf1' into staging (2019-11-02 17:59:03 +0000) | 3 | Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-fetch' into staging (2017-12-18 14:17:42 +0000) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/stefanha/qemu.git tags/block-pull-request | 7 | git://github.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 9fdd7860adec188ed50d2530e9a819e8d953f9bb: | 9 | for you to fetch changes up to 7a9dda0d7f9831c2432620dcfefdadbb7ae888dc: |
10 | 10 | ||
11 | image-fuzzer: Use OSerror.strerror instead of tuple subscript (2019-11-05 16:36:11 +0100) | 11 | qemu-iotests: add 203 savevm with IOThreads test (2017-12-19 10:25:09 +0000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Let's get the image fuzzer Python 3 changes merged in QEMU 4.2. | 16 | v2: |
17 | * Fixed incorrect virtio_blk_data_plane_create() local_err refactoring in | ||
18 | "hw/block: Use errp directly rather than local_err" that broke virtio-blk | ||
19 | over virtio-mmio [Peter] | ||
17 | 20 | ||
18 | ---------------------------------------------------------------- | 21 | ---------------------------------------------------------------- |
19 | 22 | ||
20 | Eduardo Habkost (11): | 23 | Mao Zhongyi (4): |
21 | image-fuzzer: Open image files in binary mode | 24 | hw/block/nvme: Convert to realize |
22 | image-fuzzer: Write bytes instead of string to image file | 25 | hw/block: Fix the return type |
23 | image-fuzzer: Explicitly use integer division operator | 26 | hw/block: Use errp directly rather than local_err |
24 | image-fuzzer: Use io.StringIO | 27 | dev-storage: Fix the unusual function name |
25 | image-fuzzer: Use %r for all fiels at Field.__repr__() | ||
26 | image-fuzzer: Return bytes objects on string fuzzing functions | ||
27 | image-fuzzer: Use bytes constant for field values | ||
28 | image-fuzzer: Encode file name and file format to bytes | ||
29 | image-fuzzer: Run using python3 | ||
30 | image-fuzzer: Use errors parameter of subprocess.Popen() | ||
31 | image-fuzzer: Use OSerror.strerror instead of tuple subscript | ||
32 | 28 | ||
33 | tests/image-fuzzer/qcow2/__init__.py | 1 - | 29 | Mark Kanda (2): |
34 | tests/image-fuzzer/qcow2/fuzz.py | 54 +++++++++++++------------- | 30 | virtio-blk: make queue size configurable |
35 | tests/image-fuzzer/qcow2/layout.py | 57 ++++++++++++++-------------- | 31 | virtio-blk: reject configs with logical block size > physical block |
36 | tests/image-fuzzer/runner.py | 16 ++++---- | 32 | size |
37 | 4 files changed, 63 insertions(+), 65 deletions(-) | 33 | |
34 | Paolo Bonzini (1): | ||
35 | block: avoid recursive AioContext acquire in bdrv_inactivate_all() | ||
36 | |||
37 | Stefan Hajnoczi (16): | ||
38 | coroutine: simplify co_aio_sleep_ns() prototype | ||
39 | qdev: drop unused #include "sysemu/iothread.h" | ||
40 | blockdev: hold AioContext for bdrv_unref() in | ||
41 | external_snapshot_clean() | ||
42 | block: don't keep AioContext acquired after | ||
43 | external_snapshot_prepare() | ||
44 | block: don't keep AioContext acquired after drive_backup_prepare() | ||
45 | block: don't keep AioContext acquired after blockdev_backup_prepare() | ||
46 | block: don't keep AioContext acquired after | ||
47 | internal_snapshot_prepare() | ||
48 | block: drop unused BlockDirtyBitmapState->aio_context field | ||
49 | iothread: add iothread_by_id() API | ||
50 | blockdev: add x-blockdev-set-iothread testing command | ||
51 | qemu-iotests: add 202 external snapshots IOThread test | ||
52 | docs: mark nested AioContext locking as a legacy API | ||
53 | blockdev: add x-blockdev-set-iothread force boolean | ||
54 | iotests: add VM.add_object() | ||
55 | iothread: fix iothread_stop() race condition | ||
56 | qemu-iotests: add 203 savevm with IOThreads test | ||
57 | |||
58 | docs/devel/multiple-iothreads.txt | 7 +- | ||
59 | qapi/block-core.json | 40 ++++++ | ||
60 | hw/block/dataplane/virtio-blk.h | 2 +- | ||
61 | include/hw/block/block.h | 4 +- | ||
62 | include/hw/virtio/virtio-blk.h | 1 + | ||
63 | include/qemu/coroutine.h | 6 +- | ||
64 | include/sysemu/iothread.h | 4 +- | ||
65 | block.c | 14 ++- | ||
66 | block/null.c | 3 +- | ||
67 | block/sheepdog.c | 3 +- | ||
68 | blockdev.c | 259 +++++++++++++++++++++++++++----------- | ||
69 | hw/block/block.c | 15 ++- | ||
70 | hw/block/dataplane/virtio-blk.c | 12 +- | ||
71 | hw/block/fdc.c | 17 +-- | ||
72 | hw/block/nvme.c | 23 ++-- | ||
73 | hw/block/virtio-blk.c | 30 +++-- | ||
74 | hw/core/qdev-properties-system.c | 1 - | ||
75 | hw/ide/qdev.c | 12 +- | ||
76 | hw/scsi/scsi-disk.c | 13 +- | ||
77 | hw/usb/dev-storage.c | 29 ++--- | ||
78 | iothread.c | 27 +++- | ||
79 | util/qemu-coroutine-sleep.c | 4 +- | ||
80 | tests/qemu-iotests/202 | 95 ++++++++++++++ | ||
81 | tests/qemu-iotests/202.out | 11 ++ | ||
82 | tests/qemu-iotests/203 | 59 +++++++++ | ||
83 | tests/qemu-iotests/203.out | 6 + | ||
84 | tests/qemu-iotests/group | 2 + | ||
85 | tests/qemu-iotests/iotests.py | 5 + | ||
86 | 28 files changed, 531 insertions(+), 173 deletions(-) | ||
87 | create mode 100755 tests/qemu-iotests/202 | ||
88 | create mode 100644 tests/qemu-iotests/202.out | ||
89 | create mode 100755 tests/qemu-iotests/203 | ||
90 | create mode 100644 tests/qemu-iotests/203.out | ||
38 | 91 | ||
39 | -- | 92 | -- |
40 | 2.23.0 | 93 | 2.14.3 |
41 | 94 | ||
42 | 95 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The AioContext pointer argument to co_aio_sleep_ns() is only used for | ||
2 | the sleep timer. It does not affect where the caller coroutine is | ||
3 | resumed. | ||
1 | 4 | ||
5 | Due to changes to coroutine and AIO APIs it is now possible to drop the | ||
6 | AioContext pointer argument. This is safe to do since no caller has | ||
7 | specific requirements for which AioContext the timer must run in. | ||
8 | |||
9 | This patch drops the AioContext pointer argument and renames the | ||
10 | function to simplify the API. | ||
11 | |||
12 | Reported-by: Paolo Bonzini <pbonzini@redhat.com> | ||
13 | Reported-by: Eric Blake <eblake@redhat.com> | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
16 | Message-id: 20171109102652.6360-1-stefanha@redhat.com | ||
17 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
18 | --- | ||
19 | include/qemu/coroutine.h | 6 +----- | ||
20 | block/null.c | 3 +-- | ||
21 | block/sheepdog.c | 3 +-- | ||
22 | util/qemu-coroutine-sleep.c | 4 ++-- | ||
23 | 4 files changed, 5 insertions(+), 11 deletions(-) | ||
24 | |||
25 | diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/qemu/coroutine.h | ||
28 | +++ b/include/qemu/coroutine.h | ||
29 | @@ -XXX,XX +XXX,XX @@ void qemu_co_rwlock_unlock(CoRwlock *lock); | ||
30 | |||
31 | /** | ||
32 | * Yield the coroutine for a given duration | ||
33 | - * | ||
34 | - * Behaves similarly to co_sleep_ns(), but the sleeping coroutine will be | ||
35 | - * resumed when using aio_poll(). | ||
36 | */ | ||
37 | -void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type, | ||
38 | - int64_t ns); | ||
39 | +void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns); | ||
40 | |||
41 | /** | ||
42 | * Yield until a file descriptor becomes readable | ||
43 | diff --git a/block/null.c b/block/null.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/block/null.c | ||
46 | +++ b/block/null.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn int null_co_common(BlockDriverState *bs) | ||
48 | BDRVNullState *s = bs->opaque; | ||
49 | |||
50 | if (s->latency_ns) { | ||
51 | - co_aio_sleep_ns(bdrv_get_aio_context(bs), QEMU_CLOCK_REALTIME, | ||
52 | - s->latency_ns); | ||
53 | + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, s->latency_ns); | ||
54 | } | ||
55 | return 0; | ||
56 | } | ||
57 | diff --git a/block/sheepdog.c b/block/sheepdog.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/block/sheepdog.c | ||
60 | +++ b/block/sheepdog.c | ||
61 | @@ -XXX,XX +XXX,XX @@ static coroutine_fn void reconnect_to_sdog(void *opaque) | ||
62 | if (s->fd < 0) { | ||
63 | DPRINTF("Wait for connection to be established\n"); | ||
64 | error_report_err(local_err); | ||
65 | - co_aio_sleep_ns(bdrv_get_aio_context(s->bs), QEMU_CLOCK_REALTIME, | ||
66 | - 1000000000ULL); | ||
67 | + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000000ULL); | ||
68 | } | ||
69 | }; | ||
70 | |||
71 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/util/qemu-coroutine-sleep.c | ||
74 | +++ b/util/qemu-coroutine-sleep.c | ||
75 | @@ -XXX,XX +XXX,XX @@ static void co_sleep_cb(void *opaque) | ||
76 | aio_co_wake(sleep_cb->co); | ||
77 | } | ||
78 | |||
79 | -void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type, | ||
80 | - int64_t ns) | ||
81 | +void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | ||
82 | { | ||
83 | + AioContext *ctx = qemu_get_current_aio_context(); | ||
84 | CoSleepCB sleep_cb = { | ||
85 | .co = qemu_coroutine_self(), | ||
86 | }; | ||
87 | -- | ||
88 | 2.14.3 | ||
89 | |||
90 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
1 | 2 | ||
3 | Convert nvme_init() to realize and rename it to nvme_realize(). | ||
4 | |||
5 | Cc: John Snow <jsnow@redhat.com> | ||
6 | Cc: Keith Busch <keith.busch@intel.com> | ||
7 | Cc: Kevin Wolf <kwolf@redhat.com> | ||
8 | Cc: Max Reitz <mreitz@redhat.com> | ||
9 | Cc: Markus Armbruster <armbru@redhat.com> | ||
10 | |||
11 | Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
12 | Message-id: 2882e72d795e04cbe2120f569d551aef2467ac60.1511317952.git.maozy.fnst@cn.fujitsu.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | hw/block/nvme.c | 18 ++++++++++-------- | ||
16 | 1 file changed, 10 insertions(+), 8 deletions(-) | ||
17 | |||
18 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/block/nvme.c | ||
21 | +++ b/hw/block/nvme.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvme_cmb_ops = { | ||
23 | }, | ||
24 | }; | ||
25 | |||
26 | -static int nvme_init(PCIDevice *pci_dev) | ||
27 | +static void nvme_realize(PCIDevice *pci_dev, Error **errp) | ||
28 | { | ||
29 | NvmeCtrl *n = NVME(pci_dev); | ||
30 | NvmeIdCtrl *id = &n->id_ctrl; | ||
31 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev) | ||
32 | Error *local_err = NULL; | ||
33 | |||
34 | if (!n->conf.blk) { | ||
35 | - return -1; | ||
36 | + error_setg(errp, "drive property not set"); | ||
37 | + return; | ||
38 | } | ||
39 | |||
40 | bs_size = blk_getlength(n->conf.blk); | ||
41 | if (bs_size < 0) { | ||
42 | - return -1; | ||
43 | + error_setg(errp, "could not get backing file size"); | ||
44 | + return; | ||
45 | } | ||
46 | |||
47 | blkconf_serial(&n->conf, &n->serial); | ||
48 | if (!n->serial) { | ||
49 | - return -1; | ||
50 | + error_setg(errp, "serial property not set"); | ||
51 | + return; | ||
52 | } | ||
53 | blkconf_blocksizes(&n->conf); | ||
54 | blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), | ||
55 | false, &local_err); | ||
56 | if (local_err) { | ||
57 | - error_report_err(local_err); | ||
58 | - return -1; | ||
59 | + error_propagate(errp, local_err); | ||
60 | + return; | ||
61 | } | ||
62 | |||
63 | pci_conf = pci_dev->config; | ||
64 | @@ -XXX,XX +XXX,XX @@ static int nvme_init(PCIDevice *pci_dev) | ||
65 | cpu_to_le64(n->ns_size >> | ||
66 | id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); | ||
67 | } | ||
68 | - return 0; | ||
69 | } | ||
70 | |||
71 | static void nvme_exit(PCIDevice *pci_dev) | ||
72 | @@ -XXX,XX +XXX,XX @@ static void nvme_class_init(ObjectClass *oc, void *data) | ||
73 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
74 | PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc); | ||
75 | |||
76 | - pc->init = nvme_init; | ||
77 | + pc->realize = nvme_realize; | ||
78 | pc->exit = nvme_exit; | ||
79 | pc->class_id = PCI_CLASS_STORAGE_EXPRESS; | ||
80 | pc->vendor_id = PCI_VENDOR_ID_INTEL; | ||
81 | -- | ||
82 | 2.14.3 | ||
83 | |||
84 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
1 | 2 | ||
3 | When the function no success value to transmit, it usually make the | ||
4 | function return void. It has turned out not to be a success, because | ||
5 | it means that the extra local_err variable and error_propagate() will | ||
6 | be needed. It leads to cumbersome code, therefore, transmit success/ | ||
7 | failure in the return value is worth. | ||
8 | |||
9 | So fix the return type of blkconf_apply_backend_options(), | ||
10 | blkconf_geometry() and virtio_blk_data_plane_create() to avoid it. | ||
11 | |||
12 | Cc: John Snow <jsnow@redhat.com> | ||
13 | Cc: Kevin Wolf <kwolf@redhat.com> | ||
14 | Cc: Max Reitz <mreitz@redhat.com> | ||
15 | Cc: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | |||
17 | Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
18 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | Message-id: ac0edc1fc70c4457e5cec94405eb7d1f89f9c2c1.1511317952.git.maozy.fnst@cn.fujitsu.com | ||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | --- | ||
22 | hw/block/dataplane/virtio-blk.h | 2 +- | ||
23 | include/hw/block/block.h | 4 ++-- | ||
24 | hw/block/block.c | 15 +++++++++------ | ||
25 | hw/block/dataplane/virtio-blk.c | 12 +++++++----- | ||
26 | 4 files changed, 19 insertions(+), 14 deletions(-) | ||
27 | |||
28 | diff --git a/hw/block/dataplane/virtio-blk.h b/hw/block/dataplane/virtio-blk.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/hw/block/dataplane/virtio-blk.h | ||
31 | +++ b/hw/block/dataplane/virtio-blk.h | ||
32 | @@ -XXX,XX +XXX,XX @@ | ||
33 | |||
34 | typedef struct VirtIOBlockDataPlane VirtIOBlockDataPlane; | ||
35 | |||
36 | -void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
37 | +bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
38 | VirtIOBlockDataPlane **dataplane, | ||
39 | Error **errp); | ||
40 | void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s); | ||
41 | diff --git a/include/hw/block/block.h b/include/hw/block/block.h | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/include/hw/block/block.h | ||
44 | +++ b/include/hw/block/block.h | ||
45 | @@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) | ||
46 | /* Configuration helpers */ | ||
47 | |||
48 | void blkconf_serial(BlockConf *conf, char **serial); | ||
49 | -void blkconf_geometry(BlockConf *conf, int *trans, | ||
50 | +bool blkconf_geometry(BlockConf *conf, int *trans, | ||
51 | unsigned cyls_max, unsigned heads_max, unsigned secs_max, | ||
52 | Error **errp); | ||
53 | void blkconf_blocksizes(BlockConf *conf); | ||
54 | -void blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
55 | +bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
56 | bool resizable, Error **errp); | ||
57 | |||
58 | /* Hard disk geometry */ | ||
59 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/hw/block/block.c | ||
62 | +++ b/hw/block/block.c | ||
63 | @@ -XXX,XX +XXX,XX @@ void blkconf_blocksizes(BlockConf *conf) | ||
64 | } | ||
65 | } | ||
66 | |||
67 | -void blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
68 | +bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
69 | bool resizable, Error **errp) | ||
70 | { | ||
71 | BlockBackend *blk = conf->blk; | ||
72 | @@ -XXX,XX +XXX,XX @@ void blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
73 | |||
74 | ret = blk_set_perm(blk, perm, shared_perm, errp); | ||
75 | if (ret < 0) { | ||
76 | - return; | ||
77 | + return false; | ||
78 | } | ||
79 | |||
80 | switch (conf->wce) { | ||
81 | @@ -XXX,XX +XXX,XX @@ void blkconf_apply_backend_options(BlockConf *conf, bool readonly, | ||
82 | |||
83 | blk_set_enable_write_cache(blk, wce); | ||
84 | blk_set_on_error(blk, rerror, werror); | ||
85 | + | ||
86 | + return true; | ||
87 | } | ||
88 | |||
89 | -void blkconf_geometry(BlockConf *conf, int *ptrans, | ||
90 | +bool blkconf_geometry(BlockConf *conf, int *ptrans, | ||
91 | unsigned cyls_max, unsigned heads_max, unsigned secs_max, | ||
92 | Error **errp) | ||
93 | { | ||
94 | @@ -XXX,XX +XXX,XX @@ void blkconf_geometry(BlockConf *conf, int *ptrans, | ||
95 | if (conf->cyls || conf->heads || conf->secs) { | ||
96 | if (conf->cyls < 1 || conf->cyls > cyls_max) { | ||
97 | error_setg(errp, "cyls must be between 1 and %u", cyls_max); | ||
98 | - return; | ||
99 | + return false; | ||
100 | } | ||
101 | if (conf->heads < 1 || conf->heads > heads_max) { | ||
102 | error_setg(errp, "heads must be between 1 and %u", heads_max); | ||
103 | - return; | ||
104 | + return false; | ||
105 | } | ||
106 | if (conf->secs < 1 || conf->secs > secs_max) { | ||
107 | error_setg(errp, "secs must be between 1 and %u", secs_max); | ||
108 | - return; | ||
109 | + return false; | ||
110 | } | ||
111 | } | ||
112 | + return true; | ||
113 | } | ||
114 | diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c | ||
115 | index XXXXXXX..XXXXXXX 100644 | ||
116 | --- a/hw/block/dataplane/virtio-blk.c | ||
117 | +++ b/hw/block/dataplane/virtio-blk.c | ||
118 | @@ -XXX,XX +XXX,XX @@ static void notify_guest_bh(void *opaque) | ||
119 | } | ||
120 | |||
121 | /* Context: QEMU global mutex held */ | ||
122 | -void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
123 | +bool virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
124 | VirtIOBlockDataPlane **dataplane, | ||
125 | Error **errp) | ||
126 | { | ||
127 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
128 | error_setg(errp, | ||
129 | "device is incompatible with iothread " | ||
130 | "(transport does not support notifiers)"); | ||
131 | - return; | ||
132 | + return false; | ||
133 | } | ||
134 | if (!virtio_device_ioeventfd_enabled(vdev)) { | ||
135 | error_setg(errp, "ioeventfd is required for iothread"); | ||
136 | - return; | ||
137 | + return false; | ||
138 | } | ||
139 | |||
140 | /* If dataplane is (re-)enabled while the guest is running there could | ||
141 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
142 | */ | ||
143 | if (blk_op_is_blocked(conf->conf.blk, BLOCK_OP_TYPE_DATAPLANE, errp)) { | ||
144 | error_prepend(errp, "cannot start virtio-blk dataplane: "); | ||
145 | - return; | ||
146 | + return false; | ||
147 | } | ||
148 | } | ||
149 | /* Don't try if transport does not support notifiers. */ | ||
150 | if (!virtio_device_ioeventfd_enabled(vdev)) { | ||
151 | - return; | ||
152 | + return false; | ||
153 | } | ||
154 | |||
155 | s = g_new0(VirtIOBlockDataPlane, 1); | ||
156 | @@ -XXX,XX +XXX,XX @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf, | ||
157 | s->batch_notify_vqs = bitmap_new(conf->num_queues); | ||
158 | |||
159 | *dataplane = s; | ||
160 | + | ||
161 | + return true; | ||
162 | } | ||
163 | |||
164 | /* Context: QEMU global mutex held */ | ||
165 | -- | ||
166 | 2.14.3 | ||
167 | |||
168 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | |
2 | |||
3 | [Drop virtio_blk_data_plane_create() change that misinterprets return | ||
4 | value when the virtio transport does not support dataplane. | ||
5 | --Stefan] | ||
6 | |||
7 | Cc: John Snow <jsnow@redhat.com> | ||
8 | Cc: Kevin Wolf <kwolf@redhat.com> | ||
9 | Cc: Max Reitz <mreitz@redhat.com> | ||
10 | Cc: Keith Busch <keith.busch@intel.com> | ||
11 | Cc: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Cc: "Michael S. Tsirkin" <mst@redhat.com> | ||
13 | Cc: Paolo Bonzini <pbonzini@redhat.com> | ||
14 | Cc: Gerd Hoffmann <kraxel@redhat.com> | ||
15 | Cc: Markus Armbruster <armbru@redhat.com> | ||
16 | |||
17 | Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
18 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
19 | Message-id: e77848d3735ba590f23ffbf8094379c646c33d79.1511317952.git.maozy.fnst@cn.fujitsu.com | ||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | --- | ||
22 | hw/block/fdc.c | 17 ++++++----------- | ||
23 | hw/block/nvme.c | 7 ++----- | ||
24 | hw/block/virtio-blk.c | 13 +++++-------- | ||
25 | hw/ide/qdev.c | 12 ++++-------- | ||
26 | hw/scsi/scsi-disk.c | 13 ++++--------- | ||
27 | hw/usb/dev-storage.c | 9 +++------ | ||
28 | 6 files changed, 24 insertions(+), 47 deletions(-) | ||
29 | |||
30 | diff --git a/hw/block/fdc.c b/hw/block/fdc.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/block/fdc.c | ||
33 | +++ b/hw/block/fdc.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void fd_revalidate(FDrive *drv) | ||
35 | static void fd_change_cb(void *opaque, bool load, Error **errp) | ||
36 | { | ||
37 | FDrive *drive = opaque; | ||
38 | - Error *local_err = NULL; | ||
39 | |||
40 | if (!load) { | ||
41 | blk_set_perm(drive->blk, 0, BLK_PERM_ALL, &error_abort); | ||
42 | } else { | ||
43 | - blkconf_apply_backend_options(drive->conf, | ||
44 | - blk_is_read_only(drive->blk), false, | ||
45 | - &local_err); | ||
46 | - if (local_err) { | ||
47 | - error_propagate(errp, local_err); | ||
48 | + if (!blkconf_apply_backend_options(drive->conf, | ||
49 | + blk_is_read_only(drive->blk), false, | ||
50 | + errp)) { | ||
51 | return; | ||
52 | } | ||
53 | } | ||
54 | @@ -XXX,XX +XXX,XX @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) | ||
55 | FloppyDrive *dev = FLOPPY_DRIVE(qdev); | ||
56 | FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus); | ||
57 | FDrive *drive; | ||
58 | - Error *local_err = NULL; | ||
59 | int ret; | ||
60 | |||
61 | if (dev->unit == -1) { | ||
62 | @@ -XXX,XX +XXX,XX @@ static void floppy_drive_realize(DeviceState *qdev, Error **errp) | ||
63 | dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO; | ||
64 | dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO; | ||
65 | |||
66 | - blkconf_apply_backend_options(&dev->conf, blk_is_read_only(dev->conf.blk), | ||
67 | - false, &local_err); | ||
68 | - if (local_err) { | ||
69 | - error_propagate(errp, local_err); | ||
70 | + if (!blkconf_apply_backend_options(&dev->conf, | ||
71 | + blk_is_read_only(dev->conf.blk), | ||
72 | + false, errp)) { | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | diff --git a/hw/block/nvme.c b/hw/block/nvme.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/hw/block/nvme.c | ||
79 | +++ b/hw/block/nvme.c | ||
80 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) | ||
81 | int i; | ||
82 | int64_t bs_size; | ||
83 | uint8_t *pci_conf; | ||
84 | - Error *local_err = NULL; | ||
85 | |||
86 | if (!n->conf.blk) { | ||
87 | error_setg(errp, "drive property not set"); | ||
88 | @@ -XXX,XX +XXX,XX @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) | ||
89 | return; | ||
90 | } | ||
91 | blkconf_blocksizes(&n->conf); | ||
92 | - blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), | ||
93 | - false, &local_err); | ||
94 | - if (local_err) { | ||
95 | - error_propagate(errp, local_err); | ||
96 | + if (!blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), | ||
97 | + false, errp)) { | ||
98 | return; | ||
99 | } | ||
100 | |||
101 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/hw/block/virtio-blk.c | ||
104 | +++ b/hw/block/virtio-blk.c | ||
105 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) | ||
106 | } | ||
107 | |||
108 | blkconf_serial(&conf->conf, &conf->serial); | ||
109 | - blkconf_apply_backend_options(&conf->conf, | ||
110 | - blk_is_read_only(conf->conf.blk), true, | ||
111 | - &err); | ||
112 | - if (err) { | ||
113 | - error_propagate(errp, err); | ||
114 | + if (!blkconf_apply_backend_options(&conf->conf, | ||
115 | + blk_is_read_only(conf->conf.blk), true, | ||
116 | + errp)) { | ||
117 | return; | ||
118 | } | ||
119 | s->original_wce = blk_enable_write_cache(conf->conf.blk); | ||
120 | - blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, &err); | ||
121 | - if (err) { | ||
122 | - error_propagate(errp, err); | ||
123 | + if (!blkconf_geometry(&conf->conf, NULL, 65535, 255, 255, errp)) { | ||
124 | return; | ||
125 | } | ||
126 | + | ||
127 | blkconf_blocksizes(&conf->conf); | ||
128 | |||
129 | virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, | ||
130 | diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/hw/ide/qdev.c | ||
133 | +++ b/hw/ide/qdev.c | ||
134 | @@ -XXX,XX +XXX,XX @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) | ||
135 | { | ||
136 | IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); | ||
137 | IDEState *s = bus->ifs + dev->unit; | ||
138 | - Error *err = NULL; | ||
139 | int ret; | ||
140 | |||
141 | if (!dev->conf.blk) { | ||
142 | @@ -XXX,XX +XXX,XX @@ static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) | ||
143 | |||
144 | blkconf_serial(&dev->conf, &dev->serial); | ||
145 | if (kind != IDE_CD) { | ||
146 | - blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, &err); | ||
147 | - if (err) { | ||
148 | - error_propagate(errp, err); | ||
149 | + if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, | ||
150 | + errp)) { | ||
151 | return; | ||
152 | } | ||
153 | } | ||
154 | - blkconf_apply_backend_options(&dev->conf, kind == IDE_CD, kind != IDE_CD, | ||
155 | - &err); | ||
156 | - if (err) { | ||
157 | - error_propagate(errp, err); | ||
158 | + if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD, | ||
159 | + kind != IDE_CD, errp)) { | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c | ||
164 | index XXXXXXX..XXXXXXX 100644 | ||
165 | --- a/hw/scsi/scsi-disk.c | ||
166 | +++ b/hw/scsi/scsi-disk.c | ||
167 | @@ -XXX,XX +XXX,XX @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) | ||
168 | static void scsi_realize(SCSIDevice *dev, Error **errp) | ||
169 | { | ||
170 | SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); | ||
171 | - Error *err = NULL; | ||
172 | |||
173 | if (!s->qdev.conf.blk) { | ||
174 | error_setg(errp, "drive property not set"); | ||
175 | @@ -XXX,XX +XXX,XX @@ static void scsi_realize(SCSIDevice *dev, Error **errp) | ||
176 | } | ||
177 | |||
178 | if (dev->type == TYPE_DISK) { | ||
179 | - blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, &err); | ||
180 | - if (err) { | ||
181 | - error_propagate(errp, err); | ||
182 | + if (!blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, errp)) { | ||
183 | return; | ||
184 | } | ||
185 | } | ||
186 | - blkconf_apply_backend_options(&dev->conf, | ||
187 | - blk_is_read_only(s->qdev.conf.blk), | ||
188 | - dev->type == TYPE_DISK, &err); | ||
189 | - if (err) { | ||
190 | - error_propagate(errp, err); | ||
191 | + if (!blkconf_apply_backend_options(&dev->conf, | ||
192 | + blk_is_read_only(s->qdev.conf.blk), | ||
193 | + dev->type == TYPE_DISK, errp)) { | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/hw/usb/dev-storage.c | ||
200 | +++ b/hw/usb/dev-storage.c | ||
201 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) | ||
202 | MSDState *s = USB_STORAGE_DEV(dev); | ||
203 | BlockBackend *blk = s->conf.blk; | ||
204 | SCSIDevice *scsi_dev; | ||
205 | - Error *err = NULL; | ||
206 | |||
207 | if (!blk) { | ||
208 | error_setg(errp, "drive property not set"); | ||
209 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) | ||
210 | |||
211 | blkconf_serial(&s->conf, &dev->serial); | ||
212 | blkconf_blocksizes(&s->conf); | ||
213 | - blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), true, &err); | ||
214 | - if (err) { | ||
215 | - error_propagate(errp, err); | ||
216 | + if (!blkconf_apply_backend_options(&s->conf, blk_is_read_only(blk), true, | ||
217 | + errp)) { | ||
218 | return; | ||
219 | } | ||
220 | |||
221 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) | ||
222 | &usb_msd_scsi_info_storage, NULL); | ||
223 | scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable, | ||
224 | s->conf.bootindex, dev->serial, | ||
225 | - &err); | ||
226 | + errp); | ||
227 | blk_unref(blk); | ||
228 | if (!scsi_dev) { | ||
229 | - error_propagate(errp, err); | ||
230 | return; | ||
231 | } | ||
232 | usb_msd_handle_reset(dev); | ||
233 | -- | ||
234 | 2.14.3 | ||
235 | |||
236 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
1 | 2 | ||
3 | The function name of usb_msd_{realize,unrealize}_*, | ||
4 | usb_msd_class_initfn_* are unusual. Rename it to | ||
5 | usb_msd_*_{realize,unrealize}, usb_msd_class_*_initfn. | ||
6 | |||
7 | Cc: Gerd Hoffmann <kraxel@redhat.com> | ||
8 | |||
9 | Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 11e6003433abce35f3f4970e1acc71ee92dbcf51.1511317952.git.maozy.fnst@cn.fujitsu.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
13 | --- | ||
14 | hw/usb/dev-storage.c | 20 ++++++++++---------- | ||
15 | 1 file changed, 10 insertions(+), 10 deletions(-) | ||
16 | |||
17 | diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/usb/dev-storage.c | ||
20 | +++ b/hw/usb/dev-storage.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_unrealize_storage(USBDevice *dev, Error **errp) | ||
22 | object_unref(OBJECT(&s->bus)); | ||
23 | } | ||
24 | |||
25 | -static void usb_msd_realize_storage(USBDevice *dev, Error **errp) | ||
26 | +static void usb_msd_storage_realize(USBDevice *dev, Error **errp) | ||
27 | { | ||
28 | MSDState *s = USB_STORAGE_DEV(dev); | ||
29 | BlockBackend *blk = s->conf.blk; | ||
30 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) | ||
31 | s->scsi_dev = scsi_dev; | ||
32 | } | ||
33 | |||
34 | -static void usb_msd_unrealize_bot(USBDevice *dev, Error **errp) | ||
35 | +static void usb_msd_bot_unrealize(USBDevice *dev, Error **errp) | ||
36 | { | ||
37 | MSDState *s = USB_STORAGE_DEV(dev); | ||
38 | |||
39 | object_unref(OBJECT(&s->bus)); | ||
40 | } | ||
41 | |||
42 | -static void usb_msd_realize_bot(USBDevice *dev, Error **errp) | ||
43 | +static void usb_msd_bot_realize(USBDevice *dev, Error **errp) | ||
44 | { | ||
45 | MSDState *s = USB_STORAGE_DEV(dev); | ||
46 | DeviceState *d = DEVICE(dev); | ||
47 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_class_initfn_common(ObjectClass *klass, void *data) | ||
48 | dc->vmsd = &vmstate_usb_msd; | ||
49 | } | ||
50 | |||
51 | -static void usb_msd_class_initfn_storage(ObjectClass *klass, void *data) | ||
52 | +static void usb_msd_class_storage_initfn(ObjectClass *klass, void *data) | ||
53 | { | ||
54 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
55 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); | ||
56 | |||
57 | - uc->realize = usb_msd_realize_storage; | ||
58 | + uc->realize = usb_msd_storage_realize; | ||
59 | uc->unrealize = usb_msd_unrealize_storage; | ||
60 | dc->props = msd_properties; | ||
61 | } | ||
62 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_instance_init(Object *obj) | ||
63 | object_property_set_int(obj, -1, "bootindex", NULL); | ||
64 | } | ||
65 | |||
66 | -static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data) | ||
67 | +static void usb_msd_class_bot_initfn(ObjectClass *klass, void *data) | ||
68 | { | ||
69 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); | ||
70 | |||
71 | - uc->realize = usb_msd_realize_bot; | ||
72 | - uc->unrealize = usb_msd_unrealize_bot; | ||
73 | + uc->realize = usb_msd_bot_realize; | ||
74 | + uc->unrealize = usb_msd_bot_unrealize; | ||
75 | uc->attached_settable = true; | ||
76 | } | ||
77 | |||
78 | static const TypeInfo msd_info = { | ||
79 | .name = "usb-storage", | ||
80 | .parent = TYPE_USB_STORAGE, | ||
81 | - .class_init = usb_msd_class_initfn_storage, | ||
82 | + .class_init = usb_msd_class_storage_initfn, | ||
83 | .instance_init = usb_msd_instance_init, | ||
84 | }; | ||
85 | |||
86 | static const TypeInfo bot_info = { | ||
87 | .name = "usb-bot", | ||
88 | .parent = TYPE_USB_STORAGE, | ||
89 | - .class_init = usb_msd_class_initfn_bot, | ||
90 | + .class_init = usb_msd_class_bot_initfn, | ||
91 | }; | ||
92 | |||
93 | static void usb_msd_register_types(void) | ||
94 | -- | ||
95 | 2.14.3 | ||
96 | |||
97 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Commit 1351d1ec89eabebc9fdff20451a62c413d7accc1 ("qdev: drop iothread | ||
2 | property type") forgot to remove this include. | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Message-id: 20171205133954.31006-1-stefanha@redhat.com | ||
6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
7 | --- | ||
8 | hw/core/qdev-properties-system.c | 1 - | ||
9 | 1 file changed, 1 deletion(-) | ||
10 | |||
11 | diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/core/qdev-properties-system.c | ||
14 | +++ b/hw/core/qdev-properties-system.c | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | #include "qapi/visitor.h" | ||
17 | #include "chardev/char-fe.h" | ||
18 | #include "sysemu/tpm_backend.h" | ||
19 | -#include "sysemu/iothread.h" | ||
20 | |||
21 | static void get_pointer(Object *obj, Visitor *v, Property *prop, | ||
22 | char *(*print)(void *ptr), | ||
23 | -- | ||
24 | 2.14.3 | ||
25 | |||
26 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | bdrv_unref() requires the AioContext lock because bdrv_flush() uses |
---|---|---|---|
2 | BDRV_POLL_WHILE(), which assumes the AioContext is currently held. If | ||
3 | BDRV_POLL_WHILE() runs without AioContext held the | ||
4 | pthread_mutex_unlock() call in aio_context_release() fails. | ||
2 | 5 | ||
3 | OSError can't be used like a tuple on Python 3, so change the | 6 | This patch moves bdrv_unref() into the AioContext locked region to solve |
4 | code to use `e.sterror` instead of `e[1]`. | 7 | the following pthread_mutex_unlock() failure: |
5 | 8 | ||
6 | Reported-by: John Snow <jsnow@redhat.com> | 9 | #0 0x00007f566181969b in raise () at /lib64/libc.so.6 |
7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 10 | #1 0x00007f566181b3b1 in abort () at /lib64/libc.so.6 |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 11 | #2 0x00005592cd590458 in error_exit (err=<optimized out>, msg=msg@entry=0x5592cdaf6d60 <__func__.23977> "qemu_mutex_unlock") at util/qemu-thread-posix.c:36 |
9 | Message-id: 20191021214117.18091-1-ehabkost@redhat.com | 12 | #3 0x00005592cd96e738 in qemu_mutex_unlock (mutex=mutex@entry=0x5592ce9505e0) at util/qemu-thread-posix.c:96 |
10 | Message-Id: <20191021214117.18091-1-ehabkost@redhat.com> | 13 | #4 0x00005592cd969b69 in aio_context_release (ctx=ctx@entry=0x5592ce950580) at util/async.c:507 |
14 | #5 0x00005592cd8ead78 in bdrv_flush (bs=bs@entry=0x5592cfa87210) at block/io.c:2478 | ||
15 | #6 0x00005592cd89df30 in bdrv_close (bs=0x5592cfa87210) at block.c:3207 | ||
16 | #7 0x00005592cd89df30 in bdrv_delete (bs=0x5592cfa87210) at block.c:3395 | ||
17 | #8 0x00005592cd89df30 in bdrv_unref (bs=0x5592cfa87210) at block.c:4418 | ||
18 | #9 0x00005592cd6b7f86 in qmp_transaction (dev_list=<optimized out>, has_props=<optimized out>, props=<optimized out>, errp=errp@entry=0x7ffe4a1fc9d8) at blockdev.c:2308 | ||
19 | |||
20 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
21 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
22 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
23 | Message-id: 20171206144550.22295-2-stefanha@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 24 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 25 | --- |
13 | tests/image-fuzzer/runner.py | 4 ++-- | 26 | blockdev.c | 2 +- |
14 | 1 file changed, 2 insertions(+), 2 deletions(-) | 27 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | 28 | ||
16 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py | 29 | diff --git a/blockdev.c b/blockdev.c |
17 | index XXXXXXX..XXXXXXX 100755 | 30 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/image-fuzzer/runner.py | 31 | --- a/blockdev.c |
19 | +++ b/tests/image-fuzzer/runner.py | 32 | +++ b/blockdev.c |
20 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): | 33 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_clean(BlkActionState *common) |
21 | os.makedirs(self.current_dir) | 34 | DO_UPCAST(ExternalSnapshotState, common, common); |
22 | except OSError as e: | 35 | if (state->aio_context) { |
23 | print("Error: The working directory '%s' cannot be used. Reason: %s"\ | 36 | bdrv_drained_end(state->old_bs); |
24 | - % (self.work_dir, e[1]), file=sys.stderr) | 37 | - aio_context_release(state->aio_context); |
25 | + % (self.work_dir, e.strerror), file=sys.stderr) | 38 | bdrv_unref(state->new_bs); |
26 | raise TestException | 39 | + aio_context_release(state->aio_context); |
27 | self.log = open(os.path.join(self.current_dir, "test.log"), "w") | 40 | } |
28 | self.parent_log = open(run_log, "a") | 41 | } |
29 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): | ||
30 | except OSError as e: | ||
31 | multilog("%sError: Start of '%s' failed. Reason: %s\n\n" | ||
32 | % (test_summary, os.path.basename(current_cmd[0]), | ||
33 | - e[1]), | ||
34 | + e.strerror), | ||
35 | sys.stderr, self.log, self.parent_log) | ||
36 | raise TestException | ||
37 | 42 | ||
38 | -- | 43 | -- |
39 | 2.23.0 | 44 | 2.14.3 |
40 | 45 | ||
41 | 46 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | It is not necessary to hold AioContext across transactions anymore since | |
2 | bdrv_drained_begin/end() is used to keep the nodes quiesced. In fact, | ||
3 | using the AioContext lock for this purpose was always buggy. | ||
4 | |||
5 | This patch reduces the scope of AioContext locked regions. This is not | ||
6 | just a cleanup but also fixes hangs that occur in BDRV_POLL_WHILE() | ||
7 | because it is unware of recursive locking and does not release the | ||
8 | AioContext the necessary number of times to allow progress to be made. | ||
9 | |||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
11 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
12 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
13 | Message-id: 20171206144550.22295-3-stefanha@redhat.com | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | --- | ||
16 | blockdev.c | 71 ++++++++++++++++++++++++++++++++++++++++++-------------------- | ||
17 | 1 file changed, 48 insertions(+), 23 deletions(-) | ||
18 | |||
19 | diff --git a/blockdev.c b/blockdev.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/blockdev.c | ||
22 | +++ b/blockdev.c | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef struct ExternalSnapshotState { | ||
24 | BlkActionState common; | ||
25 | BlockDriverState *old_bs; | ||
26 | BlockDriverState *new_bs; | ||
27 | - AioContext *aio_context; | ||
28 | bool overlay_appended; | ||
29 | } ExternalSnapshotState; | ||
30 | |||
31 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
32 | ExternalSnapshotState *state = | ||
33 | DO_UPCAST(ExternalSnapshotState, common, common); | ||
34 | TransactionAction *action = common->action; | ||
35 | + AioContext *aio_context; | ||
36 | |||
37 | /* 'blockdev-snapshot' and 'blockdev-snapshot-sync' have similar | ||
38 | * purpose but a different set of parameters */ | ||
39 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
40 | return; | ||
41 | } | ||
42 | |||
43 | - /* Acquire AioContext now so any threads operating on old_bs stop */ | ||
44 | - state->aio_context = bdrv_get_aio_context(state->old_bs); | ||
45 | - aio_context_acquire(state->aio_context); | ||
46 | + aio_context = bdrv_get_aio_context(state->old_bs); | ||
47 | + aio_context_acquire(aio_context); | ||
48 | + | ||
49 | + /* Paired with .clean() */ | ||
50 | bdrv_drained_begin(state->old_bs); | ||
51 | |||
52 | if (!bdrv_is_inserted(state->old_bs)) { | ||
53 | error_setg(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); | ||
54 | - return; | ||
55 | + goto out; | ||
56 | } | ||
57 | |||
58 | if (bdrv_op_is_blocked(state->old_bs, | ||
59 | BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { | ||
60 | - return; | ||
61 | + goto out; | ||
62 | } | ||
63 | |||
64 | if (!bdrv_is_read_only(state->old_bs)) { | ||
65 | if (bdrv_flush(state->old_bs)) { | ||
66 | error_setg(errp, QERR_IO_ERROR); | ||
67 | - return; | ||
68 | + goto out; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | if (!bdrv_is_first_non_filter(state->old_bs)) { | ||
73 | error_setg(errp, QERR_FEATURE_DISABLED, "snapshot"); | ||
74 | - return; | ||
75 | + goto out; | ||
76 | } | ||
77 | |||
78 | if (action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC) { | ||
79 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
80 | |||
81 | if (node_name && !snapshot_node_name) { | ||
82 | error_setg(errp, "New snapshot node name missing"); | ||
83 | - return; | ||
84 | + goto out; | ||
85 | } | ||
86 | |||
87 | if (snapshot_node_name && | ||
88 | bdrv_lookup_bs(snapshot_node_name, snapshot_node_name, NULL)) { | ||
89 | error_setg(errp, "New snapshot node name already in use"); | ||
90 | - return; | ||
91 | + goto out; | ||
92 | } | ||
93 | |||
94 | flags = state->old_bs->open_flags; | ||
95 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
96 | int64_t size = bdrv_getlength(state->old_bs); | ||
97 | if (size < 0) { | ||
98 | error_setg_errno(errp, -size, "bdrv_getlength failed"); | ||
99 | - return; | ||
100 | + goto out; | ||
101 | } | ||
102 | bdrv_img_create(new_image_file, format, | ||
103 | state->old_bs->filename, | ||
104 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
105 | NULL, size, flags, false, &local_err); | ||
106 | if (local_err) { | ||
107 | error_propagate(errp, local_err); | ||
108 | - return; | ||
109 | + goto out; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
114 | errp); | ||
115 | /* We will manually add the backing_hd field to the bs later */ | ||
116 | if (!state->new_bs) { | ||
117 | - return; | ||
118 | + goto out; | ||
119 | } | ||
120 | |||
121 | if (bdrv_has_blk(state->new_bs)) { | ||
122 | error_setg(errp, "The snapshot is already in use"); | ||
123 | - return; | ||
124 | + goto out; | ||
125 | } | ||
126 | |||
127 | if (bdrv_op_is_blocked(state->new_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, | ||
128 | errp)) { | ||
129 | - return; | ||
130 | + goto out; | ||
131 | } | ||
132 | |||
133 | if (state->new_bs->backing != NULL) { | ||
134 | error_setg(errp, "The snapshot already has a backing image"); | ||
135 | - return; | ||
136 | + goto out; | ||
137 | } | ||
138 | |||
139 | if (!state->new_bs->drv->supports_backing) { | ||
140 | error_setg(errp, "The snapshot does not support backing images"); | ||
141 | - return; | ||
142 | + goto out; | ||
143 | } | ||
144 | |||
145 | - bdrv_set_aio_context(state->new_bs, state->aio_context); | ||
146 | + bdrv_set_aio_context(state->new_bs, aio_context); | ||
147 | |||
148 | /* This removes our old bs and adds the new bs. This is an operation that | ||
149 | * can fail, so we need to do it in .prepare; undoing it for abort is | ||
150 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_prepare(BlkActionState *common, | ||
151 | bdrv_append(state->new_bs, state->old_bs, &local_err); | ||
152 | if (local_err) { | ||
153 | error_propagate(errp, local_err); | ||
154 | - return; | ||
155 | + goto out; | ||
156 | } | ||
157 | state->overlay_appended = true; | ||
158 | + | ||
159 | +out: | ||
160 | + aio_context_release(aio_context); | ||
161 | } | ||
162 | |||
163 | static void external_snapshot_commit(BlkActionState *common) | ||
164 | { | ||
165 | ExternalSnapshotState *state = | ||
166 | DO_UPCAST(ExternalSnapshotState, common, common); | ||
167 | + AioContext *aio_context; | ||
168 | + | ||
169 | + aio_context = bdrv_get_aio_context(state->old_bs); | ||
170 | + aio_context_acquire(aio_context); | ||
171 | |||
172 | /* We don't need (or want) to use the transactional | ||
173 | * bdrv_reopen_multiple() across all the entries at once, because we | ||
174 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_commit(BlkActionState *common) | ||
175 | bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR, | ||
176 | NULL); | ||
177 | } | ||
178 | + | ||
179 | + aio_context_release(aio_context); | ||
180 | } | ||
181 | |||
182 | static void external_snapshot_abort(BlkActionState *common) | ||
183 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_abort(BlkActionState *common) | ||
184 | DO_UPCAST(ExternalSnapshotState, common, common); | ||
185 | if (state->new_bs) { | ||
186 | if (state->overlay_appended) { | ||
187 | + AioContext *aio_context; | ||
188 | + | ||
189 | + aio_context = bdrv_get_aio_context(state->old_bs); | ||
190 | + aio_context_acquire(aio_context); | ||
191 | + | ||
192 | bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd() | ||
193 | close state->old_bs; we need it */ | ||
194 | bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); | ||
195 | bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); | ||
196 | bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_bs */ | ||
197 | + | ||
198 | + aio_context_release(aio_context); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_clean(BlkActionState *common) | ||
203 | { | ||
204 | ExternalSnapshotState *state = | ||
205 | DO_UPCAST(ExternalSnapshotState, common, common); | ||
206 | - if (state->aio_context) { | ||
207 | - bdrv_drained_end(state->old_bs); | ||
208 | - bdrv_unref(state->new_bs); | ||
209 | - aio_context_release(state->aio_context); | ||
210 | + AioContext *aio_context; | ||
211 | + | ||
212 | + if (!state->old_bs) { | ||
213 | + return; | ||
214 | } | ||
215 | + | ||
216 | + aio_context = bdrv_get_aio_context(state->old_bs); | ||
217 | + aio_context_acquire(aio_context); | ||
218 | + | ||
219 | + bdrv_drained_end(state->old_bs); | ||
220 | + bdrv_unref(state->new_bs); | ||
221 | + | ||
222 | + aio_context_release(aio_context); | ||
223 | } | ||
224 | |||
225 | typedef struct DriveBackupState { | ||
226 | -- | ||
227 | 2.14.3 | ||
228 | |||
229 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
2 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
3 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
4 | Message-id: 20171206144550.22295-4-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | blockdev.c | 42 ++++++++++++++++++++++++++++++++++-------- | ||
8 | 1 file changed, 34 insertions(+), 8 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/blockdev.c b/blockdev.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/blockdev.c | ||
13 | +++ b/blockdev.c | ||
14 | @@ -XXX,XX +XXX,XX @@ static void external_snapshot_clean(BlkActionState *common) | ||
15 | typedef struct DriveBackupState { | ||
16 | BlkActionState common; | ||
17 | BlockDriverState *bs; | ||
18 | - AioContext *aio_context; | ||
19 | BlockJob *job; | ||
20 | } DriveBackupState; | ||
21 | |||
22 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) | ||
23 | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); | ||
24 | BlockDriverState *bs; | ||
25 | DriveBackup *backup; | ||
26 | + AioContext *aio_context; | ||
27 | Error *local_err = NULL; | ||
28 | |||
29 | assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); | ||
30 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_prepare(BlkActionState *common, Error **errp) | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | - /* AioContext is released in .clean() */ | ||
35 | - state->aio_context = bdrv_get_aio_context(bs); | ||
36 | - aio_context_acquire(state->aio_context); | ||
37 | + aio_context = bdrv_get_aio_context(bs); | ||
38 | + aio_context_acquire(aio_context); | ||
39 | + | ||
40 | + /* Paired with .clean() */ | ||
41 | bdrv_drained_begin(bs); | ||
42 | + | ||
43 | state->bs = bs; | ||
44 | |||
45 | state->job = do_drive_backup(backup, common->block_job_txn, &local_err); | ||
46 | if (local_err) { | ||
47 | error_propagate(errp, local_err); | ||
48 | - return; | ||
49 | + goto out; | ||
50 | } | ||
51 | + | ||
52 | +out: | ||
53 | + aio_context_release(aio_context); | ||
54 | } | ||
55 | |||
56 | static void drive_backup_commit(BlkActionState *common) | ||
57 | { | ||
58 | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); | ||
59 | + AioContext *aio_context; | ||
60 | + | ||
61 | + aio_context = bdrv_get_aio_context(state->bs); | ||
62 | + aio_context_acquire(aio_context); | ||
63 | + | ||
64 | assert(state->job); | ||
65 | block_job_start(state->job); | ||
66 | + | ||
67 | + aio_context_release(aio_context); | ||
68 | } | ||
69 | |||
70 | static void drive_backup_abort(BlkActionState *common) | ||
71 | @@ -XXX,XX +XXX,XX @@ static void drive_backup_abort(BlkActionState *common) | ||
72 | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); | ||
73 | |||
74 | if (state->job) { | ||
75 | + AioContext *aio_context; | ||
76 | + | ||
77 | + aio_context = bdrv_get_aio_context(state->bs); | ||
78 | + aio_context_acquire(aio_context); | ||
79 | + | ||
80 | block_job_cancel_sync(state->job); | ||
81 | + | ||
82 | + aio_context_release(aio_context); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | static void drive_backup_clean(BlkActionState *common) | ||
87 | { | ||
88 | DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common); | ||
89 | + AioContext *aio_context; | ||
90 | |||
91 | - if (state->aio_context) { | ||
92 | - bdrv_drained_end(state->bs); | ||
93 | - aio_context_release(state->aio_context); | ||
94 | + if (!state->bs) { | ||
95 | + return; | ||
96 | } | ||
97 | + | ||
98 | + aio_context = bdrv_get_aio_context(state->bs); | ||
99 | + aio_context_acquire(aio_context); | ||
100 | + | ||
101 | + bdrv_drained_end(state->bs); | ||
102 | + | ||
103 | + aio_context_release(aio_context); | ||
104 | } | ||
105 | |||
106 | typedef struct BlockdevBackupState { | ||
107 | -- | ||
108 | 2.14.3 | ||
109 | |||
110 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
2 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
3 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
4 | Message-id: 20171206144550.22295-5-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | blockdev.c | 44 ++++++++++++++++++++++++++++++++++---------- | ||
8 | 1 file changed, 34 insertions(+), 10 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/blockdev.c b/blockdev.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/blockdev.c | ||
13 | +++ b/blockdev.c | ||
14 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockdevBackupState { | ||
15 | BlkActionState common; | ||
16 | BlockDriverState *bs; | ||
17 | BlockJob *job; | ||
18 | - AioContext *aio_context; | ||
19 | } BlockdevBackupState; | ||
20 | |||
21 | static BlockJob *do_blockdev_backup(BlockdevBackup *backup, BlockJobTxn *txn, | ||
22 | @@ -XXX,XX +XXX,XX @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp) | ||
23 | BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); | ||
24 | BlockdevBackup *backup; | ||
25 | BlockDriverState *bs, *target; | ||
26 | + AioContext *aio_context; | ||
27 | Error *local_err = NULL; | ||
28 | |||
29 | assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); | ||
30 | @@ -XXX,XX +XXX,XX @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp) | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | - /* AioContext is released in .clean() */ | ||
35 | - state->aio_context = bdrv_get_aio_context(bs); | ||
36 | - if (state->aio_context != bdrv_get_aio_context(target)) { | ||
37 | - state->aio_context = NULL; | ||
38 | + aio_context = bdrv_get_aio_context(bs); | ||
39 | + if (aio_context != bdrv_get_aio_context(target)) { | ||
40 | error_setg(errp, "Backup between two IO threads is not implemented"); | ||
41 | return; | ||
42 | } | ||
43 | - aio_context_acquire(state->aio_context); | ||
44 | + aio_context_acquire(aio_context); | ||
45 | state->bs = bs; | ||
46 | + | ||
47 | + /* Paired with .clean() */ | ||
48 | bdrv_drained_begin(state->bs); | ||
49 | |||
50 | state->job = do_blockdev_backup(backup, common->block_job_txn, &local_err); | ||
51 | if (local_err) { | ||
52 | error_propagate(errp, local_err); | ||
53 | - return; | ||
54 | + goto out; | ||
55 | } | ||
56 | + | ||
57 | +out: | ||
58 | + aio_context_release(aio_context); | ||
59 | } | ||
60 | |||
61 | static void blockdev_backup_commit(BlkActionState *common) | ||
62 | { | ||
63 | BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); | ||
64 | + AioContext *aio_context; | ||
65 | + | ||
66 | + aio_context = bdrv_get_aio_context(state->bs); | ||
67 | + aio_context_acquire(aio_context); | ||
68 | + | ||
69 | assert(state->job); | ||
70 | block_job_start(state->job); | ||
71 | + | ||
72 | + aio_context_release(aio_context); | ||
73 | } | ||
74 | |||
75 | static void blockdev_backup_abort(BlkActionState *common) | ||
76 | @@ -XXX,XX +XXX,XX @@ static void blockdev_backup_abort(BlkActionState *common) | ||
77 | BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); | ||
78 | |||
79 | if (state->job) { | ||
80 | + AioContext *aio_context; | ||
81 | + | ||
82 | + aio_context = bdrv_get_aio_context(state->bs); | ||
83 | + aio_context_acquire(aio_context); | ||
84 | + | ||
85 | block_job_cancel_sync(state->job); | ||
86 | + | ||
87 | + aio_context_release(aio_context); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | static void blockdev_backup_clean(BlkActionState *common) | ||
92 | { | ||
93 | BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common); | ||
94 | + AioContext *aio_context; | ||
95 | |||
96 | - if (state->aio_context) { | ||
97 | - bdrv_drained_end(state->bs); | ||
98 | - aio_context_release(state->aio_context); | ||
99 | + if (!state->bs) { | ||
100 | + return; | ||
101 | } | ||
102 | + | ||
103 | + aio_context = bdrv_get_aio_context(state->bs); | ||
104 | + aio_context_acquire(aio_context); | ||
105 | + | ||
106 | + bdrv_drained_end(state->bs); | ||
107 | + | ||
108 | + aio_context_release(aio_context); | ||
109 | } | ||
110 | |||
111 | typedef struct BlockDirtyBitmapState { | ||
112 | -- | ||
113 | 2.14.3 | ||
114 | |||
115 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
2 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
3 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
4 | Message-id: 20171206144550.22295-6-stefanha@redhat.com | ||
5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
6 | --- | ||
7 | blockdev.c | 47 +++++++++++++++++++++++++++++++---------------- | ||
8 | 1 file changed, 31 insertions(+), 16 deletions(-) | ||
1 | 9 | ||
10 | diff --git a/blockdev.c b/blockdev.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/blockdev.c | ||
13 | +++ b/blockdev.c | ||
14 | @@ -XXX,XX +XXX,XX @@ struct BlkActionState { | ||
15 | typedef struct InternalSnapshotState { | ||
16 | BlkActionState common; | ||
17 | BlockDriverState *bs; | ||
18 | - AioContext *aio_context; | ||
19 | QEMUSnapshotInfo sn; | ||
20 | bool created; | ||
21 | } InternalSnapshotState; | ||
22 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_prepare(BlkActionState *common, | ||
23 | qemu_timeval tv; | ||
24 | BlockdevSnapshotInternal *internal; | ||
25 | InternalSnapshotState *state; | ||
26 | + AioContext *aio_context; | ||
27 | int ret1; | ||
28 | |||
29 | g_assert(common->action->type == | ||
30 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_prepare(BlkActionState *common, | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | - /* AioContext is released in .clean() */ | ||
35 | - state->aio_context = bdrv_get_aio_context(bs); | ||
36 | - aio_context_acquire(state->aio_context); | ||
37 | + aio_context = bdrv_get_aio_context(bs); | ||
38 | + aio_context_acquire(aio_context); | ||
39 | |||
40 | state->bs = bs; | ||
41 | + | ||
42 | + /* Paired with .clean() */ | ||
43 | bdrv_drained_begin(bs); | ||
44 | |||
45 | if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT, errp)) { | ||
46 | - return; | ||
47 | + goto out; | ||
48 | } | ||
49 | |||
50 | if (bdrv_is_read_only(bs)) { | ||
51 | error_setg(errp, "Device '%s' is read only", device); | ||
52 | - return; | ||
53 | + goto out; | ||
54 | } | ||
55 | |||
56 | if (!bdrv_can_snapshot(bs)) { | ||
57 | error_setg(errp, "Block format '%s' used by device '%s' " | ||
58 | "does not support internal snapshots", | ||
59 | bs->drv->format_name, device); | ||
60 | - return; | ||
61 | + goto out; | ||
62 | } | ||
63 | |||
64 | if (!strlen(name)) { | ||
65 | error_setg(errp, "Name is empty"); | ||
66 | - return; | ||
67 | + goto out; | ||
68 | } | ||
69 | |||
70 | /* check whether a snapshot with name exist */ | ||
71 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_prepare(BlkActionState *common, | ||
72 | &local_err); | ||
73 | if (local_err) { | ||
74 | error_propagate(errp, local_err); | ||
75 | - return; | ||
76 | + goto out; | ||
77 | } else if (ret) { | ||
78 | error_setg(errp, | ||
79 | "Snapshot with name '%s' already exists on device '%s'", | ||
80 | name, device); | ||
81 | - return; | ||
82 | + goto out; | ||
83 | } | ||
84 | |||
85 | /* 3. take the snapshot */ | ||
86 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_prepare(BlkActionState *common, | ||
87 | error_setg_errno(errp, -ret1, | ||
88 | "Failed to create snapshot '%s' on device '%s'", | ||
89 | name, device); | ||
90 | - return; | ||
91 | + goto out; | ||
92 | } | ||
93 | |||
94 | /* 4. succeed, mark a snapshot is created */ | ||
95 | state->created = true; | ||
96 | + | ||
97 | +out: | ||
98 | + aio_context_release(aio_context); | ||
99 | } | ||
100 | |||
101 | static void internal_snapshot_abort(BlkActionState *common) | ||
102 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_abort(BlkActionState *common) | ||
103 | DO_UPCAST(InternalSnapshotState, common, common); | ||
104 | BlockDriverState *bs = state->bs; | ||
105 | QEMUSnapshotInfo *sn = &state->sn; | ||
106 | + AioContext *aio_context; | ||
107 | Error *local_error = NULL; | ||
108 | |||
109 | if (!state->created) { | ||
110 | return; | ||
111 | } | ||
112 | |||
113 | + aio_context = bdrv_get_aio_context(state->bs); | ||
114 | + aio_context_acquire(aio_context); | ||
115 | + | ||
116 | if (bdrv_snapshot_delete(bs, sn->id_str, sn->name, &local_error) < 0) { | ||
117 | error_reportf_err(local_error, | ||
118 | "Failed to delete snapshot with id '%s' and " | ||
119 | @@ -XXX,XX +XXX,XX @@ static void internal_snapshot_abort(BlkActionState *common) | ||
120 | sn->id_str, sn->name, | ||
121 | bdrv_get_device_name(bs)); | ||
122 | } | ||
123 | + | ||
124 | + aio_context_release(aio_context); | ||
125 | } | ||
126 | |||
127 | static void internal_snapshot_clean(BlkActionState *common) | ||
128 | { | ||
129 | InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState, | ||
130 | common, common); | ||
131 | + AioContext *aio_context; | ||
132 | |||
133 | - if (state->aio_context) { | ||
134 | - if (state->bs) { | ||
135 | - bdrv_drained_end(state->bs); | ||
136 | - } | ||
137 | - aio_context_release(state->aio_context); | ||
138 | + if (!state->bs) { | ||
139 | + return; | ||
140 | } | ||
141 | + | ||
142 | + aio_context = bdrv_get_aio_context(state->bs); | ||
143 | + aio_context_acquire(aio_context); | ||
144 | + | ||
145 | + bdrv_drained_end(state->bs); | ||
146 | + | ||
147 | + aio_context_release(aio_context); | ||
148 | } | ||
149 | |||
150 | /* external snapshot private data */ | ||
151 | -- | ||
152 | 2.14.3 | ||
153 | |||
154 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | The dirty bitmap actions in qmp_transaction have not used AioContext |
---|---|---|---|
2 | since the dirty bitmap locking discipline was introduced in commit | ||
3 | 2119882c7eb7e2c612b24fc0c8d86f5887d6f1c3 ("block: introduce | ||
4 | dirty_bitmap_mutex"). Remove the unused field. | ||
2 | 5 | ||
3 | Instead of manually encoding stderr and stdout output, use | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | `errors` parameter of subprocess.Popen(). This will make | 7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
5 | process.communicate() return unicode strings instead of bytes | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> |
6 | objects. | 9 | Message-id: 20171206144550.22295-7-stefanha@redhat.com |
7 | |||
8 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20191016192430.25098-11-ehabkost@redhat.com | ||
12 | Message-Id: <20191016192430.25098-11-ehabkost@redhat.com> | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 11 | --- |
15 | tests/image-fuzzer/runner.py | 11 ++++------- | 12 | blockdev.c | 13 ------------- |
16 | 1 file changed, 4 insertions(+), 7 deletions(-) | 13 | 1 file changed, 13 deletions(-) |
17 | 14 | ||
18 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py | 15 | diff --git a/blockdev.c b/blockdev.c |
19 | index XXXXXXX..XXXXXXX 100755 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/image-fuzzer/runner.py | 17 | --- a/blockdev.c |
21 | +++ b/tests/image-fuzzer/runner.py | 18 | +++ b/blockdev.c |
22 | @@ -XXX,XX +XXX,XX @@ def run_app(fd, q_args): | 19 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockDirtyBitmapState { |
23 | devnull = open('/dev/null', 'r+') | 20 | BlkActionState common; |
24 | process = subprocess.Popen(q_args, stdin=devnull, | 21 | BdrvDirtyBitmap *bitmap; |
25 | stdout=subprocess.PIPE, | 22 | BlockDriverState *bs; |
26 | - stderr=subprocess.PIPE) | 23 | - AioContext *aio_context; |
27 | + stderr=subprocess.PIPE, | 24 | HBitmap *backup; |
28 | + errors='replace') | 25 | bool prepared; |
29 | try: | 26 | } BlockDirtyBitmapState; |
30 | out, err = process.communicate() | 27 | @@ -XXX,XX +XXX,XX @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common, |
31 | signal.alarm(0) | 28 | } |
32 | - # fd is a text file, so we need to decode the process output before | 29 | |
33 | - # writing to it. | 30 | bdrv_clear_dirty_bitmap(state->bitmap, &state->backup); |
34 | - # We could be simply using the `errors` parameter of subprocess.Popen(), | 31 | - /* AioContext is released in .clean() */ |
35 | - # but this will be possible only after migrating to Python 3 | 32 | } |
36 | - fd.write(out.decode(errors='replace')) | 33 | |
37 | - fd.write(err.decode(errors='replace')) | 34 | static void block_dirty_bitmap_clear_abort(BlkActionState *common) |
38 | + fd.write(out) | 35 | @@ -XXX,XX +XXX,XX @@ static void block_dirty_bitmap_clear_commit(BlkActionState *common) |
39 | + fd.write(err) | 36 | hbitmap_free(state->backup); |
40 | fd.flush() | 37 | } |
41 | return process.returncode | 38 | |
39 | -static void block_dirty_bitmap_clear_clean(BlkActionState *common) | ||
40 | -{ | ||
41 | - BlockDirtyBitmapState *state = DO_UPCAST(BlockDirtyBitmapState, | ||
42 | - common, common); | ||
43 | - | ||
44 | - if (state->aio_context) { | ||
45 | - aio_context_release(state->aio_context); | ||
46 | - } | ||
47 | -} | ||
48 | - | ||
49 | static void abort_prepare(BlkActionState *common, Error **errp) | ||
50 | { | ||
51 | error_setg(errp, "Transaction aborted using Abort action"); | ||
52 | @@ -XXX,XX +XXX,XX @@ static const BlkActionOps actions[] = { | ||
53 | .prepare = block_dirty_bitmap_clear_prepare, | ||
54 | .commit = block_dirty_bitmap_clear_commit, | ||
55 | .abort = block_dirty_bitmap_clear_abort, | ||
56 | - .clean = block_dirty_bitmap_clear_clean, | ||
57 | } | ||
58 | }; | ||
42 | 59 | ||
43 | -- | 60 | -- |
44 | 2.23.0 | 61 | 2.14.3 |
45 | 62 | ||
46 | 63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Encapsulate IOThread QOM object lookup so that callers don't need to | ||
2 | know how and where IOThread objects live. | ||
1 | 3 | ||
4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
5 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
6 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
7 | Message-id: 20171206144550.22295-8-stefanha@redhat.com | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | --- | ||
10 | include/sysemu/iothread.h | 1 + | ||
11 | iothread.c | 7 +++++++ | ||
12 | 2 files changed, 8 insertions(+) | ||
13 | |||
14 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/sysemu/iothread.h | ||
17 | +++ b/include/sysemu/iothread.h | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
19 | OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) | ||
20 | |||
21 | char *iothread_get_id(IOThread *iothread); | ||
22 | +IOThread *iothread_by_id(const char *id); | ||
23 | AioContext *iothread_get_aio_context(IOThread *iothread); | ||
24 | void iothread_stop_all(void); | ||
25 | GMainContext *iothread_get_g_main_context(IOThread *iothread); | ||
26 | diff --git a/iothread.c b/iothread.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/iothread.c | ||
29 | +++ b/iothread.c | ||
30 | @@ -XXX,XX +XXX,XX @@ void iothread_destroy(IOThread *iothread) | ||
31 | { | ||
32 | object_unparent(OBJECT(iothread)); | ||
33 | } | ||
34 | + | ||
35 | +/* Lookup IOThread by its id. Only finds user-created objects, not internal | ||
36 | + * iothread_create() objects. */ | ||
37 | +IOThread *iothread_by_id(const char *id) | ||
38 | +{ | ||
39 | + return IOTHREAD(object_resolve_path_type(id, TYPE_IOTHREAD, NULL)); | ||
40 | +} | ||
41 | -- | ||
42 | 2.14.3 | ||
43 | |||
44 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently there is no easy way for iotests to ensure that a BDS is bound | ||
2 | to a particular IOThread. Normally the virtio-blk device calls | ||
3 | blk_set_aio_context() when dataplane is enabled during guest driver | ||
4 | initialization. This never happens in iotests since -machine | ||
5 | accel=qtest means there is no guest activity (including device driver | ||
6 | initialization). | ||
1 | 7 | ||
8 | This patch adds a QMP command to explicitly assign IOThreads in test | ||
9 | cases. See qapi/block-core.json for a description of the command. | ||
10 | |||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
12 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> | ||
13 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
14 | Message-id: 20171206144550.22295-9-stefanha@redhat.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | ||
17 | qapi/block-core.json | 36 ++++++++++++++++++++++++++++++++++++ | ||
18 | blockdev.c | 41 +++++++++++++++++++++++++++++++++++++++++ | ||
19 | 2 files changed, 77 insertions(+) | ||
20 | |||
21 | diff --git a/qapi/block-core.json b/qapi/block-core.json | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/qapi/block-core.json | ||
24 | +++ b/qapi/block-core.json | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | 'data' : { 'parent': 'str', | ||
27 | '*child': 'str', | ||
28 | '*node': 'str' } } | ||
29 | + | ||
30 | +## | ||
31 | +# @x-blockdev-set-iothread: | ||
32 | +# | ||
33 | +# Move @node and its children into the @iothread. If @iothread is null then | ||
34 | +# move @node and its children into the main loop. | ||
35 | +# | ||
36 | +# The node must not be attached to a BlockBackend. | ||
37 | +# | ||
38 | +# @node-name: the name of the block driver node | ||
39 | +# | ||
40 | +# @iothread: the name of the IOThread object or null for the main loop | ||
41 | +# | ||
42 | +# Note: this command is experimental and intended for test cases that need | ||
43 | +# control over IOThreads only. | ||
44 | +# | ||
45 | +# Since: 2.12 | ||
46 | +# | ||
47 | +# Example: | ||
48 | +# | ||
49 | +# 1. Move a node into an IOThread | ||
50 | +# -> { "execute": "x-blockdev-set-iothread", | ||
51 | +# "arguments": { "node-name": "disk1", | ||
52 | +# "iothread": "iothread0" } } | ||
53 | +# <- { "return": {} } | ||
54 | +# | ||
55 | +# 2. Move a node into the main loop | ||
56 | +# -> { "execute": "x-blockdev-set-iothread", | ||
57 | +# "arguments": { "node-name": "disk1", | ||
58 | +# "iothread": null } } | ||
59 | +# <- { "return": {} } | ||
60 | +# | ||
61 | +## | ||
62 | +{ 'command': 'x-blockdev-set-iothread', | ||
63 | + 'data' : { 'node-name': 'str', | ||
64 | + 'iothread': 'StrOrNull' } } | ||
65 | diff --git a/blockdev.c b/blockdev.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/blockdev.c | ||
68 | +++ b/blockdev.c | ||
69 | @@ -XXX,XX +XXX,XX @@ | ||
70 | #include "qapi/qmp/qerror.h" | ||
71 | #include "qapi/qobject-output-visitor.h" | ||
72 | #include "sysemu/sysemu.h" | ||
73 | +#include "sysemu/iothread.h" | ||
74 | #include "block/block_int.h" | ||
75 | #include "qmp-commands.h" | ||
76 | #include "block/trace.h" | ||
77 | @@ -XXX,XX +XXX,XX @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp) | ||
78 | return head; | ||
79 | } | ||
80 | |||
81 | +void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread, | ||
82 | + Error **errp) | ||
83 | +{ | ||
84 | + AioContext *old_context; | ||
85 | + AioContext *new_context; | ||
86 | + BlockDriverState *bs; | ||
87 | + | ||
88 | + bs = bdrv_find_node(node_name); | ||
89 | + if (!bs) { | ||
90 | + error_setg(errp, "Cannot find node %s", node_name); | ||
91 | + return; | ||
92 | + } | ||
93 | + | ||
94 | + /* If we want to allow more extreme test scenarios this guard could be | ||
95 | + * removed. For now it protects against accidents. */ | ||
96 | + if (bdrv_has_blk(bs)) { | ||
97 | + error_setg(errp, "Node %s is in use", node_name); | ||
98 | + return; | ||
99 | + } | ||
100 | + | ||
101 | + if (iothread->type == QTYPE_QSTRING) { | ||
102 | + IOThread *obj = iothread_by_id(iothread->u.s); | ||
103 | + if (!obj) { | ||
104 | + error_setg(errp, "Cannot find iothread %s", iothread->u.s); | ||
105 | + return; | ||
106 | + } | ||
107 | + | ||
108 | + new_context = iothread_get_aio_context(obj); | ||
109 | + } else { | ||
110 | + new_context = qemu_get_aio_context(); | ||
111 | + } | ||
112 | + | ||
113 | + old_context = bdrv_get_aio_context(bs); | ||
114 | + aio_context_acquire(old_context); | ||
115 | + | ||
116 | + bdrv_set_aio_context(bs, new_context); | ||
117 | + | ||
118 | + aio_context_release(old_context); | ||
119 | +} | ||
120 | + | ||
121 | QemuOptsList qemu_common_drive_opts = { | ||
122 | .name = "drive", | ||
123 | .head = QTAILQ_HEAD_INITIALIZER(qemu_common_drive_opts.head), | ||
124 | -- | ||
125 | 2.14.3 | ||
126 | |||
127 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | QMP 'transaction' blockdev-snapshot-sync with multiple disks in an |
---|---|---|---|
2 | IOThread is an untested code path. Several bugs have been found in | ||
3 | connection with this command. This patch adds a test case to prevent | ||
4 | future regressions. | ||
2 | 5 | ||
3 | Callers of create_image() will pass strings as arguments, but the | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | Image class will expect bytes objects to be provided. Encode | 7 | Reviewed-by: Kevin Wolf <kwolf@redhat.com> |
5 | them inside create_image(). | 8 | Reviewed-by: Eric Blake <eblake@redhat.com> |
6 | 9 | Message-id: 20171206144550.22295-10-stefanha@redhat.com | |
7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
8 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Message-id: 20191016192430.25098-9-ehabkost@redhat.com | ||
11 | Message-Id: <20191016192430.25098-9-ehabkost@redhat.com> | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 11 | --- |
14 | tests/image-fuzzer/qcow2/layout.py | 4 ++-- | 12 | tests/qemu-iotests/202 | 95 ++++++++++++++++++++++++++++++++++++++++++++++ |
15 | 1 file changed, 2 insertions(+), 2 deletions(-) | 13 | tests/qemu-iotests/202.out | 11 ++++++ |
14 | tests/qemu-iotests/group | 1 + | ||
15 | 3 files changed, 107 insertions(+) | ||
16 | create mode 100755 tests/qemu-iotests/202 | ||
17 | create mode 100644 tests/qemu-iotests/202.out | ||
16 | 18 | ||
17 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | 19 | diff --git a/tests/qemu-iotests/202 b/tests/qemu-iotests/202 |
20 | new file mode 100755 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/tests/qemu-iotests/202 | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +#!/usr/bin/env python | ||
26 | +# | ||
27 | +# Copyright (C) 2017 Red Hat, Inc. | ||
28 | +# | ||
29 | +# This program is free software; you can redistribute it and/or modify | ||
30 | +# it under the terms of the GNU General Public License as published by | ||
31 | +# the Free Software Foundation; either version 2 of the License, or | ||
32 | +# (at your option) any later version. | ||
33 | +# | ||
34 | +# This program is distributed in the hope that it will be useful, | ||
35 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
36 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
37 | +# GNU General Public License for more details. | ||
38 | +# | ||
39 | +# You should have received a copy of the GNU General Public License | ||
40 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
41 | +# | ||
42 | +# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> | ||
43 | +# | ||
44 | +# Check that QMP 'transaction' blockdev-snapshot-sync with multiple drives on a | ||
45 | +# single IOThread completes successfully. This particular command triggered a | ||
46 | +# hang due to recursive AioContext locking and BDRV_POLL_WHILE(). Protect | ||
47 | +# against regressions. | ||
48 | + | ||
49 | +import iotests | ||
50 | + | ||
51 | +iotests.verify_image_format(supported_fmts=['qcow2']) | ||
52 | +iotests.verify_platform(['linux']) | ||
53 | + | ||
54 | +with iotests.FilePath('disk0.img') as disk0_img_path, \ | ||
55 | + iotests.FilePath('disk1.img') as disk1_img_path, \ | ||
56 | + iotests.FilePath('disk0-snap.img') as disk0_snap_img_path, \ | ||
57 | + iotests.FilePath('disk1-snap.img') as disk1_snap_img_path, \ | ||
58 | + iotests.VM() as vm: | ||
59 | + | ||
60 | + img_size = '10M' | ||
61 | + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk0_img_path, img_size) | ||
62 | + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk1_img_path, img_size) | ||
63 | + | ||
64 | + iotests.log('Launching VM...') | ||
65 | + vm.launch() | ||
66 | + | ||
67 | + iotests.log('Adding IOThread...') | ||
68 | + iotests.log(vm.qmp('object-add', | ||
69 | + qom_type='iothread', | ||
70 | + id='iothread0')) | ||
71 | + | ||
72 | + iotests.log('Adding blockdevs...') | ||
73 | + iotests.log(vm.qmp('blockdev-add', | ||
74 | + driver=iotests.imgfmt, | ||
75 | + node_name='disk0', | ||
76 | + file={ | ||
77 | + 'driver': 'file', | ||
78 | + 'filename': disk0_img_path, | ||
79 | + })) | ||
80 | + iotests.log(vm.qmp('blockdev-add', | ||
81 | + driver=iotests.imgfmt, | ||
82 | + node_name='disk1', | ||
83 | + file={ | ||
84 | + 'driver': 'file', | ||
85 | + 'filename': disk1_img_path, | ||
86 | + })) | ||
87 | + | ||
88 | + iotests.log('Setting iothread...') | ||
89 | + iotests.log(vm.qmp('x-blockdev-set-iothread', | ||
90 | + node_name='disk0', | ||
91 | + iothread='iothread0')) | ||
92 | + iotests.log(vm.qmp('x-blockdev-set-iothread', | ||
93 | + node_name='disk1', | ||
94 | + iothread='iothread0')) | ||
95 | + | ||
96 | + iotests.log('Creating external snapshots...') | ||
97 | + iotests.log(vm.qmp( | ||
98 | + 'transaction', | ||
99 | + actions=[ | ||
100 | + { | ||
101 | + 'data': { | ||
102 | + 'node-name': 'disk0', | ||
103 | + 'snapshot-file': disk0_snap_img_path, | ||
104 | + 'snapshot-node-name': 'disk0-snap', | ||
105 | + 'mode': 'absolute-paths', | ||
106 | + 'format': iotests.imgfmt, | ||
107 | + }, | ||
108 | + 'type': 'blockdev-snapshot-sync' | ||
109 | + }, { | ||
110 | + 'data': { | ||
111 | + 'node-name': 'disk1', | ||
112 | + 'snapshot-file': disk1_snap_img_path, | ||
113 | + 'snapshot-node-name': 'disk1-snap', | ||
114 | + 'mode': 'absolute-paths', | ||
115 | + 'format': iotests.imgfmt | ||
116 | + }, | ||
117 | + 'type': 'blockdev-snapshot-sync' | ||
118 | + } | ||
119 | + ])) | ||
120 | diff --git a/tests/qemu-iotests/202.out b/tests/qemu-iotests/202.out | ||
121 | new file mode 100644 | ||
122 | index XXXXXXX..XXXXXXX | ||
123 | --- /dev/null | ||
124 | +++ b/tests/qemu-iotests/202.out | ||
125 | @@ -XXX,XX +XXX,XX @@ | ||
126 | +Launching VM... | ||
127 | +Adding IOThread... | ||
128 | +{u'return': {}} | ||
129 | +Adding blockdevs... | ||
130 | +{u'return': {}} | ||
131 | +{u'return': {}} | ||
132 | +Setting iothread... | ||
133 | +{u'return': {}} | ||
134 | +{u'return': {}} | ||
135 | +Creating external snapshots... | ||
136 | +{u'return': {}} | ||
137 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
18 | index XXXXXXX..XXXXXXX 100644 | 138 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tests/image-fuzzer/qcow2/layout.py | 139 | --- a/tests/qemu-iotests/group |
20 | +++ b/tests/image-fuzzer/qcow2/layout.py | 140 | +++ b/tests/qemu-iotests/group |
21 | @@ -XXX,XX +XXX,XX @@ class Image(object): | 141 | @@ -XXX,XX +XXX,XX @@ |
22 | def create_image(test_img_path, backing_file_name=None, backing_file_fmt=None, | 142 | 197 rw auto quick |
23 | fields_to_fuzz=None): | 143 | 198 rw auto |
24 | """Create a fuzzed image and write it to the specified file.""" | 144 | 200 rw auto |
25 | - image = Image(backing_file_name) | 145 | +202 rw auto quick |
26 | - image.set_backing_file_format(backing_file_fmt) | ||
27 | + image = Image(backing_file_name.encode()) | ||
28 | + image.set_backing_file_format(backing_file_fmt.encode()) | ||
29 | image.create_feature_name_table() | ||
30 | image.set_end_of_extension_area() | ||
31 | image.create_l_structures() | ||
32 | -- | 146 | -- |
33 | 2.23.0 | 147 | 2.14.3 |
34 | 148 | ||
35 | 149 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | From: Mark Kanda <mark.kanda@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Field values are supposed to be bytes objects, not unicode | 3 | Depending on the configuration, it can be beneficial to adjust the virtio-blk |
4 | strings. Change two constants that were declared as strings. | 4 | queue size to something other than the current default of 128. Add a new |
5 | property to make the queue size configurable. | ||
5 | 6 | ||
6 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 7 | Signed-off-by: Mark Kanda <mark.kanda@oracle.com> |
7 | Reviewed-by: John Snow <jsnow@redhat.com> | 8 | Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com> |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 9 | Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> |
9 | Message-id: 20191016192430.25098-8-ehabkost@redhat.com | 10 | Reviewed-by: Ameya More <ameya.more@oracle.com> |
10 | Message-Id: <20191016192430.25098-8-ehabkost@redhat.com> | 11 | Message-id: 52e6d742811f10dbd16e996e86cf375b9577c187.1513005190.git.mark.kanda@oracle.com |
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 13 | --- |
13 | tests/image-fuzzer/qcow2/layout.py | 4 ++-- | 14 | include/hw/virtio/virtio-blk.h | 1 + |
14 | 1 file changed, 2 insertions(+), 2 deletions(-) | 15 | hw/block/virtio-blk.c | 10 +++++++++- |
16 | 2 files changed, 10 insertions(+), 1 deletion(-) | ||
15 | 17 | ||
16 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | 18 | diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h |
17 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/image-fuzzer/qcow2/layout.py | 20 | --- a/include/hw/virtio/virtio-blk.h |
19 | +++ b/tests/image-fuzzer/qcow2/layout.py | 21 | +++ b/include/hw/virtio/virtio-blk.h |
20 | @@ -XXX,XX +XXX,XX @@ class Image(object): | 22 | @@ -XXX,XX +XXX,XX @@ struct VirtIOBlkConf |
21 | def create_header(self, cluster_bits, backing_file_name=None): | 23 | uint32_t config_wce; |
22 | """Generate a random valid header.""" | 24 | uint32_t request_merging; |
23 | meta_header = [ | 25 | uint16_t num_queues; |
24 | - ['>4s', 0, "QFI\xfb", 'magic'], | 26 | + uint16_t queue_size; |
25 | + ['>4s', 0, b"QFI\xfb", 'magic'], | 27 | }; |
26 | ['>I', 4, random.randint(2, 3), 'version'], | 28 | |
27 | ['>Q', 8, 0, 'backing_file_offset'], | 29 | struct VirtIOBlockDataPlane; |
28 | ['>I', 16, 0, 'backing_file_size'], | 30 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
29 | @@ -XXX,XX +XXX,XX @@ class Image(object): | 31 | index XXXXXXX..XXXXXXX 100644 |
30 | feature_tables = [] | 32 | --- a/hw/block/virtio-blk.c |
31 | feature_ids = [] | 33 | +++ b/hw/block/virtio-blk.c |
32 | inner_offset = self.ext_offset + ext_header_len | 34 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) |
33 | - feat_name = 'some cool feature' | 35 | error_setg(errp, "num-queues property must be larger than 0"); |
34 | + feat_name = b'some cool feature' | 36 | return; |
35 | while len(feature_tables) < num_fnt_entries * 3: | 37 | } |
36 | feat_type, feat_bit = gen_feat_ids() | 38 | + if (!is_power_of_2(conf->queue_size) || |
37 | # Remove duplicates | 39 | + conf->queue_size > VIRTQUEUE_MAX_SIZE) { |
40 | + error_setg(errp, "invalid queue-size property (%" PRIu16 "), " | ||
41 | + "must be a power of 2 (max %d)", | ||
42 | + conf->queue_size, VIRTQUEUE_MAX_SIZE); | ||
43 | + return; | ||
44 | + } | ||
45 | |||
46 | blkconf_serial(&conf->conf, &conf->serial); | ||
47 | if (!blkconf_apply_backend_options(&conf->conf, | ||
48 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) | ||
49 | s->sector_mask = (s->conf.conf.logical_block_size / BDRV_SECTOR_SIZE) - 1; | ||
50 | |||
51 | for (i = 0; i < conf->num_queues; i++) { | ||
52 | - virtio_add_queue(vdev, 128, virtio_blk_handle_output); | ||
53 | + virtio_add_queue(vdev, conf->queue_size, virtio_blk_handle_output); | ||
54 | } | ||
55 | virtio_blk_data_plane_create(vdev, conf, &s->dataplane, &err); | ||
56 | if (err != NULL) { | ||
57 | @@ -XXX,XX +XXX,XX @@ static Property virtio_blk_properties[] = { | ||
58 | DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0, | ||
59 | true), | ||
60 | DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1), | ||
61 | + DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128), | ||
62 | DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, | ||
63 | IOThread *), | ||
64 | DEFINE_PROP_END_OF_LIST(), | ||
38 | -- | 65 | -- |
39 | 2.23.0 | 66 | 2.14.3 |
40 | 67 | ||
41 | 68 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | From: Mark Kanda <mark.kanda@oracle.com> |
---|---|---|---|
2 | 2 | ||
3 | Most of the division expressions in image-fuzzer assume integer | 3 | virtio-blk logical block size should never be larger than physical block |
4 | division. Use the // operator to keep the same behavior when we | 4 | size because it doesn't make sense to have such configurations. QEMU doesn't |
5 | move to Python 3. | 5 | have a way to effectively express this condition; the best it can do is |
6 | report the physical block exponent as 0 - indicating the logical block size | ||
7 | equals the physical block size. | ||
6 | 8 | ||
7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 9 | This is identical to commit 3da023b5827543ee4c022986ea2ad9d1274410b2 |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | but applied to virtio-blk (instead of virtio-scsi). |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 11 | |
10 | Message-id: 20191016192430.25098-4-ehabkost@redhat.com | 12 | Signed-off-by: Mark Kanda <mark.kanda@oracle.com> |
11 | Message-Id: <20191016192430.25098-4-ehabkost@redhat.com> | 13 | Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> |
14 | Reviewed-by: Ameya More <ameya.more@oracle.com> | ||
15 | Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> | ||
16 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
17 | Message-id: 773169891f9f2deb4cb7c4ef2655580dbe24c1d1.1513005190.git.mark.kanda@oracle.com | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 19 | --- |
14 | tests/image-fuzzer/qcow2/fuzz.py | 12 ++++----- | 20 | hw/block/virtio-blk.c | 7 +++++++ |
15 | tests/image-fuzzer/qcow2/layout.py | 40 +++++++++++++++--------------- | 21 | 1 file changed, 7 insertions(+) |
16 | 2 files changed, 26 insertions(+), 26 deletions(-) | ||
17 | 22 | ||
18 | diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fuzz.py | 23 | diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c |
19 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/image-fuzzer/qcow2/fuzz.py | 25 | --- a/hw/block/virtio-blk.c |
21 | +++ b/tests/image-fuzzer/qcow2/fuzz.py | 26 | +++ b/hw/block/virtio-blk.c |
22 | @@ -XXX,XX +XXX,XX @@ UINT64 = 0xffffffffffffffff | 27 | @@ -XXX,XX +XXX,XX @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) |
23 | UINT32_M = 31 | 28 | |
24 | UINT64_M = 63 | 29 | blkconf_blocksizes(&conf->conf); |
25 | # Fuzz vectors | 30 | |
26 | -UINT8_V = [0, 0x10, UINT8/4, UINT8/2 - 1, UINT8/2, UINT8/2 + 1, UINT8 - 1, | 31 | + if (conf->conf.logical_block_size > |
27 | +UINT8_V = [0, 0x10, UINT8//4, UINT8//2 - 1, UINT8//2, UINT8//2 + 1, UINT8 - 1, | 32 | + conf->conf.physical_block_size) { |
28 | UINT8] | 33 | + error_setg(errp, |
29 | -UINT16_V = [0, 0x100, 0x1000, UINT16/4, UINT16/2 - 1, UINT16/2, UINT16/2 + 1, | 34 | + "logical_block_size > physical_block_size not supported"); |
30 | +UINT16_V = [0, 0x100, 0x1000, UINT16//4, UINT16//2 - 1, UINT16//2, UINT16//2 + 1, | 35 | + return; |
31 | UINT16 - 1, UINT16] | 36 | + } |
32 | -UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32/4, UINT32/2 - 1, | 37 | + |
33 | - UINT32/2, UINT32/2 + 1, UINT32 - 1, UINT32] | 38 | virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, |
34 | -UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64/4, | 39 | sizeof(struct virtio_blk_config)); |
35 | - UINT64/2 - 1, UINT64/2, UINT64/2 + 1, UINT64 - 1, | ||
36 | +UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32//4, UINT32//2 - 1, | ||
37 | + UINT32//2, UINT32//2 + 1, UINT32 - 1, UINT32] | ||
38 | +UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4, | ||
39 | + UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1, | ||
40 | UINT64] | ||
41 | STRING_V = ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x', | ||
42 | '%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%20n', | ||
43 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/tests/image-fuzzer/qcow2/layout.py | ||
46 | +++ b/tests/image-fuzzer/qcow2/layout.py | ||
47 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
48 | ['>I', self.ext_offset, 0x6803f857, 'ext_magic'], | ||
49 | # One feature table contains 3 fields and takes 48 bytes | ||
50 | ['>I', self.ext_offset + UINT32_S, | ||
51 | - len(feature_tables) / 3 * 48, 'ext_length'] | ||
52 | + len(feature_tables) // 3 * 48, 'ext_length'] | ||
53 | ] + feature_tables) | ||
54 | self.ext_offset = inner_offset | ||
55 | |||
56 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
57 | def create_l2_entry(host, guest, l2_cluster): | ||
58 | """Generate one L2 entry.""" | ||
59 | offset = l2_cluster * self.cluster_size | ||
60 | - l2_size = self.cluster_size / UINT64_S | ||
61 | + l2_size = self.cluster_size // UINT64_S | ||
62 | entry_offset = offset + UINT64_S * (guest % l2_size) | ||
63 | cluster_descriptor = host * self.cluster_size | ||
64 | if not self.header['version'][0].value == 2: | ||
65 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
66 | |||
67 | def create_l1_entry(l2_cluster, l1_offset, guest): | ||
68 | """Generate one L1 entry.""" | ||
69 | - l2_size = self.cluster_size / UINT64_S | ||
70 | - entry_offset = l1_offset + UINT64_S * (guest / l2_size) | ||
71 | + l2_size = self.cluster_size // UINT64_S | ||
72 | + entry_offset = l1_offset + UINT64_S * (guest // l2_size) | ||
73 | # While snapshots are not supported bit #63 = 1 | ||
74 | entry_val = (1 << 63) + l2_cluster * self.cluster_size | ||
75 | return ['>Q', entry_offset, entry_val, 'l1_entry'] | ||
76 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
77 | l2 = [] | ||
78 | else: | ||
79 | meta_data = self._get_metadata() | ||
80 | - guest_clusters = random.sample(range(self.image_size / | ||
81 | + guest_clusters = random.sample(range(self.image_size // | ||
82 | self.cluster_size), | ||
83 | len(self.data_clusters)) | ||
84 | # Number of entries in a L1/L2 table | ||
85 | - l_size = self.cluster_size / UINT64_S | ||
86 | + l_size = self.cluster_size // UINT64_S | ||
87 | # Number of clusters necessary for L1 table | ||
88 | l1_size = int(ceil((max(guest_clusters) + 1) / float(l_size**2))) | ||
89 | l1_start = self._get_adjacent_clusters(self.data_clusters | | ||
90 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
91 | # L2 entries | ||
92 | l2 = [] | ||
93 | for host, guest in zip(self.data_clusters, guest_clusters): | ||
94 | - l2_id = guest / l_size | ||
95 | + l2_id = guest // l_size | ||
96 | if l2_id not in l2_ids: | ||
97 | l2_ids.append(l2_id) | ||
98 | l2_clusters.append(self._get_adjacent_clusters( | ||
99 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
100 | def allocate_rfc_blocks(data, size): | ||
101 | """Return indices of clusters allocated for refcount blocks.""" | ||
102 | cluster_ids = set() | ||
103 | - diff = block_ids = set([x / size for x in data]) | ||
104 | + diff = block_ids = set([x // size for x in data]) | ||
105 | while len(diff) != 0: | ||
106 | # Allocate all yet not allocated clusters | ||
107 | new = self._get_available_clusters(data | cluster_ids, | ||
108 | len(diff)) | ||
109 | # Indices of new refcount blocks necessary to cover clusters | ||
110 | # in 'new' | ||
111 | - diff = set([x / size for x in new]) - block_ids | ||
112 | + diff = set([x // size for x in new]) - block_ids | ||
113 | cluster_ids |= new | ||
114 | block_ids |= diff | ||
115 | return cluster_ids, block_ids | ||
116 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
117 | blocks = set(init_blocks) | ||
118 | clusters = set() | ||
119 | # Number of entries in one cluster of the refcount table | ||
120 | - size = self.cluster_size / UINT64_S | ||
121 | + size = self.cluster_size // UINT64_S | ||
122 | # Number of clusters necessary for the refcount table based on | ||
123 | # the current number of refcount blocks | ||
124 | table_size = int(ceil((max(blocks) + 1) / float(size))) | ||
125 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
126 | table_size + 1)) | ||
127 | # New refcount blocks necessary for clusters occupied by the | ||
128 | # refcount table | ||
129 | - diff = set([c / block_size for c in table_clusters]) - blocks | ||
130 | + diff = set([c // block_size for c in table_clusters]) - blocks | ||
131 | blocks |= diff | ||
132 | while len(diff) != 0: | ||
133 | # Allocate clusters for new refcount blocks | ||
134 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
135 | len(diff)) | ||
136 | # Indices of new refcount blocks necessary to cover | ||
137 | # clusters in 'new' | ||
138 | - diff = set([x / block_size for x in new]) - blocks | ||
139 | + diff = set([x // block_size for x in new]) - blocks | ||
140 | clusters |= new | ||
141 | blocks |= diff | ||
142 | # Check if the refcount table needs one more cluster | ||
143 | if int(ceil((max(blocks) + 1) / float(size))) > table_size: | ||
144 | - new_block_id = (table_start + table_size) / block_size | ||
145 | + new_block_id = (table_start + table_size) // block_size | ||
146 | # Check if the additional table cluster needs | ||
147 | # one more refcount block | ||
148 | if new_block_id not in blocks: | ||
149 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
150 | def create_table_entry(table_offset, block_cluster, block_size, | ||
151 | cluster): | ||
152 | """Generate a refcount table entry.""" | ||
153 | - offset = table_offset + UINT64_S * (cluster / block_size) | ||
154 | + offset = table_offset + UINT64_S * (cluster // block_size) | ||
155 | return ['>Q', offset, block_cluster * self.cluster_size, | ||
156 | 'refcount_table_entry'] | ||
157 | |||
158 | def create_block_entry(block_cluster, block_size, cluster): | ||
159 | """Generate a list of entries for the current block.""" | ||
160 | - entry_size = self.cluster_size / block_size | ||
161 | + entry_size = self.cluster_size // block_size | ||
162 | offset = block_cluster * self.cluster_size | ||
163 | entry_offset = offset + entry_size * (cluster % block_size) | ||
164 | # While snapshots are not supported all refcounts are set to 1 | ||
165 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
166 | # Number of refcount entries per refcount block | ||
167 | # Convert self.cluster_size from bytes to bits to have the same | ||
168 | # base for the numerator and denominator | ||
169 | - block_size = self.cluster_size * 8 / refcount_bits | ||
170 | + block_size = self.cluster_size * 8 // refcount_bits | ||
171 | meta_data = self._get_metadata() | ||
172 | if len(self.data_clusters) == 0: | ||
173 | # All metadata for an empty guest image needs 4 clusters: | ||
174 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
175 | rfc_blocks = [] | ||
176 | |||
177 | for cluster in sorted(self.data_clusters | meta_data): | ||
178 | - if cluster / block_size != block_id: | ||
179 | - block_id = cluster / block_size | ||
180 | + if cluster // block_size != block_id: | ||
181 | + block_id = cluster // block_size | ||
182 | block_cluster = block_clusters[block_ids.index(block_id)] | ||
183 | rfc_table.append(create_table_entry(table_offset, | ||
184 | block_cluster, | ||
185 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
186 | def _alloc_data(img_size, cluster_size): | ||
187 | """Return a set of random indices of clusters allocated for guest data. | ||
188 | """ | ||
189 | - num_of_cls = img_size/cluster_size | ||
190 | + num_of_cls = img_size // cluster_size | ||
191 | return set(random.sample(range(1, num_of_cls + 1), | ||
192 | random.randint(0, num_of_cls))) | ||
193 | |||
194 | @@ -XXX,XX +XXX,XX @@ class Image(object): | ||
195 | """Return indices of clusters allocated for image metadata.""" | ||
196 | ids = set() | ||
197 | for x in self: | ||
198 | - ids.add(x.offset/self.cluster_size) | ||
199 | + ids.add(x.offset // self.cluster_size) | ||
200 | return ids | ||
201 | |||
202 | 40 | ||
203 | -- | 41 | -- |
204 | 2.23.0 | 42 | 2.14.3 |
205 | 43 | ||
206 | 44 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | From: Paolo Bonzini <pbonzini@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | No caller of fuzzer functions is interested in unicode string values, | 3 | BDRV_POLL_WHILE() does not support recursive AioContext locking. It |
4 | so replace them with bytes sequences. | 4 | only releases the AioContext lock once regardless of how many times the |
5 | caller has acquired it. This results in a hang since the IOThread does | ||
6 | not make progress while the AioContext is still locked. | ||
5 | 7 | ||
6 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 8 | The following steps trigger the hang: |
7 | Reviewed-by: John Snow <jsnow@redhat.com> | 9 | |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 10 | $ qemu-system-x86_64 -M accel=kvm -m 1G -cpu host \ |
9 | Message-id: 20191016192430.25098-7-ehabkost@redhat.com | 11 | -object iothread,id=iothread0 \ |
10 | Message-Id: <20191016192430.25098-7-ehabkost@redhat.com> | 12 | -device virtio-scsi-pci,iothread=iothread0 \ |
13 | -drive if=none,id=drive0,file=test.img,format=raw \ | ||
14 | -device scsi-hd,drive=drive0 \ | ||
15 | -drive if=none,id=drive1,file=test.img,format=raw \ | ||
16 | -device scsi-hd,drive=drive1 | ||
17 | $ qemu-system-x86_64 ...same options... \ | ||
18 | -incoming tcp::1234 | ||
19 | (qemu) migrate tcp:127.0.0.1:1234 | ||
20 | ...hang... | ||
21 | |||
22 | Tested-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
23 | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> | ||
24 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
25 | Message-id: 20171207201320.19284-2-stefanha@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 26 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 27 | --- |
13 | tests/image-fuzzer/qcow2/fuzz.py | 42 ++++++++++++++++---------------- | 28 | block.c | 14 +++++++++++--- |
14 | 1 file changed, 21 insertions(+), 21 deletions(-) | 29 | 1 file changed, 11 insertions(+), 3 deletions(-) |
15 | 30 | ||
16 | diff --git a/tests/image-fuzzer/qcow2/fuzz.py b/tests/image-fuzzer/qcow2/fuzz.py | 31 | diff --git a/block.c b/block.c |
17 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/image-fuzzer/qcow2/fuzz.py | 33 | --- a/block.c |
19 | +++ b/tests/image-fuzzer/qcow2/fuzz.py | 34 | +++ b/block.c |
20 | @@ -XXX,XX +XXX,XX @@ UINT32_V = [0, 0x100, 0x1000, 0x10000, 0x100000, UINT32//4, UINT32//2 - 1, | 35 | @@ -XXX,XX +XXX,XX @@ int bdrv_inactivate_all(void) |
21 | UINT64_V = UINT32_V + [0x1000000, 0x10000000, 0x100000000, UINT64//4, | 36 | BdrvNextIterator it; |
22 | UINT64//2 - 1, UINT64//2, UINT64//2 + 1, UINT64 - 1, | 37 | int ret = 0; |
23 | UINT64] | 38 | int pass; |
24 | -STRING_V = ['%s%p%x%d', '.1024d', '%.2049d', '%p%p%p%p', '%x%x%x%x', | 39 | + GSList *aio_ctxs = NULL, *ctx; |
25 | - '%d%d%d%d', '%s%s%s%s', '%99999999999s', '%08x', '%%20d', '%%20n', | 40 | |
26 | - '%%20x', '%%20s', '%s%s%s%s%s%s%s%s%s%s', '%p%p%p%p%p%p%p%p%p%p', | 41 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
27 | - '%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%', | 42 | - aio_context_acquire(bdrv_get_aio_context(bs)); |
28 | - '%s x 129', '%x x 257'] | 43 | + AioContext *aio_context = bdrv_get_aio_context(bs); |
29 | +BYTES_V = [b'%s%p%x%d', b'.1024d', b'%.2049d', b'%p%p%p%p', b'%x%x%x%x', | 44 | + |
30 | + b'%d%d%d%d', b'%s%s%s%s', b'%99999999999s', b'%08x', b'%%20d', b'%%20n', | 45 | + if (!g_slist_find(aio_ctxs, aio_context)) { |
31 | + b'%%20x', b'%%20s', b'%s%s%s%s%s%s%s%s%s%s', b'%p%p%p%p%p%p%p%p%p%p', | 46 | + aio_ctxs = g_slist_prepend(aio_ctxs, aio_context); |
32 | + b'%#0123456x%08x%x%s%p%d%n%o%u%c%h%l%q%j%z%Z%t%i%e%g%f%a%C%S%08x%%', | 47 | + aio_context_acquire(aio_context); |
33 | + b'%s x 129', b'%x x 257'] | 48 | + } |
34 | 49 | } | |
35 | 50 | ||
36 | def random_from_intervals(intervals): | 51 | /* We do two passes of inactivation. The first pass calls to drivers' |
37 | @@ -XXX,XX +XXX,XX @@ def random_bits(bit_ranges): | 52 | @@ -XXX,XX +XXX,XX @@ int bdrv_inactivate_all(void) |
38 | return val | 53 | } |
39 | 54 | ||
40 | 55 | out: | |
41 | -def truncate_string(strings, length): | 56 | - for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
42 | - """Return strings truncated to specified length.""" | 57 | - aio_context_release(bdrv_get_aio_context(bs)); |
43 | - if type(strings) == list: | 58 | + for (ctx = aio_ctxs; ctx != NULL; ctx = ctx->next) { |
44 | - return [s[:length] for s in strings] | 59 | + AioContext *aio_context = ctx->data; |
45 | +def truncate_bytes(sequences, length): | 60 | + aio_context_release(aio_context); |
46 | + """Return sequences truncated to specified length.""" | 61 | } |
47 | + if type(sequences) == list: | 62 | + g_slist_free(aio_ctxs); |
48 | + return [s[:length] for s in sequences] | 63 | |
49 | else: | 64 | return ret; |
50 | - return strings[:length] | 65 | } |
51 | + return sequences[:length] | ||
52 | |||
53 | |||
54 | def validator(current, pick, choices): | ||
55 | @@ -XXX,XX +XXX,XX @@ def bit_validator(current, bit_ranges): | ||
56 | return validator(current, random_bits, bit_ranges) | ||
57 | |||
58 | |||
59 | -def string_validator(current, strings): | ||
60 | - """Return a random string value from the list not equal to the current. | ||
61 | +def bytes_validator(current, sequences): | ||
62 | + """Return a random bytes value from the list not equal to the current. | ||
63 | |||
64 | This function is useful for selection from valid values except current one. | ||
65 | """ | ||
66 | - return validator(current, random.choice, strings) | ||
67 | + return validator(current, random.choice, sequences) | ||
68 | |||
69 | |||
70 | def selector(current, constraints, validate=int_validator): | ||
71 | @@ -XXX,XX +XXX,XX @@ def header_length(current): | ||
72 | def bf_name(current): | ||
73 | """Fuzz the backing file name.""" | ||
74 | constraints = [ | ||
75 | - truncate_string(STRING_V, len(current)) | ||
76 | + truncate_bytes(BYTES_V, len(current)) | ||
77 | ] | ||
78 | - return selector(current, constraints, string_validator) | ||
79 | + return selector(current, constraints, bytes_validator) | ||
80 | |||
81 | |||
82 | def ext_magic(current): | ||
83 | @@ -XXX,XX +XXX,XX @@ def ext_length(current): | ||
84 | def bf_format(current): | ||
85 | """Fuzz backing file format in the corresponding header extension.""" | ||
86 | constraints = [ | ||
87 | - truncate_string(STRING_V, len(current)), | ||
88 | - truncate_string(STRING_V, (len(current) + 7) & ~7) # Fuzz padding | ||
89 | + truncate_bytes(BYTES_V, len(current)), | ||
90 | + truncate_bytes(BYTES_V, (len(current) + 7) & ~7) # Fuzz padding | ||
91 | ] | ||
92 | - return selector(current, constraints, string_validator) | ||
93 | + return selector(current, constraints, bytes_validator) | ||
94 | |||
95 | |||
96 | def feature_type(current): | ||
97 | @@ -XXX,XX +XXX,XX @@ def feature_bit_number(current): | ||
98 | def feature_name(current): | ||
99 | """Fuzz feature name field of a feature name table header extension.""" | ||
100 | constraints = [ | ||
101 | - truncate_string(STRING_V, len(current)), | ||
102 | - truncate_string(STRING_V, 46) # Fuzz padding (field length = 46) | ||
103 | + truncate_bytes(BYTES_V, len(current)), | ||
104 | + truncate_bytes(BYTES_V, 46) # Fuzz padding (field length = 46) | ||
105 | ] | ||
106 | - return selector(current, constraints, string_validator) | ||
107 | + return selector(current, constraints, bytes_validator) | ||
108 | |||
109 | |||
110 | def l1_entry(current): | ||
111 | -- | 66 | -- |
112 | 2.23.0 | 67 | 2.14.3 |
113 | 68 | ||
114 | 69 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | See the patch for why nested AioContext locking is no longer allowed. |
---|---|---|---|
2 | 2 | ||
3 | This makes the formatting code simpler, and safer if we change | 3 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | the type of self.value from str to bytes. | 4 | Reviewed-by: Eric Blake <eblake@redhat.com> |
5 | 5 | Message-id: 20171207201320.19284-3-stefanha@redhat.com | |
6 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
7 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20191016192430.25098-6-ehabkost@redhat.com | ||
10 | Message-Id: <20191016192430.25098-6-ehabkost@redhat.com> | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 6 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 7 | --- |
13 | tests/image-fuzzer/qcow2/layout.py | 4 ++-- | 8 | docs/devel/multiple-iothreads.txt | 7 ++++--- |
14 | 1 file changed, 2 insertions(+), 2 deletions(-) | 9 | 1 file changed, 4 insertions(+), 3 deletions(-) |
15 | 10 | ||
16 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | 11 | diff --git a/docs/devel/multiple-iothreads.txt b/docs/devel/multiple-iothreads.txt |
17 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tests/image-fuzzer/qcow2/layout.py | 13 | --- a/docs/devel/multiple-iothreads.txt |
19 | +++ b/tests/image-fuzzer/qcow2/layout.py | 14 | +++ b/docs/devel/multiple-iothreads.txt |
20 | @@ -XXX,XX +XXX,XX @@ class Field(object): | 15 | @@ -XXX,XX +XXX,XX @@ |
21 | return iter([self.fmt, self.offset, self.value, self.name]) | 16 | -Copyright (c) 2014 Red Hat Inc. |
22 | 17 | +Copyright (c) 2014-2017 Red Hat Inc. | |
23 | def __repr__(self): | 18 | |
24 | - return "Field(fmt='%s', offset=%d, value=%s, name=%s)" % \ | 19 | This work is licensed under the terms of the GNU GPL, version 2 or later. See |
25 | - (self.fmt, self.offset, str(self.value), self.name) | 20 | the COPYING file in the top-level directory. |
26 | + return "Field(fmt=%r, offset=%r, value=%r, name=%r)" % \ | 21 | @@ -XXX,XX +XXX,XX @@ aio_context_acquire()/aio_context_release() for mutual exclusion. Once the |
27 | + (self.fmt, self.offset, self.value, self.name) | 22 | context is acquired no other thread can access it or run event loop iterations |
28 | 23 | in this AioContext. | |
29 | 24 | ||
30 | class FieldsList(object): | 25 | -aio_context_acquire()/aio_context_release() calls may be nested. This |
26 | -means you can call them if you're not sure whether #2 applies. | ||
27 | +Legacy code sometimes nests aio_context_acquire()/aio_context_release() calls. | ||
28 | +Do not use nesting anymore, it is incompatible with the BDRV_POLL_WHILE() macro | ||
29 | +used in the block layer and can lead to hangs. | ||
30 | |||
31 | There is currently no lock ordering rule if a thread needs to acquire multiple | ||
32 | AioContexts simultaneously. Therefore, it is only safe for code holding the | ||
31 | -- | 33 | -- |
32 | 2.23.0 | 34 | 2.14.3 |
33 | 35 | ||
34 | 36 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | When a node is already associated with a BlockBackend the |
---|---|---|---|
2 | x-blockdev-set-iothread command refuses to set the IOThread. This is to | ||
3 | prevent accidentally changing the IOThread when the nodes are in use. | ||
2 | 4 | ||
3 | image-fuzzer is now supposed to be ready to run using Python 3. | 5 | When the nodes are created with -drive they automatically get a |
4 | Remove the __future__ imports and change the interpreter line to | 6 | BlockBackend. In that case we know nothing is using them yet and it's |
5 | "#!/usr/bin/env python3". | 7 | safe to set the IOThread. Add a force boolean to override the check. |
6 | 8 | ||
7 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 9 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | Reviewed-by: John Snow <jsnow@redhat.com> | 10 | Reviewed-by: Eric Blake <eblake@redhat.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 11 | Message-id: 20171207201320.19284-4-stefanha@redhat.com |
10 | Message-id: 20191016192430.25098-10-ehabkost@redhat.com | ||
11 | Message-Id: <20191016192430.25098-10-ehabkost@redhat.com> | ||
12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
13 | --- | 13 | --- |
14 | tests/image-fuzzer/qcow2/__init__.py | 1 - | 14 | qapi/block-core.json | 6 +++++- |
15 | tests/image-fuzzer/qcow2/layout.py | 1 - | 15 | blockdev.c | 11 ++++++----- |
16 | tests/image-fuzzer/runner.py | 3 +-- | 16 | 2 files changed, 11 insertions(+), 6 deletions(-) |
17 | 3 files changed, 1 insertion(+), 4 deletions(-) | ||
18 | 17 | ||
19 | diff --git a/tests/image-fuzzer/qcow2/__init__.py b/tests/image-fuzzer/qcow2/__init__.py | 18 | diff --git a/qapi/block-core.json b/qapi/block-core.json |
20 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/tests/image-fuzzer/qcow2/__init__.py | 20 | --- a/qapi/block-core.json |
22 | +++ b/tests/image-fuzzer/qcow2/__init__.py | 21 | +++ b/qapi/block-core.json |
23 | @@ -1,2 +1 @@ | ||
24 | -from __future__ import absolute_import | ||
25 | from .layout import create_image | ||
26 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/tests/image-fuzzer/qcow2/layout.py | ||
29 | +++ b/tests/image-fuzzer/qcow2/layout.py | ||
30 | @@ -XXX,XX +XXX,XX @@ | 22 | @@ -XXX,XX +XXX,XX @@ |
31 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
32 | # | 23 | # |
33 | 24 | # @iothread: the name of the IOThread object or null for the main loop | |
34 | -from __future__ import absolute_import | 25 | # |
35 | import random | 26 | +# @force: true if the node and its children should be moved when a BlockBackend |
36 | import struct | 27 | +# is already attached |
37 | from . import fuzz | 28 | +# |
38 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py | 29 | # Note: this command is experimental and intended for test cases that need |
39 | index XXXXXXX..XXXXXXX 100755 | 30 | # control over IOThreads only. |
40 | --- a/tests/image-fuzzer/runner.py | ||
41 | +++ b/tests/image-fuzzer/runner.py | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | -#!/usr/bin/env python | ||
44 | +#!/usr/bin/env python3 | ||
45 | |||
46 | # Tool for running fuzz tests | ||
47 | # | 31 | # |
48 | @@ -XXX,XX +XXX,XX @@ | 32 | @@ -XXX,XX +XXX,XX @@ |
49 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 33 | ## |
50 | # | 34 | { 'command': 'x-blockdev-set-iothread', |
51 | 35 | 'data' : { 'node-name': 'str', | |
52 | -from __future__ import print_function | 36 | - 'iothread': 'StrOrNull' } } |
53 | import sys | 37 | + 'iothread': 'StrOrNull', |
54 | import os | 38 | + '*force': 'bool' } } |
55 | import signal | 39 | diff --git a/blockdev.c b/blockdev.c |
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/blockdev.c | ||
42 | +++ b/blockdev.c | ||
43 | @@ -XXX,XX +XXX,XX @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp) | ||
44 | } | ||
45 | |||
46 | void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread, | ||
47 | - Error **errp) | ||
48 | + bool has_force, bool force, Error **errp) | ||
49 | { | ||
50 | AioContext *old_context; | ||
51 | AioContext *new_context; | ||
52 | @@ -XXX,XX +XXX,XX @@ void qmp_x_blockdev_set_iothread(const char *node_name, StrOrNull *iothread, | ||
53 | return; | ||
54 | } | ||
55 | |||
56 | - /* If we want to allow more extreme test scenarios this guard could be | ||
57 | - * removed. For now it protects against accidents. */ | ||
58 | - if (bdrv_has_blk(bs)) { | ||
59 | - error_setg(errp, "Node %s is in use", node_name); | ||
60 | + /* Protects against accidents. */ | ||
61 | + if (!(has_force && force) && bdrv_has_blk(bs)) { | ||
62 | + error_setg(errp, "Node %s is associated with a BlockBackend and could " | ||
63 | + "be in use (use force=true to override this check)", | ||
64 | + node_name); | ||
65 | return; | ||
66 | } | ||
67 | |||
56 | -- | 68 | -- |
57 | 2.23.0 | 69 | 2.14.3 |
58 | 70 | ||
59 | 71 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | The VM.add_object() method can be used to add IOThreads or memory |
---|---|---|---|
2 | backend objects. | ||
2 | 3 | ||
3 | StringIO.StringIO is not available on Python 3, but io.StringIO | 4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | is available on both Python 2 and 3. io.StringIO is slightly | 5 | Reviewed-by: Eric Blake <eblake@redhat.com> |
5 | different from the Python 2 StringIO module, though, so we need | 6 | Message-id: 20171207201320.19284-5-stefanha@redhat.com |
6 | bytes coming from subprocess.Popen() to be explicitly decoded. | ||
7 | |||
8 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20191016192430.25098-5-ehabkost@redhat.com | ||
12 | Message-Id: <20191016192430.25098-5-ehabkost@redhat.com> | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 8 | --- |
15 | tests/image-fuzzer/runner.py | 14 +++++++++----- | 9 | tests/qemu-iotests/iotests.py | 5 +++++ |
16 | 1 file changed, 9 insertions(+), 5 deletions(-) | 10 | 1 file changed, 5 insertions(+) |
17 | 11 | ||
18 | diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py | 12 | diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py |
19 | index XXXXXXX..XXXXXXX 100755 | 13 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/image-fuzzer/runner.py | 14 | --- a/tests/qemu-iotests/iotests.py |
21 | +++ b/tests/image-fuzzer/runner.py | 15 | +++ b/tests/qemu-iotests/iotests.py |
22 | @@ -XXX,XX +XXX,XX @@ import shutil | 16 | @@ -XXX,XX +XXX,XX @@ class VM(qtest.QEMUQtestMachine): |
23 | from itertools import count | 17 | socket_scm_helper=socket_scm_helper) |
24 | import time | 18 | self._num_drives = 0 |
25 | import getopt | 19 | |
26 | -import StringIO | 20 | + def add_object(self, opts): |
27 | +import io | 21 | + self._args.append('-object') |
28 | import resource | 22 | + self._args.append(opts) |
29 | 23 | + return self | |
30 | try: | 24 | + |
31 | @@ -XXX,XX +XXX,XX @@ def run_app(fd, q_args): | 25 | def add_device(self, opts): |
32 | try: | 26 | self._args.append('-device') |
33 | out, err = process.communicate() | 27 | self._args.append(opts) |
34 | signal.alarm(0) | ||
35 | - fd.write(out) | ||
36 | - fd.write(err) | ||
37 | + # fd is a text file, so we need to decode the process output before | ||
38 | + # writing to it. | ||
39 | + # We could be simply using the `errors` parameter of subprocess.Popen(), | ||
40 | + # but this will be possible only after migrating to Python 3 | ||
41 | + fd.write(out.decode(errors='replace')) | ||
42 | + fd.write(err.decode(errors='replace')) | ||
43 | fd.flush() | ||
44 | return process.returncode | ||
45 | |||
46 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): | ||
47 | MAX_BACKING_FILE_SIZE) * (1 << 20) | ||
48 | cmd = self.qemu_img + ['create', '-f', backing_file_fmt, | ||
49 | backing_file_name, str(backing_file_size)] | ||
50 | - temp_log = StringIO.StringIO() | ||
51 | + temp_log = io.StringIO() | ||
52 | retcode = run_app(temp_log, cmd) | ||
53 | if retcode == 0: | ||
54 | temp_log.close() | ||
55 | @@ -XXX,XX +XXX,XX @@ class TestEnv(object): | ||
56 | "Backing file: %s\n" \ | ||
57 | % (self.seed, " ".join(current_cmd), | ||
58 | self.current_dir, backing_file_name) | ||
59 | - temp_log = StringIO.StringIO() | ||
60 | + temp_log = io.StringIO() | ||
61 | try: | ||
62 | retcode = run_app(temp_log, current_cmd) | ||
63 | except OSError as e: | ||
64 | -- | 28 | -- |
65 | 2.23.0 | 29 | 2.14.3 |
66 | 30 | ||
67 | 31 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | There is a small chance that iothread_stop() hangs as follows: |
---|---|---|---|
2 | 2 | ||
3 | This is necessary for Python 3 compatibility. | 3 | Thread 3 (Thread 0x7f63eba5f700 (LWP 16105)): |
4 | #0 0x00007f64012c09b6 in ppoll () at /lib64/libc.so.6 | ||
5 | #1 0x000055959992eac9 in ppoll (__ss=0x0, __timeout=0x0, __nfds=<optimized out>, __fds=<optimized out>) at /usr/include/bits/poll2.h:77 | ||
6 | #2 0x000055959992eac9 in qemu_poll_ns (fds=<optimized out>, nfds=<optimized out>, timeout=<optimized out>) at util/qemu-timer.c:322 | ||
7 | #3 0x0000559599930711 in aio_poll (ctx=0x55959bdb83c0, blocking=blocking@entry=true) at util/aio-posix.c:629 | ||
8 | #4 0x00005595996806fe in iothread_run (opaque=0x55959bd78400) at iothread.c:59 | ||
9 | #5 0x00007f640159f609 in start_thread () at /lib64/libpthread.so.0 | ||
10 | #6 0x00007f64012cce6f in clone () at /lib64/libc.so.6 | ||
4 | 11 | ||
5 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 12 | Thread 1 (Thread 0x7f640b45b280 (LWP 16103)): |
6 | Reviewed-by: John Snow <jsnow@redhat.com> | 13 | #0 0x00007f64015a0b6d in pthread_join () at /lib64/libpthread.so.0 |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 14 | #1 0x00005595999332ef in qemu_thread_join (thread=<optimized out>) at util/qemu-thread-posix.c:547 |
8 | Message-id: 20191016192430.25098-3-ehabkost@redhat.com | 15 | #2 0x00005595996808ae in iothread_stop (iothread=<optimized out>) at iothread.c:91 |
9 | Message-Id: <20191016192430.25098-3-ehabkost@redhat.com> | 16 | #3 0x000055959968094d in iothread_stop_iter (object=<optimized out>, opaque=<optimized out>) at iothread.c:102 |
17 | #4 0x0000559599857d97 in do_object_child_foreach (obj=obj@entry=0x55959bdb8100, fn=fn@entry=0x559599680930 <iothread_stop_iter>, opaque=opaque@entry=0x0, recurse=recurse@entry=false) at qom/object.c:852 | ||
18 | #5 0x0000559599859477 in object_child_foreach (obj=obj@entry=0x55959bdb8100, fn=fn@entry=0x559599680930 <iothread_stop_iter>, opaque=opaque@entry=0x0) at qom/object.c:867 | ||
19 | #6 0x0000559599680a6e in iothread_stop_all () at iothread.c:341 | ||
20 | #7 0x000055959955b1d5 in main (argc=<optimized out>, argv=<optimized out>, envp=<optimized out>) at vl.c:4913 | ||
21 | |||
22 | The relevant code from iothread_run() is: | ||
23 | |||
24 | while (!atomic_read(&iothread->stopping)) { | ||
25 | aio_poll(iothread->ctx, true); | ||
26 | |||
27 | and iothread_stop(): | ||
28 | |||
29 | iothread->stopping = true; | ||
30 | aio_notify(iothread->ctx); | ||
31 | ... | ||
32 | qemu_thread_join(&iothread->thread); | ||
33 | |||
34 | The following scenario can occur: | ||
35 | |||
36 | 1. IOThread: | ||
37 | while (!atomic_read(&iothread->stopping)) -> stopping=false | ||
38 | |||
39 | 2. Main loop: | ||
40 | iothread->stopping = true; | ||
41 | aio_notify(iothread->ctx); | ||
42 | |||
43 | 3. IOThread: | ||
44 | aio_poll(iothread->ctx, true); -> hang | ||
45 | |||
46 | The bug is explained by the AioContext->notify_me doc comments: | ||
47 | |||
48 | "If this field is 0, everything (file descriptors, bottom halves, | ||
49 | timers) will be re-evaluated before the next blocking poll(), thus the | ||
50 | event_notifier_set call can be skipped." | ||
51 | |||
52 | The problem is that "everything" does not include checking | ||
53 | iothread->stopping. This means iothread_run() will block in aio_poll() | ||
54 | if aio_notify() was called just before aio_poll(). | ||
55 | |||
56 | This patch fixes the hang by replacing aio_notify() with | ||
57 | aio_bh_schedule_oneshot(). This makes aio_poll() or g_main_loop_run() | ||
58 | to return. | ||
59 | |||
60 | Implementing this properly required a new bool running flag. The new | ||
61 | flag prevents races that are tricky if we try to use iothread->stopping. | ||
62 | Now iothread->stopping is purely for iothread_stop() and | ||
63 | iothread->running is purely for the iothread_run() thread. | ||
64 | |||
65 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
66 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
67 | Message-id: 20171207201320.19284-6-stefanha@redhat.com | ||
10 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 68 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
11 | --- | 69 | --- |
12 | tests/image-fuzzer/qcow2/layout.py | 2 +- | 70 | include/sysemu/iothread.h | 3 ++- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 71 | iothread.c | 20 +++++++++++++++----- |
72 | 2 files changed, 17 insertions(+), 6 deletions(-) | ||
14 | 73 | ||
15 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | 74 | diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h |
16 | index XXXXXXX..XXXXXXX 100644 | 75 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tests/image-fuzzer/qcow2/layout.py | 76 | --- a/include/sysemu/iothread.h |
18 | +++ b/tests/image-fuzzer/qcow2/layout.py | 77 | +++ b/include/sysemu/iothread.h |
19 | @@ -XXX,XX +XXX,XX @@ class Image(object): | 78 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
20 | rounded = (size + self.cluster_size - 1) & ~(self.cluster_size - 1) | 79 | GOnce once; |
21 | if rounded > size: | 80 | QemuMutex init_done_lock; |
22 | image_file.seek(rounded - 1) | 81 | QemuCond init_done_cond; /* is thread initialization done? */ |
23 | - image_file.write("\0") | 82 | - bool stopping; |
24 | + image_file.write(b'\x00') | 83 | + bool stopping; /* has iothread_stop() been called? */ |
25 | image_file.close() | 84 | + bool running; /* should iothread_run() continue? */ |
26 | 85 | int thread_id; | |
27 | @staticmethod | 86 | |
87 | /* AioContext poll parameters */ | ||
88 | diff --git a/iothread.c b/iothread.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/iothread.c | ||
91 | +++ b/iothread.c | ||
92 | @@ -XXX,XX +XXX,XX @@ static void *iothread_run(void *opaque) | ||
93 | qemu_cond_signal(&iothread->init_done_cond); | ||
94 | qemu_mutex_unlock(&iothread->init_done_lock); | ||
95 | |||
96 | - while (!atomic_read(&iothread->stopping)) { | ||
97 | + while (iothread->running) { | ||
98 | aio_poll(iothread->ctx, true); | ||
99 | |||
100 | if (atomic_read(&iothread->worker_context)) { | ||
101 | @@ -XXX,XX +XXX,XX @@ static void *iothread_run(void *opaque) | ||
102 | return NULL; | ||
103 | } | ||
104 | |||
105 | +/* Runs in iothread_run() thread */ | ||
106 | +static void iothread_stop_bh(void *opaque) | ||
107 | +{ | ||
108 | + IOThread *iothread = opaque; | ||
109 | + | ||
110 | + iothread->running = false; /* stop iothread_run() */ | ||
111 | + | ||
112 | + if (iothread->main_loop) { | ||
113 | + g_main_loop_quit(iothread->main_loop); | ||
114 | + } | ||
115 | +} | ||
116 | + | ||
117 | void iothread_stop(IOThread *iothread) | ||
118 | { | ||
119 | if (!iothread->ctx || iothread->stopping) { | ||
120 | return; | ||
121 | } | ||
122 | iothread->stopping = true; | ||
123 | - aio_notify(iothread->ctx); | ||
124 | - if (atomic_read(&iothread->main_loop)) { | ||
125 | - g_main_loop_quit(iothread->main_loop); | ||
126 | - } | ||
127 | + aio_bh_schedule_oneshot(iothread->ctx, iothread_stop_bh, iothread); | ||
128 | qemu_thread_join(&iothread->thread); | ||
129 | } | ||
130 | |||
131 | @@ -XXX,XX +XXX,XX @@ static void iothread_complete(UserCreatable *obj, Error **errp) | ||
132 | char *name, *thread_name; | ||
133 | |||
134 | iothread->stopping = false; | ||
135 | + iothread->running = true; | ||
136 | iothread->thread_id = -1; | ||
137 | iothread->ctx = aio_context_new(&local_error); | ||
138 | if (!iothread->ctx) { | ||
28 | -- | 139 | -- |
29 | 2.23.0 | 140 | 2.14.3 |
30 | 141 | ||
31 | 142 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | This test case will prevent future regressions with savevm and |
---|---|---|---|
2 | IOThreads. | ||
2 | 3 | ||
3 | This probably never caused problems because on Linux there's no | 4 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
4 | actual newline conversion happening, but on Python 3 the | 5 | Reviewed-by: Eric Blake <eblake@redhat.com> |
5 | binary/text distinction is stronger and we must explicitly open | 6 | Message-id: 20171207201320.19284-7-stefanha@redhat.com |
6 | the image file in binary mode. | ||
7 | |||
8 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
9 | Reviewed-by: John Snow <jsnow@redhat.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20191016192430.25098-2-ehabkost@redhat.com | ||
12 | Message-Id: <20191016192430.25098-2-ehabkost@redhat.com> | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
14 | --- | 8 | --- |
15 | tests/image-fuzzer/qcow2/layout.py | 2 +- | 9 | tests/qemu-iotests/203 | 59 ++++++++++++++++++++++++++++++++++++++++++++++ |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 10 | tests/qemu-iotests/203.out | 6 +++++ |
11 | tests/qemu-iotests/group | 1 + | ||
12 | 3 files changed, 66 insertions(+) | ||
13 | create mode 100755 tests/qemu-iotests/203 | ||
14 | create mode 100644 tests/qemu-iotests/203.out | ||
17 | 15 | ||
18 | diff --git a/tests/image-fuzzer/qcow2/layout.py b/tests/image-fuzzer/qcow2/layout.py | 16 | diff --git a/tests/qemu-iotests/203 b/tests/qemu-iotests/203 |
17 | new file mode 100755 | ||
18 | index XXXXXXX..XXXXXXX | ||
19 | --- /dev/null | ||
20 | +++ b/tests/qemu-iotests/203 | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | +#!/usr/bin/env python | ||
23 | +# | ||
24 | +# Copyright (C) 2017 Red Hat, Inc. | ||
25 | +# | ||
26 | +# This program is free software; you can redistribute it and/or modify | ||
27 | +# it under the terms of the GNU General Public License as published by | ||
28 | +# the Free Software Foundation; either version 2 of the License, or | ||
29 | +# (at your option) any later version. | ||
30 | +# | ||
31 | +# This program is distributed in the hope that it will be useful, | ||
32 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
33 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
34 | +# GNU General Public License for more details. | ||
35 | +# | ||
36 | +# You should have received a copy of the GNU General Public License | ||
37 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
38 | +# | ||
39 | +# Creator/Owner: Stefan Hajnoczi <stefanha@redhat.com> | ||
40 | +# | ||
41 | +# Check that QMP 'migrate' with multiple drives on a single IOThread completes | ||
42 | +# successfully. This particular command triggered a hang in the source QEMU | ||
43 | +# process due to recursive AioContext locking in bdrv_invalidate_all() and | ||
44 | +# BDRV_POLL_WHILE(). | ||
45 | + | ||
46 | +import iotests | ||
47 | + | ||
48 | +iotests.verify_image_format(supported_fmts=['qcow2']) | ||
49 | +iotests.verify_platform(['linux']) | ||
50 | + | ||
51 | +with iotests.FilePath('disk0.img') as disk0_img_path, \ | ||
52 | + iotests.FilePath('disk1.img') as disk1_img_path, \ | ||
53 | + iotests.VM() as vm: | ||
54 | + | ||
55 | + img_size = '10M' | ||
56 | + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk0_img_path, img_size) | ||
57 | + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, disk1_img_path, img_size) | ||
58 | + | ||
59 | + iotests.log('Launching VM...') | ||
60 | + (vm.add_object('iothread,id=iothread0') | ||
61 | + .add_drive(disk0_img_path, 'node-name=drive0-node', interface='none') | ||
62 | + .add_drive(disk1_img_path, 'node-name=drive1-node', interface='none') | ||
63 | + .launch()) | ||
64 | + | ||
65 | + iotests.log('Setting IOThreads...') | ||
66 | + iotests.log(vm.qmp('x-blockdev-set-iothread', | ||
67 | + node_name='drive0-node', iothread='iothread0', | ||
68 | + force=True)) | ||
69 | + iotests.log(vm.qmp('x-blockdev-set-iothread', | ||
70 | + node_name='drive1-node', iothread='iothread0', | ||
71 | + force=True)) | ||
72 | + | ||
73 | + iotests.log('Starting migration...') | ||
74 | + iotests.log(vm.qmp('migrate', uri='exec:cat >/dev/null')) | ||
75 | + while True: | ||
76 | + vm.get_qmp_event(wait=60.0) | ||
77 | + result = vm.qmp('query-migrate') | ||
78 | + status = result.get('return', {}).get('status', None) | ||
79 | + if status == 'completed': | ||
80 | + break | ||
81 | diff --git a/tests/qemu-iotests/203.out b/tests/qemu-iotests/203.out | ||
82 | new file mode 100644 | ||
83 | index XXXXXXX..XXXXXXX | ||
84 | --- /dev/null | ||
85 | +++ b/tests/qemu-iotests/203.out | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | +Launching VM... | ||
88 | +Setting IOThreads... | ||
89 | +{u'return': {}} | ||
90 | +{u'return': {}} | ||
91 | +Starting migration... | ||
92 | +{u'return': {}} | ||
93 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
19 | index XXXXXXX..XXXXXXX 100644 | 94 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/tests/image-fuzzer/qcow2/layout.py | 95 | --- a/tests/qemu-iotests/group |
21 | +++ b/tests/image-fuzzer/qcow2/layout.py | 96 | +++ b/tests/qemu-iotests/group |
22 | @@ -XXX,XX +XXX,XX @@ class Image(object): | 97 | @@ -XXX,XX +XXX,XX @@ |
23 | 98 | 198 rw auto | |
24 | def write(self, filename): | 99 | 200 rw auto |
25 | """Write an entire image to the file.""" | 100 | 202 rw auto quick |
26 | - image_file = open(filename, 'w') | 101 | +203 rw auto |
27 | + image_file = open(filename, 'wb') | ||
28 | for field in self: | ||
29 | image_file.seek(field.offset) | ||
30 | image_file.write(struct.pack(field.fmt, field.value)) | ||
31 | -- | 102 | -- |
32 | 2.23.0 | 103 | 2.14.3 |
33 | 104 | ||
34 | 105 | diff view generated by jsdifflib |