1 | The following changes since commit f6b06fcceef465de0cf2514c9f76fe0192896781: | 1 | The following changes since commit 711c0418c8c1ce3a24346f058b001c4c5a2f0f81: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/kraxel/tags/ui-20190121-pull-request' into staging (2019-01-23 17:57:47 +0000) | 3 | Merge remote-tracking branch 'remotes/philmd/tags/mips-20210702' into staging (2021-07-04 14:04:12 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git://github.com/stefanha/qemu.git tags/block-pull-request | 7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request |
8 | 8 | ||
9 | for you to fetch changes up to 8595685986152334b1ec28c78cb0e5e855d56b54: | 9 | for you to fetch changes up to 9f460c64e13897117f35ffb61f6f5e0102cabc70: |
10 | 10 | ||
11 | qemu-coroutine-sleep: drop CoSleepCB (2019-01-24 10:05:16 +0000) | 11 | block/io: Merge discard request alignments (2021-07-06 14:28:55 +0100) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Pull request |
15 | 15 | ||
16 | Changelog: No user-visible changes. | ||
17 | |||
18 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
19 | 17 | ||
18 | Akihiko Odaki (3): | ||
19 | block/file-posix: Optimize for macOS | ||
20 | block: Add backend_defaults property | ||
21 | block/io: Merge discard request alignments | ||
22 | |||
20 | Stefan Hajnoczi (2): | 23 | Stefan Hajnoczi (2): |
21 | throttle-groups: fix restart coroutine iothread race | 24 | util/async: add a human-readable name to BHs for debugging |
22 | iotests: add 238 for throttling tgm unregister iothread segfault | 25 | util/async: print leaked BH name when AioContext finalizes |
23 | 26 | ||
24 | Vladimir Sementsov-Ogievskiy (1): | 27 | include/block/aio.h | 31 ++++++++++++++++++++++--- |
25 | qemu-coroutine-sleep: drop CoSleepCB | 28 | include/hw/block/block.h | 3 +++ |
26 | 29 | include/qemu/main-loop.h | 4 +++- | |
27 | include/block/throttle-groups.h | 5 ++++ | 30 | block/file-posix.c | 27 ++++++++++++++++++++-- |
28 | block/throttle-groups.c | 9 +++++++ | 31 | block/io.c | 2 ++ |
29 | util/qemu-coroutine-sleep.c | 27 +++++++------------ | 32 | hw/block/block.c | 42 ++++++++++++++++++++++++++++++---- |
30 | tests/qemu-iotests/238 | 47 +++++++++++++++++++++++++++++++++ | 33 | tests/unit/ptimer-test-stubs.c | 2 +- |
31 | tests/qemu-iotests/238.out | 6 +++++ | 34 | util/async.c | 25 ++++++++++++++++---- |
32 | tests/qemu-iotests/group | 1 + | 35 | util/main-loop.c | 4 ++-- |
33 | 6 files changed, 78 insertions(+), 17 deletions(-) | 36 | tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++ |
34 | create mode 100755 tests/qemu-iotests/238 | 37 | 10 files changed, 161 insertions(+), 17 deletions(-) |
35 | create mode 100644 tests/qemu-iotests/238.out | ||
36 | 38 | ||
37 | -- | 39 | -- |
38 | 2.20.1 | 40 | 2.31.1 |
39 | 41 | ||
40 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | It can be difficult to debug issues with BHs in production environments. | ||
2 | Although BHs can usually be identified by looking up their ->cb() | ||
3 | function pointer, this requires debug information for the program. It is | ||
4 | also not possible to print human-readable diagnostics about BHs because | ||
5 | they have no identifier. | ||
1 | 6 | ||
7 | This patch adds a name to each BH. The name is not unique per instance | ||
8 | but differentiates between cb() functions, which is usually enough. It's | ||
9 | done by changing aio_bh_new() and friends to macros that stringify cb. | ||
10 | |||
11 | The next patch will use the name field when reporting leaked BHs. | ||
12 | |||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
15 | Message-Id: <20210414200247.917496-2-stefanha@redhat.com> | ||
16 | --- | ||
17 | include/block/aio.h | 31 ++++++++++++++++++++++++++++--- | ||
18 | include/qemu/main-loop.h | 4 +++- | ||
19 | tests/unit/ptimer-test-stubs.c | 2 +- | ||
20 | util/async.c | 9 +++++++-- | ||
21 | util/main-loop.c | 4 ++-- | ||
22 | 5 files changed, 41 insertions(+), 9 deletions(-) | ||
23 | |||
24 | diff --git a/include/block/aio.h b/include/block/aio.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/block/aio.h | ||
27 | +++ b/include/block/aio.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void aio_context_acquire(AioContext *ctx); | ||
29 | /* Relinquish ownership of the AioContext. */ | ||
30 | void aio_context_release(AioContext *ctx); | ||
31 | |||
32 | +/** | ||
33 | + * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that will | ||
34 | + * run only once and as soon as possible. | ||
35 | + * | ||
36 | + * @name: A human-readable identifier for debugging purposes. | ||
37 | + */ | ||
38 | +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
39 | + const char *name); | ||
40 | + | ||
41 | /** | ||
42 | * aio_bh_schedule_oneshot: Allocate a new bottom half structure that will run | ||
43 | * only once and as soon as possible. | ||
44 | + * | ||
45 | + * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb as the | ||
46 | + * name string. | ||
47 | */ | ||
48 | -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque); | ||
49 | +#define aio_bh_schedule_oneshot(ctx, cb, opaque) \ | ||
50 | + aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb))) | ||
51 | |||
52 | /** | ||
53 | - * aio_bh_new: Allocate a new bottom half structure. | ||
54 | + * aio_bh_new_full: Allocate a new bottom half structure. | ||
55 | * | ||
56 | * Bottom halves are lightweight callbacks whose invocation is guaranteed | ||
57 | * to be wait-free, thread-safe and signal-safe. The #QEMUBH structure | ||
58 | * is opaque and must be allocated prior to its use. | ||
59 | + * | ||
60 | + * @name: A human-readable identifier for debugging purposes. | ||
61 | */ | ||
62 | -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque); | ||
63 | +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
64 | + const char *name); | ||
65 | + | ||
66 | +/** | ||
67 | + * aio_bh_new: Allocate a new bottom half structure | ||
68 | + * | ||
69 | + * A convenience wrapper for aio_bh_new_full() that uses the cb as the name | ||
70 | + * string. | ||
71 | + */ | ||
72 | +#define aio_bh_new(ctx, cb, opaque) \ | ||
73 | + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb))) | ||
74 | |||
75 | /** | ||
76 | * aio_notify: Force processing of pending events. | ||
77 | diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/include/qemu/main-loop.h | ||
80 | +++ b/include/qemu/main-loop.h | ||
81 | @@ -XXX,XX +XXX,XX @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int ms); | ||
82 | |||
83 | void qemu_fd_register(int fd); | ||
84 | |||
85 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); | ||
86 | +#define qemu_bh_new(cb, opaque) \ | ||
87 | + qemu_bh_new_full((cb), (opaque), (stringify(cb))) | ||
88 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name); | ||
89 | void qemu_bh_schedule_idle(QEMUBH *bh); | ||
90 | |||
91 | enum { | ||
92 | diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/tests/unit/ptimer-test-stubs.c | ||
95 | +++ b/tests/unit/ptimer-test-stubs.c | ||
96 | @@ -XXX,XX +XXX,XX @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask) | ||
97 | return deadline; | ||
98 | } | ||
99 | |||
100 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | ||
101 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) | ||
102 | { | ||
103 | QEMUBH *bh = g_new(QEMUBH, 1); | ||
104 | |||
105 | diff --git a/util/async.c b/util/async.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/util/async.c | ||
108 | +++ b/util/async.c | ||
109 | @@ -XXX,XX +XXX,XX @@ enum { | ||
110 | |||
111 | struct QEMUBH { | ||
112 | AioContext *ctx; | ||
113 | + const char *name; | ||
114 | QEMUBHFunc *cb; | ||
115 | void *opaque; | ||
116 | QSLIST_ENTRY(QEMUBH) next; | ||
117 | @@ -XXX,XX +XXX,XX @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *flags) | ||
118 | return bh; | ||
119 | } | ||
120 | |||
121 | -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
122 | +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, | ||
123 | + void *opaque, const char *name) | ||
124 | { | ||
125 | QEMUBH *bh; | ||
126 | bh = g_new(QEMUBH, 1); | ||
127 | @@ -XXX,XX +XXX,XX @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
128 | .ctx = ctx, | ||
129 | .cb = cb, | ||
130 | .opaque = opaque, | ||
131 | + .name = name, | ||
132 | }; | ||
133 | aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT); | ||
134 | } | ||
135 | |||
136 | -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
137 | +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, | ||
138 | + const char *name) | ||
139 | { | ||
140 | QEMUBH *bh; | ||
141 | bh = g_new(QEMUBH, 1); | ||
142 | @@ -XXX,XX +XXX,XX @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) | ||
143 | .ctx = ctx, | ||
144 | .cb = cb, | ||
145 | .opaque = opaque, | ||
146 | + .name = name, | ||
147 | }; | ||
148 | return bh; | ||
149 | } | ||
150 | diff --git a/util/main-loop.c b/util/main-loop.c | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/util/main-loop.c | ||
153 | +++ b/util/main-loop.c | ||
154 | @@ -XXX,XX +XXX,XX @@ void main_loop_wait(int nonblocking) | ||
155 | |||
156 | /* Functions to operate on the main QEMU AioContext. */ | ||
157 | |||
158 | -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) | ||
159 | +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) | ||
160 | { | ||
161 | - return aio_bh_new(qemu_aio_context, cb, opaque); | ||
162 | + return aio_bh_new_full(qemu_aio_context, cb, opaque, name); | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | -- | ||
167 | 2.31.1 | ||
168 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | BHs must be deleted before the AioContext is finalized. If not, it's a | ||
2 | bug and probably indicates that some part of the program still expects | ||
3 | the BH to run in the future. That can lead to memory leaks, inconsistent | ||
4 | state, or just hangs. | ||
1 | 5 | ||
6 | Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize() | ||
7 | is difficult to debug because the assertion failure contains no | ||
8 | information about the BH! | ||
9 | |||
10 | Use the QEMUBH name field added in the previous patch to show a useful | ||
11 | error when a leaked BH is detected. | ||
12 | |||
13 | Suggested-by: Eric Ernst <eric.g.ernst@gmail.com> | ||
14 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
15 | Message-Id: <20210414200247.917496-3-stefanha@redhat.com> | ||
16 | --- | ||
17 | util/async.c | 16 ++++++++++++++-- | ||
18 | 1 file changed, 14 insertions(+), 2 deletions(-) | ||
19 | |||
20 | diff --git a/util/async.c b/util/async.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/util/async.c | ||
23 | +++ b/util/async.c | ||
24 | @@ -XXX,XX +XXX,XX @@ aio_ctx_finalize(GSource *source) | ||
25 | assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list)); | ||
26 | |||
27 | while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) { | ||
28 | - /* qemu_bh_delete() must have been called on BHs in this AioContext */ | ||
29 | - assert(flags & BH_DELETED); | ||
30 | + /* | ||
31 | + * qemu_bh_delete() must have been called on BHs in this AioContext. In | ||
32 | + * many cases memory leaks, hangs, or inconsistent state occur when a | ||
33 | + * BH is leaked because something still expects it to run. | ||
34 | + * | ||
35 | + * If you hit this, fix the lifecycle of the BH so that | ||
36 | + * qemu_bh_delete() and any associated cleanup is called before the | ||
37 | + * AioContext is finalized. | ||
38 | + */ | ||
39 | + if (unlikely(!(flags & BH_DELETED))) { | ||
40 | + fprintf(stderr, "%s: BH '%s' leaked, aborting...\n", | ||
41 | + __func__, bh->name); | ||
42 | + abort(); | ||
43 | + } | ||
44 | |||
45 | g_free(bh); | ||
46 | } | ||
47 | -- | ||
48 | 2.31.1 | ||
49 | diff view generated by jsdifflib |
1 | The following QMP command leads to a crash when iothreads are used: | 1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | { 'execute': 'device_del', 'arguments': {'id': 'data'} } | 3 | This commit introduces "punch hole" operation and optimizes transfer |
4 | block size for macOS. | ||
4 | 5 | ||
5 | The backtrace involves the queue restart coroutine where | 6 | Thanks to Konstantin Nazarov for detailed analysis of a flaw in an |
6 | tgm->throttle_state is a NULL pointer because | 7 | old version of this change: |
7 | throttle_group_unregister_tgm() has already been called: | 8 | https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistcomment-3654667 |
8 | 9 | ||
9 | (gdb) bt full | 10 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> |
10 | #0 0x00005585a7a3b378 in qemu_mutex_lock_impl (mutex=0xffffffffffffffd0, file=0x5585a7bb3d54 "block/throttle-groups.c", line=412) at util/qemu-thread-posix.c:64 | 11 | Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com |
11 | err = <optimized out> | ||
12 | __PRETTY_FUNCTION__ = "qemu_mutex_lock_impl" | ||
13 | __func__ = "qemu_mutex_lock_impl" | ||
14 | #1 0x00005585a79be074 in throttle_group_restart_queue_entry (opaque=0x5585a9de4eb0) at block/throttle-groups.c:412 | ||
15 | _f = <optimized out> | ||
16 | data = 0x5585a9de4eb0 | ||
17 | tgm = 0x5585a9079440 | ||
18 | ts = 0x0 | ||
19 | tg = 0xffffffffffffff98 | ||
20 | is_write = false | ||
21 | empty_queue = 255 | ||
22 | |||
23 | This coroutine should not execute in the iothread after the throttle | ||
24 | group member has been unregistered! | ||
25 | |||
26 | The root cause is that the device_del code path schedules the restart | ||
27 | coroutine in the iothread while holding the AioContext lock. Therefore | ||
28 | the iothread cannot execute the coroutine until after device_del | ||
29 | releases the lock - by this time it's too late. | ||
30 | |||
31 | This patch adds a reference count to ThrottleGroupMember so we can | ||
32 | synchronously wait for restart coroutines to complete. Once they are | ||
33 | done it is safe to unregister the ThrottleGroupMember. | ||
34 | |||
35 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
36 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
37 | Message-id: 20190114133257.30299-2-stefanha@redhat.com | ||
38 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 12 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
39 | --- | 13 | --- |
40 | include/block/throttle-groups.h | 5 +++++ | 14 | block/file-posix.c | 27 +++++++++++++++++++++++++-- |
41 | block/throttle-groups.c | 9 +++++++++ | 15 | 1 file changed, 25 insertions(+), 2 deletions(-) |
42 | 2 files changed, 14 insertions(+) | ||
43 | 16 | ||
44 | diff --git a/include/block/throttle-groups.h b/include/block/throttle-groups.h | 17 | diff --git a/block/file-posix.c b/block/file-posix.c |
45 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/include/block/throttle-groups.h | 19 | --- a/block/file-posix.c |
47 | +++ b/include/block/throttle-groups.h | 20 | +++ b/block/file-posix.c |
48 | @@ -XXX,XX +XXX,XX @@ typedef struct ThrottleGroupMember { | 21 | @@ -XXX,XX +XXX,XX @@ |
49 | */ | 22 | #if defined(HAVE_HOST_BLOCK_DEVICE) |
50 | unsigned int io_limits_disabled; | 23 | #include <paths.h> |
51 | 24 | #include <sys/param.h> | |
52 | + /* Number of pending throttle_group_restart_queue_entry() coroutines. | 25 | +#include <sys/mount.h> |
53 | + * Accessed with atomic operations. | 26 | #include <IOKit/IOKitLib.h> |
54 | + */ | 27 | #include <IOKit/IOBSD.h> |
55 | + unsigned int restart_pending; | 28 | #include <IOKit/storage/IOMediaBSDClient.h> |
56 | + | 29 | @@ -XXX,XX +XXX,XX @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) |
57 | /* The following fields are protected by the ThrottleGroup lock. | ||
58 | * See the ThrottleGroup documentation for details. | ||
59 | * throttle_state tells us if I/O limits are configured. */ | ||
60 | diff --git a/block/throttle-groups.c b/block/throttle-groups.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/block/throttle-groups.c | ||
63 | +++ b/block/throttle-groups.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) | ||
65 | } | ||
66 | |||
67 | g_free(data); | ||
68 | + | ||
69 | + atomic_dec(&tgm->restart_pending); | ||
70 | + aio_wait_kick(); | ||
71 | } | ||
72 | |||
73 | static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write) | ||
74 | @@ -XXX,XX +XXX,XX @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write | ||
75 | * be no timer pending on this tgm at this point */ | ||
76 | assert(!timer_pending(tgm->throttle_timers.timers[is_write])); | ||
77 | |||
78 | + atomic_inc(&tgm->restart_pending); | ||
79 | + | ||
80 | co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd); | ||
81 | aio_co_enter(tgm->aio_context, co); | ||
82 | } | ||
83 | @@ -XXX,XX +XXX,XX @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm, | ||
84 | |||
85 | tgm->throttle_state = ts; | ||
86 | tgm->aio_context = ctx; | ||
87 | + atomic_set(&tgm->restart_pending, 0); | ||
88 | |||
89 | qemu_mutex_lock(&tg->lock); | ||
90 | /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */ | ||
91 | @@ -XXX,XX +XXX,XX @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) | ||
92 | return; | 30 | return; |
93 | } | 31 | } |
94 | 32 | ||
95 | + /* Wait for throttle_group_restart_queue_entry() coroutines to finish */ | 33 | +#if defined(__APPLE__) && (__MACH__) |
96 | + AIO_WAIT_WHILE(tgm->aio_context, atomic_read(&tgm->restart_pending) > 0); | 34 | + struct statfs buf; |
97 | + | 35 | + |
98 | qemu_mutex_lock(&tg->lock); | 36 | + if (!fstatfs(s->fd, &buf)) { |
99 | for (i = 0; i < 2; i++) { | 37 | + bs->bl.opt_transfer = buf.f_iosize; |
100 | assert(tgm->pending_reqs[i] == 0); | 38 | + bs->bl.pdiscard_alignment = buf.f_bsize; |
39 | + } | ||
40 | +#endif | ||
41 | + | ||
42 | if (bs->sg || S_ISBLK(st.st_mode)) { | ||
43 | int ret = hdev_get_max_hw_transfer(s->fd, &st); | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ out: | ||
46 | } | ||
47 | } | ||
48 | |||
49 | +#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD) | ||
50 | static int translate_err(int err) | ||
51 | { | ||
52 | if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP || | ||
53 | @@ -XXX,XX +XXX,XX @@ static int translate_err(int err) | ||
54 | } | ||
55 | return err; | ||
56 | } | ||
57 | +#endif | ||
58 | |||
59 | #ifdef CONFIG_FALLOCATE | ||
60 | static int do_fallocate(int fd, int mode, off_t offset, off_t len) | ||
61 | @@ -XXX,XX +XXX,XX @@ static int handle_aiocb_discard(void *opaque) | ||
62 | } | ||
63 | } while (errno == EINTR); | ||
64 | |||
65 | - ret = -errno; | ||
66 | + ret = translate_err(-errno); | ||
67 | #endif | ||
68 | } else { | ||
69 | #ifdef CONFIG_FALLOCATE_PUNCH_HOLE | ||
70 | ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, | ||
71 | aiocb->aio_offset, aiocb->aio_nbytes); | ||
72 | + ret = translate_err(-errno); | ||
73 | +#elif defined(__APPLE__) && (__MACH__) | ||
74 | + fpunchhole_t fpunchhole; | ||
75 | + fpunchhole.fp_flags = 0; | ||
76 | + fpunchhole.reserved = 0; | ||
77 | + fpunchhole.fp_offset = aiocb->aio_offset; | ||
78 | + fpunchhole.fp_length = aiocb->aio_nbytes; | ||
79 | + if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) == -1) { | ||
80 | + ret = errno == ENODEV ? -ENOTSUP : -errno; | ||
81 | + } else { | ||
82 | + ret = 0; | ||
83 | + } | ||
84 | #endif | ||
85 | } | ||
86 | |||
87 | - ret = translate_err(ret); | ||
88 | if (ret == -ENOTSUP) { | ||
89 | s->has_discard = false; | ||
90 | } | ||
101 | -- | 91 | -- |
102 | 2.20.1 | 92 | 2.31.1 |
103 | 93 | ||
104 | diff view generated by jsdifflib |
1 | From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Drop CoSleepCB structure. It's actually unused. | 3 | backend_defaults property allow users to control if default block |
4 | 4 | properties should be decided with backend information. | |
5 | Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 5 | |
6 | Message-id: 20190122143113.20331-1-vsementsov@virtuozzo.com | 6 | If it is off, any backend information will be discarded, which is |
7 | suitable if you plan to perform live migration to a different disk backend. | ||
8 | |||
9 | If it is on, a block device may utilize backend information more | ||
10 | aggressively. | ||
11 | |||
12 | By default, it is auto, which uses backend information for block | ||
13 | sizes and ignores the others, which is consistent with the older | ||
14 | versions. | ||
15 | |||
16 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> | ||
17 | Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com | ||
7 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 18 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
8 | --- | 19 | --- |
9 | util/qemu-coroutine-sleep.c | 27 ++++++++++----------------- | 20 | include/hw/block/block.h | 3 +++ |
10 | 1 file changed, 10 insertions(+), 17 deletions(-) | 21 | hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++---- |
11 | 22 | tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++ | |
12 | diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c | 23 | 3 files changed, 79 insertions(+), 4 deletions(-) |
24 | |||
25 | diff --git a/include/hw/block/block.h b/include/hw/block/block.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/util/qemu-coroutine-sleep.c | 27 | --- a/include/hw/block/block.h |
15 | +++ b/util/qemu-coroutine-sleep.c | 28 | +++ b/include/hw/block/block.h |
16 | @@ -XXX,XX +XXX,XX @@ | 29 | @@ -XXX,XX +XXX,XX @@ |
17 | #include "qemu/timer.h" | 30 | |
18 | #include "block/aio.h" | 31 | typedef struct BlockConf { |
19 | 32 | BlockBackend *blk; | |
20 | -typedef struct CoSleepCB { | 33 | + OnOffAuto backend_defaults; |
21 | - QEMUTimer *ts; | 34 | uint32_t physical_block_size; |
22 | - Coroutine *co; | 35 | uint32_t logical_block_size; |
23 | -} CoSleepCB; | 36 | uint32_t min_io_size; |
24 | - | 37 | @@ -XXX,XX +XXX,XX @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) |
25 | static void co_sleep_cb(void *opaque) | 38 | } |
39 | |||
40 | #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \ | ||
41 | + DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \ | ||
42 | + _conf.backend_defaults, ON_OFF_AUTO_AUTO), \ | ||
43 | DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ | ||
44 | _conf.logical_block_size), \ | ||
45 | DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ | ||
46 | diff --git a/hw/block/block.c b/hw/block/block.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/hw/block/block.c | ||
49 | +++ b/hw/block/block.c | ||
50 | @@ -XXX,XX +XXX,XX @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp) | ||
26 | { | 51 | { |
27 | - CoSleepCB *sleep_cb = opaque; | 52 | BlockBackend *blk = conf->blk; |
28 | + Coroutine *co = opaque; | 53 | BlockSizes blocksizes; |
29 | 54 | - int backend_ret; | |
30 | /* Write of schedule protected by barrier write in aio_co_schedule */ | 55 | + BlockDriverState *bs; |
31 | - atomic_set(&sleep_cb->co->scheduled, NULL); | 56 | + bool use_blocksizes; |
32 | - aio_co_wake(sleep_cb->co); | 57 | + bool use_bs; |
33 | + atomic_set(&co->scheduled, NULL); | 58 | + |
34 | + aio_co_wake(co); | 59 | + switch (conf->backend_defaults) { |
35 | } | 60 | + case ON_OFF_AUTO_AUTO: |
36 | 61 | + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); | |
37 | void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns) | 62 | + use_bs = false; |
38 | { | 63 | + break; |
39 | AioContext *ctx = qemu_get_current_aio_context(); | 64 | + |
40 | - CoSleepCB sleep_cb = { | 65 | + case ON_OFF_AUTO_ON: |
41 | - .co = qemu_coroutine_self(), | 66 | + use_blocksizes = !blk_probe_blocksizes(blk, &blocksizes); |
42 | - }; | 67 | + bs = blk_bs(blk); |
43 | + QEMUTimer *ts; | 68 | + use_bs = bs; |
44 | + Coroutine *co = qemu_coroutine_self(); | 69 | + break; |
45 | 70 | + | |
46 | - const char *scheduled = atomic_cmpxchg(&sleep_cb.co->scheduled, NULL, | 71 | + case ON_OFF_AUTO_OFF: |
47 | - __func__); | 72 | + use_blocksizes = false; |
48 | + const char *scheduled = atomic_cmpxchg(&co->scheduled, NULL, __func__); | 73 | + use_bs = false; |
49 | if (scheduled) { | 74 | + break; |
50 | fprintf(stderr, | 75 | + |
51 | "%s: Co-routine was already scheduled in '%s'\n", | 76 | + default: |
52 | __func__, scheduled); | 77 | + abort(); |
53 | abort(); | 78 | + } |
79 | |||
80 | - backend_ret = blk_probe_blocksizes(blk, &blocksizes); | ||
81 | /* fill in detected values if they are not defined via qemu command line */ | ||
82 | if (!conf->physical_block_size) { | ||
83 | - if (!backend_ret) { | ||
84 | + if (use_blocksizes) { | ||
85 | conf->physical_block_size = blocksizes.phys; | ||
86 | } else { | ||
87 | conf->physical_block_size = BDRV_SECTOR_SIZE; | ||
88 | } | ||
54 | } | 89 | } |
55 | - sleep_cb.ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &sleep_cb); | 90 | if (!conf->logical_block_size) { |
56 | - timer_mod(sleep_cb.ts, qemu_clock_get_ns(type) + ns); | 91 | - if (!backend_ret) { |
57 | + ts = aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, co); | 92 | + if (use_blocksizes) { |
58 | + timer_mod(ts, qemu_clock_get_ns(type) + ns); | 93 | conf->logical_block_size = blocksizes.log; |
59 | qemu_coroutine_yield(); | 94 | } else { |
60 | - timer_del(sleep_cb.ts); | 95 | conf->logical_block_size = BDRV_SECTOR_SIZE; |
61 | - timer_free(sleep_cb.ts); | 96 | } |
62 | + timer_del(ts); | 97 | } |
63 | + timer_free(ts); | 98 | + if (use_bs) { |
64 | } | 99 | + if (!conf->opt_io_size) { |
100 | + conf->opt_io_size = bs->bl.opt_transfer; | ||
101 | + } | ||
102 | + if (conf->discard_granularity == -1) { | ||
103 | + if (bs->bl.pdiscard_alignment) { | ||
104 | + conf->discard_granularity = bs->bl.pdiscard_alignment; | ||
105 | + } else if (bs->bl.request_alignment != 1) { | ||
106 | + conf->discard_granularity = bs->bl.request_alignment; | ||
107 | + } | ||
108 | + } | ||
109 | + } | ||
110 | |||
111 | if (conf->logical_block_size > conf->physical_block_size) { | ||
112 | error_setg(errp, | ||
113 | diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/tests/qemu-iotests/172.out | ||
116 | +++ b/tests/qemu-iotests/172.out | ||
117 | @@ -XXX,XX +XXX,XX @@ Testing: | ||
118 | dev: floppy, id "" | ||
119 | unit = 0 (0x0) | ||
120 | drive = "floppy0" | ||
121 | + backend_defaults = "auto" | ||
122 | logical_block_size = 512 (512 B) | ||
123 | physical_block_size = 512 (512 B) | ||
124 | min_io_size = 0 (0 B) | ||
125 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 | ||
126 | dev: floppy, id "" | ||
127 | unit = 0 (0x0) | ||
128 | drive = "floppy0" | ||
129 | + backend_defaults = "auto" | ||
130 | logical_block_size = 512 (512 B) | ||
131 | physical_block_size = 512 (512 B) | ||
132 | min_io_size = 0 (0 B) | ||
133 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 | ||
134 | dev: floppy, id "" | ||
135 | unit = 1 (0x1) | ||
136 | drive = "floppy1" | ||
137 | + backend_defaults = "auto" | ||
138 | logical_block_size = 512 (512 B) | ||
139 | physical_block_size = 512 (512 B) | ||
140 | min_io_size = 0 (0 B) | ||
141 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 | ||
142 | dev: floppy, id "" | ||
143 | unit = 0 (0x0) | ||
144 | drive = "floppy0" | ||
145 | + backend_defaults = "auto" | ||
146 | logical_block_size = 512 (512 B) | ||
147 | physical_block_size = 512 (512 B) | ||
148 | min_io_size = 0 (0 B) | ||
149 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 | ||
150 | dev: floppy, id "" | ||
151 | unit = 1 (0x1) | ||
152 | drive = "floppy1" | ||
153 | + backend_defaults = "auto" | ||
154 | logical_block_size = 512 (512 B) | ||
155 | physical_block_size = 512 (512 B) | ||
156 | min_io_size = 0 (0 B) | ||
157 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 | ||
158 | dev: floppy, id "" | ||
159 | unit = 0 (0x0) | ||
160 | drive = "floppy0" | ||
161 | + backend_defaults = "auto" | ||
162 | logical_block_size = 512 (512 B) | ||
163 | physical_block_size = 512 (512 B) | ||
164 | min_io_size = 0 (0 B) | ||
165 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb | ||
166 | dev: floppy, id "" | ||
167 | unit = 1 (0x1) | ||
168 | drive = "floppy1" | ||
169 | + backend_defaults = "auto" | ||
170 | logical_block_size = 512 (512 B) | ||
171 | physical_block_size = 512 (512 B) | ||
172 | min_io_size = 0 (0 B) | ||
173 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb | ||
174 | dev: floppy, id "" | ||
175 | unit = 0 (0x0) | ||
176 | drive = "floppy0" | ||
177 | + backend_defaults = "auto" | ||
178 | logical_block_size = 512 (512 B) | ||
179 | physical_block_size = 512 (512 B) | ||
180 | min_io_size = 0 (0 B) | ||
181 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 | ||
182 | dev: floppy, id "" | ||
183 | unit = 0 (0x0) | ||
184 | drive = "floppy0" | ||
185 | + backend_defaults = "auto" | ||
186 | logical_block_size = 512 (512 B) | ||
187 | physical_block_size = 512 (512 B) | ||
188 | min_io_size = 0 (0 B) | ||
189 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 | ||
190 | dev: floppy, id "" | ||
191 | unit = 1 (0x1) | ||
192 | drive = "floppy1" | ||
193 | + backend_defaults = "auto" | ||
194 | logical_block_size = 512 (512 B) | ||
195 | physical_block_size = 512 (512 B) | ||
196 | min_io_size = 0 (0 B) | ||
197 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2,index=1 | ||
198 | dev: floppy, id "" | ||
199 | unit = 0 (0x0) | ||
200 | drive = "floppy0" | ||
201 | + backend_defaults = "auto" | ||
202 | logical_block_size = 512 (512 B) | ||
203 | physical_block_size = 512 (512 B) | ||
204 | min_io_size = 0 (0 B) | ||
205 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t | ||
206 | dev: floppy, id "" | ||
207 | unit = 1 (0x1) | ||
208 | drive = "floppy1" | ||
209 | + backend_defaults = "auto" | ||
210 | logical_block_size = 512 (512 B) | ||
211 | physical_block_size = 512 (512 B) | ||
212 | min_io_size = 0 (0 B) | ||
213 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=floppy,file=TEST_DIR/t | ||
214 | dev: floppy, id "" | ||
215 | unit = 0 (0x0) | ||
216 | drive = "floppy0" | ||
217 | + backend_defaults = "auto" | ||
218 | logical_block_size = 512 (512 B) | ||
219 | physical_block_size = 512 (512 B) | ||
220 | min_io_size = 0 (0 B) | ||
221 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0 | ||
222 | dev: floppy, id "" | ||
223 | unit = 0 (0x0) | ||
224 | drive = "none0" | ||
225 | + backend_defaults = "auto" | ||
226 | logical_block_size = 512 (512 B) | ||
227 | physical_block_size = 512 (512 B) | ||
228 | min_io_size = 0 (0 B) | ||
229 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,unit=1 | ||
230 | dev: floppy, id "" | ||
231 | unit = 1 (0x1) | ||
232 | drive = "none0" | ||
233 | + backend_defaults = "auto" | ||
234 | logical_block_size = 512 (512 B) | ||
235 | physical_block_size = 512 (512 B) | ||
236 | min_io_size = 0 (0 B) | ||
237 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco | ||
238 | dev: floppy, id "" | ||
239 | unit = 1 (0x1) | ||
240 | drive = "none1" | ||
241 | + backend_defaults = "auto" | ||
242 | logical_block_size = 512 (512 B) | ||
243 | physical_block_size = 512 (512 B) | ||
244 | min_io_size = 0 (0 B) | ||
245 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qco | ||
246 | dev: floppy, id "" | ||
247 | unit = 0 (0x0) | ||
248 | drive = "none0" | ||
249 | + backend_defaults = "auto" | ||
250 | logical_block_size = 512 (512 B) | ||
251 | physical_block_size = 512 (512 B) | ||
252 | min_io_size = 0 (0 B) | ||
253 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
254 | dev: floppy, id "" | ||
255 | unit = 1 (0x1) | ||
256 | drive = "none0" | ||
257 | + backend_defaults = "auto" | ||
258 | logical_block_size = 512 (512 B) | ||
259 | physical_block_size = 512 (512 B) | ||
260 | min_io_size = 0 (0 B) | ||
261 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
262 | dev: floppy, id "" | ||
263 | unit = 0 (0x0) | ||
264 | drive = "floppy0" | ||
265 | + backend_defaults = "auto" | ||
266 | logical_block_size = 512 (512 B) | ||
267 | physical_block_size = 512 (512 B) | ||
268 | min_io_size = 0 (0 B) | ||
269 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
270 | dev: floppy, id "" | ||
271 | unit = 1 (0x1) | ||
272 | drive = "none0" | ||
273 | + backend_defaults = "auto" | ||
274 | logical_block_size = 512 (512 B) | ||
275 | physical_block_size = 512 (512 B) | ||
276 | min_io_size = 0 (0 B) | ||
277 | @@ -XXX,XX +XXX,XX @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
278 | dev: floppy, id "" | ||
279 | unit = 0 (0x0) | ||
280 | drive = "floppy0" | ||
281 | + backend_defaults = "auto" | ||
282 | logical_block_size = 512 (512 B) | ||
283 | physical_block_size = 512 (512 B) | ||
284 | min_io_size = 0 (0 B) | ||
285 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
286 | dev: floppy, id "" | ||
287 | unit = 0 (0x0) | ||
288 | drive = "none0" | ||
289 | + backend_defaults = "auto" | ||
290 | logical_block_size = 512 (512 B) | ||
291 | physical_block_size = 512 (512 B) | ||
292 | min_io_size = 0 (0 B) | ||
293 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
294 | dev: floppy, id "" | ||
295 | unit = 1 (0x1) | ||
296 | drive = "floppy1" | ||
297 | + backend_defaults = "auto" | ||
298 | logical_block_size = 512 (512 B) | ||
299 | physical_block_size = 512 (512 B) | ||
300 | min_io_size = 0 (0 B) | ||
301 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
302 | dev: floppy, id "" | ||
303 | unit = 0 (0x0) | ||
304 | drive = "none0" | ||
305 | + backend_defaults = "auto" | ||
306 | logical_block_size = 512 (512 B) | ||
307 | physical_block_size = 512 (512 B) | ||
308 | min_io_size = 0 (0 B) | ||
309 | @@ -XXX,XX +XXX,XX @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.qcow2.2 -device fl | ||
310 | dev: floppy, id "" | ||
311 | unit = 1 (0x1) | ||
312 | drive = "floppy1" | ||
313 | + backend_defaults = "auto" | ||
314 | logical_block_size = 512 (512 B) | ||
315 | physical_block_size = 512 (512 B) | ||
316 | min_io_size = 0 (0 B) | ||
317 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
318 | dev: floppy, id "" | ||
319 | unit = 1 (0x1) | ||
320 | drive = "none0" | ||
321 | + backend_defaults = "auto" | ||
322 | logical_block_size = 512 (512 B) | ||
323 | physical_block_size = 512 (512 B) | ||
324 | min_io_size = 0 (0 B) | ||
325 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
326 | dev: floppy, id "" | ||
327 | unit = 0 (0x0) | ||
328 | drive = "floppy0" | ||
329 | + backend_defaults = "auto" | ||
330 | logical_block_size = 512 (512 B) | ||
331 | physical_block_size = 512 (512 B) | ||
332 | min_io_size = 0 (0 B) | ||
333 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
334 | dev: floppy, id "" | ||
335 | unit = 1 (0x1) | ||
336 | drive = "none0" | ||
337 | + backend_defaults = "auto" | ||
338 | logical_block_size = 512 (512 B) | ||
339 | physical_block_size = 512 (512 B) | ||
340 | min_io_size = 0 (0 B) | ||
341 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=floppy,file=TEST_DIR/t.qcow2 -drive if=none,file=TEST_DIR/t.q | ||
342 | dev: floppy, id "" | ||
343 | unit = 0 (0x0) | ||
344 | drive = "floppy0" | ||
345 | + backend_defaults = "auto" | ||
346 | logical_block_size = 512 (512 B) | ||
347 | physical_block_size = 512 (512 B) | ||
348 | min_io_size = 0 (0 B) | ||
349 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -global floppy.drive=none0 -device | ||
350 | dev: floppy, id "" | ||
351 | unit = 0 (0x0) | ||
352 | drive = "none0" | ||
353 | + backend_defaults = "auto" | ||
354 | logical_block_size = 512 (512 B) | ||
355 | physical_block_size = 512 (512 B) | ||
356 | min_io_size = 0 (0 B) | ||
357 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy | ||
358 | dev: floppy, id "" | ||
359 | unit = 0 (0x0) | ||
360 | drive = "" | ||
361 | + backend_defaults = "auto" | ||
362 | logical_block_size = 512 (512 B) | ||
363 | physical_block_size = 512 (512 B) | ||
364 | min_io_size = 0 (0 B) | ||
365 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=120 | ||
366 | dev: floppy, id "" | ||
367 | unit = 0 (0x0) | ||
368 | drive = "" | ||
369 | + backend_defaults = "auto" | ||
370 | logical_block_size = 512 (512 B) | ||
371 | physical_block_size = 512 (512 B) | ||
372 | min_io_size = 0 (0 B) | ||
373 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=144 | ||
374 | dev: floppy, id "" | ||
375 | unit = 0 (0x0) | ||
376 | drive = "" | ||
377 | + backend_defaults = "auto" | ||
378 | logical_block_size = 512 (512 B) | ||
379 | physical_block_size = 512 (512 B) | ||
380 | min_io_size = 0 (0 B) | ||
381 | @@ -XXX,XX +XXX,XX @@ Testing: -device floppy,drive-type=288 | ||
382 | dev: floppy, id "" | ||
383 | unit = 0 (0x0) | ||
384 | drive = "" | ||
385 | + backend_defaults = "auto" | ||
386 | logical_block_size = 512 (512 B) | ||
387 | physical_block_size = 512 (512 B) | ||
388 | min_io_size = 0 (0 B) | ||
389 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t | ||
390 | dev: floppy, id "" | ||
391 | unit = 0 (0x0) | ||
392 | drive = "none0" | ||
393 | + backend_defaults = "auto" | ||
394 | logical_block_size = 512 (512 B) | ||
395 | physical_block_size = 512 (512 B) | ||
396 | min_io_size = 0 (0 B) | ||
397 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,drive-t | ||
398 | dev: floppy, id "" | ||
399 | unit = 0 (0x0) | ||
400 | drive = "none0" | ||
401 | + backend_defaults = "auto" | ||
402 | logical_block_size = 512 (512 B) | ||
403 | physical_block_size = 512 (512 B) | ||
404 | min_io_size = 0 (0 B) | ||
405 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,logical | ||
406 | dev: floppy, id "" | ||
407 | unit = 0 (0x0) | ||
408 | drive = "none0" | ||
409 | + backend_defaults = "auto" | ||
410 | logical_block_size = 512 (512 B) | ||
411 | physical_block_size = 512 (512 B) | ||
412 | min_io_size = 0 (0 B) | ||
413 | @@ -XXX,XX +XXX,XX @@ Testing: -drive if=none,file=TEST_DIR/t.qcow2 -device floppy,drive=none0,physica | ||
414 | dev: floppy, id "" | ||
415 | unit = 0 (0x0) | ||
416 | drive = "none0" | ||
417 | + backend_defaults = "auto" | ||
418 | logical_block_size = 512 (512 B) | ||
419 | physical_block_size = 512 (512 B) | ||
420 | min_io_size = 0 (0 B) | ||
65 | -- | 421 | -- |
66 | 2.20.1 | 422 | 2.31.1 |
67 | 423 | ||
68 | diff view generated by jsdifflib |
1 | Hot-unplug a scsi-hd using an iothread. The previous patch fixes a | 1 | From: Akihiko Odaki <akihiko.odaki@gmail.com> |
---|---|---|---|
2 | segfault in this scenario. | ||
3 | 2 | ||
4 | This patch adds a regression test. | 3 | Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com> |
5 | 4 | Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com | |
6 | Suggested-by: Alberto Garcia <berto@igalia.com> | ||
7 | Suggested-by: Kevin Wolf <kwolf@redhat.com> | ||
8 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
9 | Reviewed-by: Alberto Garcia <berto@igalia.com> | ||
10 | Message-id: 20190114133257.30299-3-stefanha@redhat.com | ||
11 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | 5 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> |
12 | --- | 6 | --- |
13 | tests/qemu-iotests/238 | 47 ++++++++++++++++++++++++++++++++++++++ | 7 | block/io.c | 2 ++ |
14 | tests/qemu-iotests/238.out | 6 +++++ | 8 | 1 file changed, 2 insertions(+) |
15 | tests/qemu-iotests/group | 1 + | ||
16 | 3 files changed, 54 insertions(+) | ||
17 | create mode 100755 tests/qemu-iotests/238 | ||
18 | create mode 100644 tests/qemu-iotests/238.out | ||
19 | 9 | ||
20 | diff --git a/tests/qemu-iotests/238 b/tests/qemu-iotests/238 | 10 | diff --git a/block/io.c b/block/io.c |
21 | new file mode 100755 | ||
22 | index XXXXXXX..XXXXXXX | ||
23 | --- /dev/null | ||
24 | +++ b/tests/qemu-iotests/238 | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | +#!/usr/bin/env python | ||
27 | +# | ||
28 | +# Regression test for throttle group member unregister segfault with iothread | ||
29 | +# | ||
30 | +# Copyright (c) 2019 Red Hat, Inc. | ||
31 | +# | ||
32 | +# This program is free software; you can redistribute it and/or modify | ||
33 | +# it under the terms of the GNU General Public License as published by | ||
34 | +# the Free Software Foundation; either version 2 of the License, or | ||
35 | +# (at your option) any later version. | ||
36 | +# | ||
37 | +# This program is distributed in the hope that it will be useful, | ||
38 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
39 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
40 | +# GNU General Public License for more details. | ||
41 | +# | ||
42 | +# You should have received a copy of the GNU General Public License | ||
43 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
44 | +# | ||
45 | + | ||
46 | +import sys | ||
47 | +import os | ||
48 | +import iotests | ||
49 | +from iotests import log | ||
50 | + | ||
51 | +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) | ||
52 | + | ||
53 | +from qemu import QEMUMachine | ||
54 | + | ||
55 | +if iotests.qemu_default_machine == 's390-ccw-virtio': | ||
56 | + virtio_scsi_device = 'virtio-scsi-ccw' | ||
57 | +else: | ||
58 | + virtio_scsi_device = 'virtio-scsi-pci' | ||
59 | + | ||
60 | +vm = QEMUMachine(iotests.qemu_prog) | ||
61 | +vm.add_args('-machine', 'accel=kvm') | ||
62 | +vm.launch() | ||
63 | + | ||
64 | +log(vm.qmp('blockdev-add', node_name='hd0', driver='null-co')) | ||
65 | +log(vm.qmp('object-add', qom_type='iothread', id='iothread0')) | ||
66 | +log(vm.qmp('device_add', id='scsi0', driver=virtio_scsi_device, iothread='iothread0')) | ||
67 | +log(vm.qmp('device_add', id='scsi-hd0', driver='scsi-hd', drive='hd0')) | ||
68 | +log(vm.qmp('block_set_io_throttle', id='scsi-hd0', bps=0, bps_rd=0, bps_wr=0, | ||
69 | + iops=1000, iops_rd=0, iops_wr=0, conv_keys=False)) | ||
70 | +log(vm.qmp('device_del', id='scsi-hd0')) | ||
71 | + | ||
72 | +vm.shutdown() | ||
73 | diff --git a/tests/qemu-iotests/238.out b/tests/qemu-iotests/238.out | ||
74 | new file mode 100644 | ||
75 | index XXXXXXX..XXXXXXX | ||
76 | --- /dev/null | ||
77 | +++ b/tests/qemu-iotests/238.out | ||
78 | @@ -XXX,XX +XXX,XX @@ | ||
79 | +{"return": {}} | ||
80 | +{"return": {}} | ||
81 | +{"return": {}} | ||
82 | +{"return": {}} | ||
83 | +{"return": {}} | ||
84 | +{"return": {}} | ||
85 | diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group | ||
86 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
87 | --- a/tests/qemu-iotests/group | 12 | --- a/block/io.c |
88 | +++ b/tests/qemu-iotests/group | 13 | +++ b/block/io.c |
89 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) |
90 | 234 auto quick migration | 15 | |
91 | 235 auto quick | 16 | static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) |
92 | 236 auto quick | 17 | { |
93 | +238 auto quick | 18 | + dst->pdiscard_alignment = MAX(dst->pdiscard_alignment, |
19 | + src->pdiscard_alignment); | ||
20 | dst->opt_transfer = MAX(dst->opt_transfer, src->opt_transfer); | ||
21 | dst->max_transfer = MIN_NON_ZERO(dst->max_transfer, src->max_transfer); | ||
22 | dst->max_hw_transfer = MIN_NON_ZERO(dst->max_hw_transfer, | ||
94 | -- | 23 | -- |
95 | 2.20.1 | 24 | 2.31.1 |
96 | 25 | ||
97 | diff view generated by jsdifflib |