1 | The following changes since commit 15ef89d2a1a7b93845a6b09c2ee8e1979f6eb30b: | 1 | The following changes since commit 19b599f7664b2ebfd0f405fb79c14dd241557452: |
---|---|---|---|
2 | 2 | ||
3 | Update version for v7.0.0-rc1 release (2022-03-22 22:58:44 +0000) | 3 | Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-08-27-v2' into staging (2018-08-27 16:44:20 +0100) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/stefanha/qemu.git tags/block-pull-request | 7 | https://git.xanclic.moe/XanClic/qemu.git tags/pull-block-2018-08-31-v2 |
8 | 8 | ||
9 | for you to fetch changes up to 2539eade4f689eda7e9fe45486f18334bfbafaf0: | 9 | for you to fetch changes up to e21a1c9831fc80ae3f3c1affdfa43350035d8588: |
10 | 10 | ||
11 | hw: Fix misleading hexadecimal format (2022-03-24 10:38:42 +0000) | 11 | jobs: remove job_defer_to_main_loop (2018-08-31 16:28:33 +0200) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Pull request | 14 | Block patches: |
15 | 15 | - (Block) job exit refactoring, part 1 | |
16 | Philippe found cases where the 0x%d format string was used, leading to | 16 | (removing job_defer_to_main_loop()) |
17 | misleading output. The patches look harmless and could save people time, so I | 17 | - test-bdrv-drain leak fix |
18 | think it's worth including them in 7.0. | ||
19 | 18 | ||
20 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
20 | John Snow (9): | ||
21 | jobs: change start callback to run callback | ||
22 | jobs: canonize Error object | ||
23 | jobs: add exit shim | ||
24 | block/commit: utilize job_exit shim | ||
25 | block/mirror: utilize job_exit shim | ||
26 | jobs: utilize job_exit shim | ||
27 | block/backup: make function variables consistently named | ||
28 | jobs: remove ret argument to job_completed; privatize it | ||
29 | jobs: remove job_defer_to_main_loop | ||
21 | 30 | ||
22 | Philippe Mathieu-Daudé (2): | 31 | Marc-André Lureau (1): |
23 | block: Fix misleading hexadecimal format | 32 | tests: fix bdrv-drain leak |
24 | hw: Fix misleading hexadecimal format | ||
25 | 33 | ||
26 | block/parallels-ext.c | 2 +- | 34 | include/qemu/job.h | 70 ++++++++++++++++----------------- |
27 | hw/i386/sgx.c | 2 +- | 35 | block/backup.c | 81 ++++++++++++++++----------------------- |
28 | hw/i386/trace-events | 6 +++--- | 36 | block/commit.c | 29 +++++--------- |
29 | hw/misc/trace-events | 4 ++-- | 37 | block/create.c | 19 +++------ |
30 | hw/scsi/trace-events | 4 ++-- | 38 | block/mirror.c | 39 ++++++++----------- |
31 | 5 files changed, 9 insertions(+), 9 deletions(-) | 39 | block/stream.c | 29 ++++++-------- |
40 | job-qmp.c | 5 ++- | ||
41 | job.c | 73 ++++++++++++----------------------- | ||
42 | tests/test-bdrv-drain.c | 14 +++---- | ||
43 | tests/test-blockjob-txn.c | 25 +++++------- | ||
44 | tests/test-blockjob.c | 17 ++++---- | ||
45 | trace-events | 2 +- | ||
46 | 12 files changed, 161 insertions(+), 242 deletions(-) | ||
32 | 47 | ||
33 | -- | 48 | -- |
34 | 2.35.1 | 49 | 2.17.1 |
35 | 50 | ||
51 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
1 | 2 | ||
3 | Spotted by ASAN: | ||
4 | |||
5 | ================================================================= | ||
6 | ==5378==ERROR: LeakSanitizer: detected memory leaks | ||
7 | |||
8 | Direct leak of 65536 byte(s) in 1 object(s) allocated from: | ||
9 | #0 0x7f788f83bc48 in malloc (/lib64/libasan.so.5+0xeec48) | ||
10 | #1 0x7f788c9923c5 in g_malloc (/lib64/libglib-2.0.so.0+0x523c5) | ||
11 | #2 0x5622a1fe37bc in coroutine_trampoline /home/elmarco/src/qq/util/coroutine-ucontext.c:116 | ||
12 | #3 0x7f788a15d75f in __correctly_grouped_prefixwc (/lib64/libc.so.6+0x4c75f) | ||
13 | |||
14 | (Broken in commit 4c8158e359d.) | ||
15 | |||
16 | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
17 | Message-id: 20180809114417.28718-3-marcandre.lureau@redhat.com | ||
18 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
19 | --- | ||
20 | tests/test-bdrv-drain.c | 1 + | ||
21 | 1 file changed, 1 insertion(+) | ||
22 | |||
23 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/tests/test-bdrv-drain.c | ||
26 | +++ b/tests/test-bdrv-drain.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn test_co_delete_by_drain(void *opaque) | ||
28 | } | ||
29 | |||
30 | dbdd->done = true; | ||
31 | + g_free(buffer); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | -- | ||
36 | 2.17.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: John Snow <jsnow@redhat.com> | |
2 | |||
3 | Presently we codify the entry point for a job as the "start" callback, | ||
4 | but a more apt name would be "run" to clarify the idea that when this | ||
5 | function returns we consider the job to have "finished," except for | ||
6 | any cleanup which occurs in separate callbacks later. | ||
7 | |||
8 | As part of this clarification, change the signature to include an error | ||
9 | object and a return code. The error ptr is not yet used, and the return | ||
10 | code while captured, will be overwritten by actions in the job_completed | ||
11 | function. | ||
12 | |||
13 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
14 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
15 | Message-id: 20180830015734.19765-2-jsnow@redhat.com | ||
16 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
17 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
18 | --- | ||
19 | include/qemu/job.h | 2 +- | ||
20 | block/backup.c | 7 ++++--- | ||
21 | block/commit.c | 7 ++++--- | ||
22 | block/create.c | 8 +++++--- | ||
23 | block/mirror.c | 10 ++++++---- | ||
24 | block/stream.c | 7 ++++--- | ||
25 | job.c | 6 +++--- | ||
26 | tests/test-bdrv-drain.c | 7 ++++--- | ||
27 | tests/test-blockjob-txn.c | 16 ++++++++-------- | ||
28 | tests/test-blockjob.c | 7 ++++--- | ||
29 | 10 files changed, 43 insertions(+), 34 deletions(-) | ||
30 | |||
31 | diff --git a/include/qemu/job.h b/include/qemu/job.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/qemu/job.h | ||
34 | +++ b/include/qemu/job.h | ||
35 | @@ -XXX,XX +XXX,XX @@ struct JobDriver { | ||
36 | JobType job_type; | ||
37 | |||
38 | /** Mandatory: Entrypoint for the Coroutine. */ | ||
39 | - CoroutineEntry *start; | ||
40 | + int coroutine_fn (*run)(Job *job, Error **errp); | ||
41 | |||
42 | /** | ||
43 | * If the callback is not NULL, it will be invoked when the job transitions | ||
44 | diff --git a/block/backup.c b/block/backup.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/block/backup.c | ||
47 | +++ b/block/backup.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job) | ||
49 | bdrv_dirty_iter_free(dbi); | ||
50 | } | ||
51 | |||
52 | -static void coroutine_fn backup_run(void *opaque) | ||
53 | +static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
54 | { | ||
55 | - BackupBlockJob *job = opaque; | ||
56 | + BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job); | ||
57 | BackupCompleteData *data; | ||
58 | BlockDriverState *bs = blk_bs(job->common.blk); | ||
59 | int64_t offset, nb_clusters; | ||
60 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn backup_run(void *opaque) | ||
61 | data = g_malloc(sizeof(*data)); | ||
62 | data->ret = ret; | ||
63 | job_defer_to_main_loop(&job->common.job, backup_complete, data); | ||
64 | + return ret; | ||
65 | } | ||
66 | |||
67 | static const BlockJobDriver backup_job_driver = { | ||
68 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver backup_job_driver = { | ||
69 | .free = block_job_free, | ||
70 | .user_resume = block_job_user_resume, | ||
71 | .drain = block_job_drain, | ||
72 | - .start = backup_run, | ||
73 | + .run = backup_run, | ||
74 | .commit = backup_commit, | ||
75 | .abort = backup_abort, | ||
76 | .clean = backup_clean, | ||
77 | diff --git a/block/commit.c b/block/commit.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/block/commit.c | ||
80 | +++ b/block/commit.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(Job *job, void *opaque) | ||
82 | bdrv_unref(top); | ||
83 | } | ||
84 | |||
85 | -static void coroutine_fn commit_run(void *opaque) | ||
86 | +static int coroutine_fn commit_run(Job *job, Error **errp) | ||
87 | { | ||
88 | - CommitBlockJob *s = opaque; | ||
89 | + CommitBlockJob *s = container_of(job, CommitBlockJob, common.job); | ||
90 | CommitCompleteData *data; | ||
91 | int64_t offset; | ||
92 | uint64_t delay_ns = 0; | ||
93 | @@ -XXX,XX +XXX,XX @@ out: | ||
94 | data = g_malloc(sizeof(*data)); | ||
95 | data->ret = ret; | ||
96 | job_defer_to_main_loop(&s->common.job, commit_complete, data); | ||
97 | + return ret; | ||
98 | } | ||
99 | |||
100 | static const BlockJobDriver commit_job_driver = { | ||
101 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver commit_job_driver = { | ||
102 | .free = block_job_free, | ||
103 | .user_resume = block_job_user_resume, | ||
104 | .drain = block_job_drain, | ||
105 | - .start = commit_run, | ||
106 | + .run = commit_run, | ||
107 | }, | ||
108 | }; | ||
109 | |||
110 | diff --git a/block/create.c b/block/create.c | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/block/create.c | ||
113 | +++ b/block/create.c | ||
114 | @@ -XXX,XX +XXX,XX @@ static void blockdev_create_complete(Job *job, void *opaque) | ||
115 | job_completed(job, s->ret, s->err); | ||
116 | } | ||
117 | |||
118 | -static void coroutine_fn blockdev_create_run(void *opaque) | ||
119 | +static int coroutine_fn blockdev_create_run(Job *job, Error **errp) | ||
120 | { | ||
121 | - BlockdevCreateJob *s = opaque; | ||
122 | + BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); | ||
123 | |||
124 | job_progress_set_remaining(&s->common, 1); | ||
125 | s->ret = s->drv->bdrv_co_create(s->opts, &s->err); | ||
126 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn blockdev_create_run(void *opaque) | ||
127 | |||
128 | qapi_free_BlockdevCreateOptions(s->opts); | ||
129 | job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL); | ||
130 | + | ||
131 | + return s->ret; | ||
132 | } | ||
133 | |||
134 | static const JobDriver blockdev_create_job_driver = { | ||
135 | .instance_size = sizeof(BlockdevCreateJob), | ||
136 | .job_type = JOB_TYPE_CREATE, | ||
137 | - .start = blockdev_create_run, | ||
138 | + .run = blockdev_create_run, | ||
139 | }; | ||
140 | |||
141 | void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options, | ||
142 | diff --git a/block/mirror.c b/block/mirror.c | ||
143 | index XXXXXXX..XXXXXXX 100644 | ||
144 | --- a/block/mirror.c | ||
145 | +++ b/block/mirror.c | ||
146 | @@ -XXX,XX +XXX,XX @@ static int mirror_flush(MirrorBlockJob *s) | ||
147 | return ret; | ||
148 | } | ||
149 | |||
150 | -static void coroutine_fn mirror_run(void *opaque) | ||
151 | +static int coroutine_fn mirror_run(Job *job, Error **errp) | ||
152 | { | ||
153 | - MirrorBlockJob *s = opaque; | ||
154 | + MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); | ||
155 | MirrorExitData *data; | ||
156 | BlockDriverState *bs = s->mirror_top_bs->backing->bs; | ||
157 | BlockDriverState *target_bs = blk_bs(s->target); | ||
158 | @@ -XXX,XX +XXX,XX @@ immediate_exit: | ||
159 | if (need_drain) { | ||
160 | bdrv_drained_begin(bs); | ||
161 | } | ||
162 | + | ||
163 | job_defer_to_main_loop(&s->common.job, mirror_exit, data); | ||
164 | + return ret; | ||
165 | } | ||
166 | |||
167 | static void mirror_complete(Job *job, Error **errp) | ||
168 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver mirror_job_driver = { | ||
169 | .free = block_job_free, | ||
170 | .user_resume = block_job_user_resume, | ||
171 | .drain = block_job_drain, | ||
172 | - .start = mirror_run, | ||
173 | + .run = mirror_run, | ||
174 | .pause = mirror_pause, | ||
175 | .complete = mirror_complete, | ||
176 | }, | ||
177 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver commit_active_job_driver = { | ||
178 | .free = block_job_free, | ||
179 | .user_resume = block_job_user_resume, | ||
180 | .drain = block_job_drain, | ||
181 | - .start = mirror_run, | ||
182 | + .run = mirror_run, | ||
183 | .pause = mirror_pause, | ||
184 | .complete = mirror_complete, | ||
185 | }, | ||
186 | diff --git a/block/stream.c b/block/stream.c | ||
187 | index XXXXXXX..XXXXXXX 100644 | ||
188 | --- a/block/stream.c | ||
189 | +++ b/block/stream.c | ||
190 | @@ -XXX,XX +XXX,XX @@ out: | ||
191 | g_free(data); | ||
192 | } | ||
193 | |||
194 | -static void coroutine_fn stream_run(void *opaque) | ||
195 | +static int coroutine_fn stream_run(Job *job, Error **errp) | ||
196 | { | ||
197 | - StreamBlockJob *s = opaque; | ||
198 | + StreamBlockJob *s = container_of(job, StreamBlockJob, common.job); | ||
199 | StreamCompleteData *data; | ||
200 | BlockBackend *blk = s->common.blk; | ||
201 | BlockDriverState *bs = blk_bs(blk); | ||
202 | @@ -XXX,XX +XXX,XX @@ out: | ||
203 | data = g_malloc(sizeof(*data)); | ||
204 | data->ret = ret; | ||
205 | job_defer_to_main_loop(&s->common.job, stream_complete, data); | ||
206 | + return ret; | ||
207 | } | ||
208 | |||
209 | static const BlockJobDriver stream_job_driver = { | ||
210 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver stream_job_driver = { | ||
211 | .instance_size = sizeof(StreamBlockJob), | ||
212 | .job_type = JOB_TYPE_STREAM, | ||
213 | .free = block_job_free, | ||
214 | - .start = stream_run, | ||
215 | + .run = stream_run, | ||
216 | .user_resume = block_job_user_resume, | ||
217 | .drain = block_job_drain, | ||
218 | }, | ||
219 | diff --git a/job.c b/job.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/job.c | ||
222 | +++ b/job.c | ||
223 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn job_co_entry(void *opaque) | ||
224 | { | ||
225 | Job *job = opaque; | ||
226 | |||
227 | - assert(job && job->driver && job->driver->start); | ||
228 | + assert(job && job->driver && job->driver->run); | ||
229 | job_pause_point(job); | ||
230 | - job->driver->start(job); | ||
231 | + job->ret = job->driver->run(job, NULL); | ||
232 | } | ||
233 | |||
234 | |||
235 | void job_start(Job *job) | ||
236 | { | ||
237 | assert(job && !job_started(job) && job->paused && | ||
238 | - job->driver && job->driver->start); | ||
239 | + job->driver && job->driver->run); | ||
240 | job->co = qemu_coroutine_create(job_co_entry, job); | ||
241 | job->pause_count--; | ||
242 | job->busy = true; | ||
243 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
244 | index XXXXXXX..XXXXXXX 100644 | ||
245 | --- a/tests/test-bdrv-drain.c | ||
246 | +++ b/tests/test-bdrv-drain.c | ||
247 | @@ -XXX,XX +XXX,XX @@ static void test_job_completed(Job *job, void *opaque) | ||
248 | job_completed(job, 0, NULL); | ||
249 | } | ||
250 | |||
251 | -static void coroutine_fn test_job_start(void *opaque) | ||
252 | +static int coroutine_fn test_job_run(Job *job, Error **errp) | ||
253 | { | ||
254 | - TestBlockJob *s = opaque; | ||
255 | + TestBlockJob *s = container_of(job, TestBlockJob, common.job); | ||
256 | |||
257 | job_transition_to_ready(&s->common.job); | ||
258 | while (!s->should_complete) { | ||
259 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn test_job_start(void *opaque) | ||
260 | } | ||
261 | |||
262 | job_defer_to_main_loop(&s->common.job, test_job_completed, NULL); | ||
263 | + return 0; | ||
264 | } | ||
265 | |||
266 | static void test_job_complete(Job *job, Error **errp) | ||
267 | @@ -XXX,XX +XXX,XX @@ BlockJobDriver test_job_driver = { | ||
268 | .free = block_job_free, | ||
269 | .user_resume = block_job_user_resume, | ||
270 | .drain = block_job_drain, | ||
271 | - .start = test_job_start, | ||
272 | + .run = test_job_run, | ||
273 | .complete = test_job_complete, | ||
274 | }, | ||
275 | }; | ||
276 | diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c | ||
277 | index XXXXXXX..XXXXXXX 100644 | ||
278 | --- a/tests/test-blockjob-txn.c | ||
279 | +++ b/tests/test-blockjob-txn.c | ||
280 | @@ -XXX,XX +XXX,XX @@ static void test_block_job_complete(Job *job, void *opaque) | ||
281 | bdrv_unref(bs); | ||
282 | } | ||
283 | |||
284 | -static void coroutine_fn test_block_job_run(void *opaque) | ||
285 | +static int coroutine_fn test_block_job_run(Job *job, Error **errp) | ||
286 | { | ||
287 | - TestBlockJob *s = opaque; | ||
288 | - BlockJob *job = &s->common; | ||
289 | + TestBlockJob *s = container_of(job, TestBlockJob, common.job); | ||
290 | |||
291 | while (s->iterations--) { | ||
292 | if (s->use_timer) { | ||
293 | - job_sleep_ns(&job->job, 0); | ||
294 | + job_sleep_ns(job, 0); | ||
295 | } else { | ||
296 | - job_yield(&job->job); | ||
297 | + job_yield(job); | ||
298 | } | ||
299 | |||
300 | - if (job_is_cancelled(&job->job)) { | ||
301 | + if (job_is_cancelled(job)) { | ||
302 | break; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | - job_defer_to_main_loop(&job->job, test_block_job_complete, | ||
307 | + job_defer_to_main_loop(job, test_block_job_complete, | ||
308 | (void *)(intptr_t)s->rc); | ||
309 | + return s->rc; | ||
310 | } | ||
311 | |||
312 | typedef struct { | ||
313 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver test_block_job_driver = { | ||
314 | .free = block_job_free, | ||
315 | .user_resume = block_job_user_resume, | ||
316 | .drain = block_job_drain, | ||
317 | - .start = test_block_job_run, | ||
318 | + .run = test_block_job_run, | ||
319 | }, | ||
320 | }; | ||
321 | |||
322 | diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c | ||
323 | index XXXXXXX..XXXXXXX 100644 | ||
324 | --- a/tests/test-blockjob.c | ||
325 | +++ b/tests/test-blockjob.c | ||
326 | @@ -XXX,XX +XXX,XX @@ static void cancel_job_complete(Job *job, Error **errp) | ||
327 | s->should_complete = true; | ||
328 | } | ||
329 | |||
330 | -static void coroutine_fn cancel_job_start(void *opaque) | ||
331 | +static int coroutine_fn cancel_job_run(Job *job, Error **errp) | ||
332 | { | ||
333 | - CancelJob *s = opaque; | ||
334 | + CancelJob *s = container_of(job, CancelJob, common.job); | ||
335 | |||
336 | while (!s->should_complete) { | ||
337 | if (job_is_cancelled(&s->common.job)) { | ||
338 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn cancel_job_start(void *opaque) | ||
339 | |||
340 | defer: | ||
341 | job_defer_to_main_loop(&s->common.job, cancel_job_completed, s); | ||
342 | + return 0; | ||
343 | } | ||
344 | |||
345 | static const BlockJobDriver test_cancel_driver = { | ||
346 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver test_cancel_driver = { | ||
347 | .free = block_job_free, | ||
348 | .user_resume = block_job_user_resume, | ||
349 | .drain = block_job_drain, | ||
350 | - .start = cancel_job_start, | ||
351 | + .run = cancel_job_run, | ||
352 | .complete = cancel_job_complete, | ||
353 | }, | ||
354 | }; | ||
355 | -- | ||
356 | 2.17.1 | ||
357 | |||
358 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: John Snow <jsnow@redhat.com> | |
2 | |||
3 | Jobs presently use both an Error object in the case of the create job, | ||
4 | and char strings in the case of generic errors elsewhere. | ||
5 | |||
6 | Unify the two paths as just j->err, and remove the extra argument from | ||
7 | job_completed. The integer error code for job_completed is kept for now, | ||
8 | to be removed shortly in a separate patch. | ||
9 | |||
10 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
11 | Message-id: 20180830015734.19765-3-jsnow@redhat.com | ||
12 | [mreitz: Dropped a superfluous g_strdup()] | ||
13 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
15 | --- | ||
16 | include/qemu/job.h | 14 ++++++++------ | ||
17 | block/backup.c | 2 +- | ||
18 | block/commit.c | 2 +- | ||
19 | block/create.c | 5 ++--- | ||
20 | block/mirror.c | 2 +- | ||
21 | block/stream.c | 2 +- | ||
22 | job-qmp.c | 5 +++-- | ||
23 | job.c | 18 ++++++------------ | ||
24 | tests/test-bdrv-drain.c | 2 +- | ||
25 | tests/test-blockjob-txn.c | 2 +- | ||
26 | tests/test-blockjob.c | 2 +- | ||
27 | 11 files changed, 26 insertions(+), 30 deletions(-) | ||
28 | |||
29 | diff --git a/include/qemu/job.h b/include/qemu/job.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/qemu/job.h | ||
32 | +++ b/include/qemu/job.h | ||
33 | @@ -XXX,XX +XXX,XX @@ typedef struct Job { | ||
34 | /** Estimated progress_current value at the completion of the job */ | ||
35 | int64_t progress_total; | ||
36 | |||
37 | - /** Error string for a failed job (NULL if, and only if, job->ret == 0) */ | ||
38 | - char *error; | ||
39 | - | ||
40 | /** ret code passed to job_completed. */ | ||
41 | int ret; | ||
42 | |||
43 | + /** | ||
44 | + * Error object for a failed job. | ||
45 | + * If job->ret is nonzero and an error object was not set, it will be set | ||
46 | + * to strerror(-job->ret) during job_completed. | ||
47 | + */ | ||
48 | + Error *err; | ||
49 | + | ||
50 | /** The completion function that will be called when the job completes. */ | ||
51 | BlockCompletionFunc *cb; | ||
52 | |||
53 | @@ -XXX,XX +XXX,XX @@ void job_transition_to_ready(Job *job); | ||
54 | /** | ||
55 | * @job: The job being completed. | ||
56 | * @ret: The status code. | ||
57 | - * @error: The error message for a failing job (only with @ret < 0). If @ret is | ||
58 | - * negative, but NULL is given for @error, strerror() is used. | ||
59 | * | ||
60 | * Marks @job as completed. If @ret is non-zero, the job transaction it is part | ||
61 | * of is aborted. If @ret is zero, the job moves into the WAITING state. If it | ||
62 | * is the last job to complete in its transaction, all jobs in the transaction | ||
63 | * move from WAITING to PENDING. | ||
64 | */ | ||
65 | -void job_completed(Job *job, int ret, Error *error); | ||
66 | +void job_completed(Job *job, int ret); | ||
67 | |||
68 | /** Asynchronously complete the specified @job. */ | ||
69 | void job_complete(Job *job, Error **errp); | ||
70 | diff --git a/block/backup.c b/block/backup.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/block/backup.c | ||
73 | +++ b/block/backup.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static void backup_complete(Job *job, void *opaque) | ||
75 | { | ||
76 | BackupCompleteData *data = opaque; | ||
77 | |||
78 | - job_completed(job, data->ret, NULL); | ||
79 | + job_completed(job, data->ret); | ||
80 | g_free(data); | ||
81 | } | ||
82 | |||
83 | diff --git a/block/commit.c b/block/commit.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/block/commit.c | ||
86 | +++ b/block/commit.c | ||
87 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(Job *job, void *opaque) | ||
88 | * bdrv_set_backing_hd() to fail. */ | ||
89 | block_job_remove_all_bdrv(bjob); | ||
90 | |||
91 | - job_completed(job, ret, NULL); | ||
92 | + job_completed(job, ret); | ||
93 | g_free(data); | ||
94 | |||
95 | /* If bdrv_drop_intermediate() didn't already do that, remove the commit | ||
96 | diff --git a/block/create.c b/block/create.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/block/create.c | ||
99 | +++ b/block/create.c | ||
100 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockdevCreateJob { | ||
101 | BlockDriver *drv; | ||
102 | BlockdevCreateOptions *opts; | ||
103 | int ret; | ||
104 | - Error *err; | ||
105 | } BlockdevCreateJob; | ||
106 | |||
107 | static void blockdev_create_complete(Job *job, void *opaque) | ||
108 | { | ||
109 | BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); | ||
110 | |||
111 | - job_completed(job, s->ret, s->err); | ||
112 | + job_completed(job, s->ret); | ||
113 | } | ||
114 | |||
115 | static int coroutine_fn blockdev_create_run(Job *job, Error **errp) | ||
116 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp) | ||
117 | BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); | ||
118 | |||
119 | job_progress_set_remaining(&s->common, 1); | ||
120 | - s->ret = s->drv->bdrv_co_create(s->opts, &s->err); | ||
121 | + s->ret = s->drv->bdrv_co_create(s->opts, errp); | ||
122 | job_progress_update(&s->common, 1); | ||
123 | |||
124 | qapi_free_BlockdevCreateOptions(s->opts); | ||
125 | diff --git a/block/mirror.c b/block/mirror.c | ||
126 | index XXXXXXX..XXXXXXX 100644 | ||
127 | --- a/block/mirror.c | ||
128 | +++ b/block/mirror.c | ||
129 | @@ -XXX,XX +XXX,XX @@ static void mirror_exit(Job *job, void *opaque) | ||
130 | blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort); | ||
131 | |||
132 | bs_opaque->job = NULL; | ||
133 | - job_completed(job, data->ret, NULL); | ||
134 | + job_completed(job, data->ret); | ||
135 | |||
136 | g_free(data); | ||
137 | bdrv_drained_end(src); | ||
138 | diff --git a/block/stream.c b/block/stream.c | ||
139 | index XXXXXXX..XXXXXXX 100644 | ||
140 | --- a/block/stream.c | ||
141 | +++ b/block/stream.c | ||
142 | @@ -XXX,XX +XXX,XX @@ out: | ||
143 | } | ||
144 | |||
145 | g_free(s->backing_file_str); | ||
146 | - job_completed(job, data->ret, NULL); | ||
147 | + job_completed(job, data->ret); | ||
148 | g_free(data); | ||
149 | } | ||
150 | |||
151 | diff --git a/job-qmp.c b/job-qmp.c | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/job-qmp.c | ||
154 | +++ b/job-qmp.c | ||
155 | @@ -XXX,XX +XXX,XX @@ static JobInfo *job_query_single(Job *job, Error **errp) | ||
156 | .status = job->status, | ||
157 | .current_progress = job->progress_current, | ||
158 | .total_progress = job->progress_total, | ||
159 | - .has_error = !!job->error, | ||
160 | - .error = g_strdup(job->error), | ||
161 | + .has_error = !!job->err, | ||
162 | + .error = job->err ? \ | ||
163 | + g_strdup(error_get_pretty(job->err)) : NULL, | ||
164 | }; | ||
165 | |||
166 | return info; | ||
167 | diff --git a/job.c b/job.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/job.c | ||
170 | +++ b/job.c | ||
171 | @@ -XXX,XX +XXX,XX @@ void job_unref(Job *job) | ||
172 | |||
173 | QLIST_REMOVE(job, job_list); | ||
174 | |||
175 | - g_free(job->error); | ||
176 | + error_free(job->err); | ||
177 | g_free(job->id); | ||
178 | g_free(job); | ||
179 | } | ||
180 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn job_co_entry(void *opaque) | ||
181 | |||
182 | assert(job && job->driver && job->driver->run); | ||
183 | job_pause_point(job); | ||
184 | - job->ret = job->driver->run(job, NULL); | ||
185 | + job->ret = job->driver->run(job, &job->err); | ||
186 | } | ||
187 | |||
188 | |||
189 | @@ -XXX,XX +XXX,XX @@ static void job_update_rc(Job *job) | ||
190 | job->ret = -ECANCELED; | ||
191 | } | ||
192 | if (job->ret) { | ||
193 | - if (!job->error) { | ||
194 | - job->error = g_strdup(strerror(-job->ret)); | ||
195 | + if (!job->err) { | ||
196 | + error_setg(&job->err, "%s", strerror(-job->ret)); | ||
197 | } | ||
198 | job_state_transition(job, JOB_STATUS_ABORTING); | ||
199 | } | ||
200 | @@ -XXX,XX +XXX,XX @@ static void job_completed_txn_success(Job *job) | ||
201 | } | ||
202 | } | ||
203 | |||
204 | -void job_completed(Job *job, int ret, Error *error) | ||
205 | +void job_completed(Job *job, int ret) | ||
206 | { | ||
207 | assert(job && job->txn && !job_is_completed(job)); | ||
208 | |||
209 | job->ret = ret; | ||
210 | - if (error) { | ||
211 | - assert(job->ret < 0); | ||
212 | - job->error = g_strdup(error_get_pretty(error)); | ||
213 | - error_free(error); | ||
214 | - } | ||
215 | - | ||
216 | job_update_rc(job); | ||
217 | trace_job_completed(job, ret, job->ret); | ||
218 | if (job->ret) { | ||
219 | @@ -XXX,XX +XXX,XX @@ void job_cancel(Job *job, bool force) | ||
220 | } | ||
221 | job_cancel_async(job, force); | ||
222 | if (!job_started(job)) { | ||
223 | - job_completed(job, -ECANCELED, NULL); | ||
224 | + job_completed(job, -ECANCELED); | ||
225 | } else if (job->deferred_to_main_loop) { | ||
226 | job_completed_txn_abort(job); | ||
227 | } else { | ||
228 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
229 | index XXXXXXX..XXXXXXX 100644 | ||
230 | --- a/tests/test-bdrv-drain.c | ||
231 | +++ b/tests/test-bdrv-drain.c | ||
232 | @@ -XXX,XX +XXX,XX @@ typedef struct TestBlockJob { | ||
233 | |||
234 | static void test_job_completed(Job *job, void *opaque) | ||
235 | { | ||
236 | - job_completed(job, 0, NULL); | ||
237 | + job_completed(job, 0); | ||
238 | } | ||
239 | |||
240 | static int coroutine_fn test_job_run(Job *job, Error **errp) | ||
241 | diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c | ||
242 | index XXXXXXX..XXXXXXX 100644 | ||
243 | --- a/tests/test-blockjob-txn.c | ||
244 | +++ b/tests/test-blockjob-txn.c | ||
245 | @@ -XXX,XX +XXX,XX @@ static void test_block_job_complete(Job *job, void *opaque) | ||
246 | rc = -ECANCELED; | ||
247 | } | ||
248 | |||
249 | - job_completed(job, rc, NULL); | ||
250 | + job_completed(job, rc); | ||
251 | bdrv_unref(bs); | ||
252 | } | ||
253 | |||
254 | diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c | ||
255 | index XXXXXXX..XXXXXXX 100644 | ||
256 | --- a/tests/test-blockjob.c | ||
257 | +++ b/tests/test-blockjob.c | ||
258 | @@ -XXX,XX +XXX,XX @@ static void cancel_job_completed(Job *job, void *opaque) | ||
259 | { | ||
260 | CancelJob *s = opaque; | ||
261 | s->completed = true; | ||
262 | - job_completed(job, 0, NULL); | ||
263 | + job_completed(job, 0); | ||
264 | } | ||
265 | |||
266 | static void cancel_job_complete(Job *job, Error **errp) | ||
267 | -- | ||
268 | 2.17.1 | ||
269 | |||
270 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | All jobs do the same thing when they leave their running loop: | ||
4 | - Store the return code in a structure | ||
5 | - wait to receive this structure in the main thread | ||
6 | - signal job completion via job_completed | ||
7 | |||
8 | Few jobs do anything beyond exactly this. Consolidate this exit | ||
9 | logic for a net reduction in SLOC. | ||
10 | |||
11 | More seriously, when we utilize job_defer_to_main_loop_bh to call | ||
12 | a function that calls job_completed, job_finalize_single will run | ||
13 | in a context where it has recursively taken the aio_context lock, | ||
14 | which can cause hangs if it puts down a reference that causes a flush. | ||
15 | |||
16 | You can observe this in practice by looking at mirror_exit's careful | ||
17 | placement of job_completed and bdrv_unref calls. | ||
18 | |||
19 | If we centralize job exiting, we can signal job completion from outside | ||
20 | of the aio_context, which should allow for job cleanup code to run with | ||
21 | only one lock, which makes cleanup callbacks less tricky to write. | ||
22 | |||
23 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
24 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
25 | Message-id: 20180830015734.19765-4-jsnow@redhat.com | ||
26 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
27 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
28 | --- | ||
29 | include/qemu/job.h | 11 +++++++++++ | ||
30 | job.c | 18 ++++++++++++++++++ | ||
31 | 2 files changed, 29 insertions(+) | ||
32 | |||
33 | diff --git a/include/qemu/job.h b/include/qemu/job.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/qemu/job.h | ||
36 | +++ b/include/qemu/job.h | ||
37 | @@ -XXX,XX +XXX,XX @@ struct JobDriver { | ||
38 | */ | ||
39 | void (*drain)(Job *job); | ||
40 | |||
41 | + /** | ||
42 | + * If the callback is not NULL, exit will be invoked from the main thread | ||
43 | + * when the job's coroutine has finished, but before transactional | ||
44 | + * convergence; before @prepare or @abort. | ||
45 | + * | ||
46 | + * FIXME TODO: This callback is only temporary to transition remaining jobs | ||
47 | + * to prepare/commit/abort/clean callbacks and will be removed before 3.1. | ||
48 | + * is released. | ||
49 | + */ | ||
50 | + void (*exit)(Job *job); | ||
51 | + | ||
52 | /** | ||
53 | * If the callback is not NULL, prepare will be invoked when all the jobs | ||
54 | * belonging to the same transaction complete; or upon this job's completion | ||
55 | diff --git a/job.c b/job.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/job.c | ||
58 | +++ b/job.c | ||
59 | @@ -XXX,XX +XXX,XX @@ void job_drain(Job *job) | ||
60 | } | ||
61 | } | ||
62 | |||
63 | +static void job_exit(void *opaque) | ||
64 | +{ | ||
65 | + Job *job = (Job *)opaque; | ||
66 | + AioContext *aio_context = job->aio_context; | ||
67 | + | ||
68 | + if (job->driver->exit) { | ||
69 | + aio_context_acquire(aio_context); | ||
70 | + job->driver->exit(job); | ||
71 | + aio_context_release(aio_context); | ||
72 | + } | ||
73 | + job_completed(job, job->ret); | ||
74 | +} | ||
75 | |||
76 | /** | ||
77 | * All jobs must allow a pause point before entering their job proper. This | ||
78 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn job_co_entry(void *opaque) | ||
79 | assert(job && job->driver && job->driver->run); | ||
80 | job_pause_point(job); | ||
81 | job->ret = job->driver->run(job, &job->err); | ||
82 | + if (!job->deferred_to_main_loop) { | ||
83 | + job->deferred_to_main_loop = true; | ||
84 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
85 | + job_exit, | ||
86 | + job); | ||
87 | + } | ||
88 | } | ||
89 | |||
90 | |||
91 | -- | ||
92 | 2.17.1 | ||
93 | |||
94 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | "0x%u" format is very misleading, replace by "0x%x". | 3 | Change the manual deferment to commit_complete into the implicit |
4 | callback to job_exit, renaming commit_complete to commit_exit. | ||
4 | 5 | ||
5 | Found running: | 6 | This conversion does change the timing of when job_completed is |
7 | called to after the bdrv_replace_node and bdrv_unref calls, which | ||
8 | could have implications for bjob->blk which will now be put down | ||
9 | after this cleanup. | ||
6 | 10 | ||
7 | $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/ | 11 | Kevin highlights that we did not take any permissions for that backend |
12 | at job creation time, so it is safe to reorder these operations. | ||
8 | 13 | ||
9 | Inspired-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Signed-off-by: John Snow <jsnow@redhat.com> |
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 15 | Reviewed-by: Max Reitz <mreitz@redhat.com> |
11 | Reviewed-by: Hanna Reitz <hreitz@redhat.com> | 16 | Message-id: 20180830015734.19765-5-jsnow@redhat.com |
12 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | 17 | Reviewed-by: Jeff Cody <jcody@redhat.com> |
13 | Reviewed-by: Denis V. Lunev <den@openvz.org> | 18 | Signed-off-by: Max Reitz <mreitz@redhat.com> |
14 | Message-id: 20220323114718.58714-2-philippe.mathieu.daude@gmail.com | ||
15 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
16 | --- | 19 | --- |
17 | block/parallels-ext.c | 2 +- | 20 | block/commit.c | 22 +++++----------------- |
18 | 1 file changed, 1 insertion(+), 1 deletion(-) | 21 | 1 file changed, 5 insertions(+), 17 deletions(-) |
19 | 22 | ||
20 | diff --git a/block/parallels-ext.c b/block/parallels-ext.c | 23 | diff --git a/block/commit.c b/block/commit.c |
21 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/block/parallels-ext.c | 25 | --- a/block/commit.c |
23 | +++ b/block/parallels-ext.c | 26 | +++ b/block/commit.c |
24 | @@ -XXX,XX +XXX,XX @@ static int parallels_parse_format_extension(BlockDriverState *bs, | 27 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn commit_populate(BlockBackend *bs, BlockBackend *base, |
25 | break; | 28 | return 0; |
26 | 29 | } | |
27 | default: | 30 | |
28 | - error_setg(errp, "Unknown feature: 0x%" PRIu64, fh.magic); | 31 | -typedef struct { |
29 | + error_setg(errp, "Unknown feature: 0x%" PRIx64, fh.magic); | 32 | - int ret; |
30 | goto fail; | 33 | -} CommitCompleteData; |
31 | } | 34 | - |
35 | -static void commit_complete(Job *job, void *opaque) | ||
36 | +static void commit_exit(Job *job) | ||
37 | { | ||
38 | CommitBlockJob *s = container_of(job, CommitBlockJob, common.job); | ||
39 | BlockJob *bjob = &s->common; | ||
40 | - CommitCompleteData *data = opaque; | ||
41 | BlockDriverState *top = blk_bs(s->top); | ||
42 | BlockDriverState *base = blk_bs(s->base); | ||
43 | BlockDriverState *commit_top_bs = s->commit_top_bs; | ||
44 | - int ret = data->ret; | ||
45 | bool remove_commit_top_bs = false; | ||
46 | |||
47 | /* Make sure commit_top_bs and top stay around until bdrv_replace_node() */ | ||
48 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(Job *job, void *opaque) | ||
49 | * the normal backing chain can be restored. */ | ||
50 | blk_unref(s->base); | ||
51 | |||
52 | - if (!job_is_cancelled(job) && ret == 0) { | ||
53 | + if (!job_is_cancelled(job) && job->ret == 0) { | ||
54 | /* success */ | ||
55 | - ret = bdrv_drop_intermediate(s->commit_top_bs, base, | ||
56 | - s->backing_file_str); | ||
57 | + job->ret = bdrv_drop_intermediate(s->commit_top_bs, base, | ||
58 | + s->backing_file_str); | ||
59 | } else { | ||
60 | /* XXX Can (or should) we somehow keep 'consistent read' blocked even | ||
61 | * after the failed/cancelled commit job is gone? If we already wrote | ||
62 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(Job *job, void *opaque) | ||
63 | * bdrv_set_backing_hd() to fail. */ | ||
64 | block_job_remove_all_bdrv(bjob); | ||
65 | |||
66 | - job_completed(job, ret); | ||
67 | - g_free(data); | ||
68 | - | ||
69 | /* If bdrv_drop_intermediate() didn't already do that, remove the commit | ||
70 | * filter driver from the backing chain. Do this as the final step so that | ||
71 | * the 'consistent read' permission can be granted. */ | ||
72 | @@ -XXX,XX +XXX,XX @@ static void commit_complete(Job *job, void *opaque) | ||
73 | static int coroutine_fn commit_run(Job *job, Error **errp) | ||
74 | { | ||
75 | CommitBlockJob *s = container_of(job, CommitBlockJob, common.job); | ||
76 | - CommitCompleteData *data; | ||
77 | int64_t offset; | ||
78 | uint64_t delay_ns = 0; | ||
79 | int ret = 0; | ||
80 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn commit_run(Job *job, Error **errp) | ||
81 | out: | ||
82 | qemu_vfree(buf); | ||
83 | |||
84 | - data = g_malloc(sizeof(*data)); | ||
85 | - data->ret = ret; | ||
86 | - job_defer_to_main_loop(&s->common.job, commit_complete, data); | ||
87 | return ret; | ||
88 | } | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver commit_job_driver = { | ||
91 | .user_resume = block_job_user_resume, | ||
92 | .drain = block_job_drain, | ||
93 | .run = commit_run, | ||
94 | + .exit = commit_exit, | ||
95 | }, | ||
96 | }; | ||
32 | 97 | ||
33 | -- | 98 | -- |
34 | 2.35.1 | 99 | 2.17.1 |
35 | 100 | ||
36 | 101 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Change the manual deferment to mirror_exit into the implicit | ||
4 | callback to job_exit and the mirror_exit callback. | ||
5 | |||
6 | This does change the order of some bdrv_unref calls and job_completed, | ||
7 | but thanks to the new context in which we call .exit, this is safe to | ||
8 | defer the possible flushing of any nodes to the job_finalize_single | ||
9 | cleanup stage. | ||
10 | |||
11 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
12 | Message-id: 20180830015734.19765-6-jsnow@redhat.com | ||
13 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
14 | Reviewed-by: Jeff Cody <jcody@redhat.com> | ||
15 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
16 | --- | ||
17 | block/mirror.c | 29 +++++++++++------------------ | ||
18 | 1 file changed, 11 insertions(+), 18 deletions(-) | ||
19 | |||
20 | diff --git a/block/mirror.c b/block/mirror.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/block/mirror.c | ||
23 | +++ b/block/mirror.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static void mirror_wait_for_all_io(MirrorBlockJob *s) | ||
25 | } | ||
26 | } | ||
27 | |||
28 | -typedef struct { | ||
29 | - int ret; | ||
30 | -} MirrorExitData; | ||
31 | - | ||
32 | -static void mirror_exit(Job *job, void *opaque) | ||
33 | +static void mirror_exit(Job *job) | ||
34 | { | ||
35 | MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); | ||
36 | BlockJob *bjob = &s->common; | ||
37 | - MirrorExitData *data = opaque; | ||
38 | MirrorBDSOpaque *bs_opaque = s->mirror_top_bs->opaque; | ||
39 | AioContext *replace_aio_context = NULL; | ||
40 | BlockDriverState *src = s->mirror_top_bs->backing->bs; | ||
41 | BlockDriverState *target_bs = blk_bs(s->target); | ||
42 | BlockDriverState *mirror_top_bs = s->mirror_top_bs; | ||
43 | Error *local_err = NULL; | ||
44 | + int ret = job->ret; | ||
45 | |||
46 | bdrv_release_dirty_bitmap(src, s->dirty_bitmap); | ||
47 | |||
48 | - /* Make sure that the source BDS doesn't go away before we called | ||
49 | - * job_completed(). */ | ||
50 | + /* Make sure that the source BDS doesn't go away during bdrv_replace_node, | ||
51 | + * before we can call bdrv_drained_end */ | ||
52 | bdrv_ref(src); | ||
53 | bdrv_ref(mirror_top_bs); | ||
54 | bdrv_ref(target_bs); | ||
55 | @@ -XXX,XX +XXX,XX @@ static void mirror_exit(Job *job, void *opaque) | ||
56 | bdrv_set_backing_hd(target_bs, backing, &local_err); | ||
57 | if (local_err) { | ||
58 | error_report_err(local_err); | ||
59 | - data->ret = -EPERM; | ||
60 | + ret = -EPERM; | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static void mirror_exit(Job *job, void *opaque) | ||
65 | aio_context_acquire(replace_aio_context); | ||
66 | } | ||
67 | |||
68 | - if (s->should_complete && data->ret == 0) { | ||
69 | + if (s->should_complete && ret == 0) { | ||
70 | BlockDriverState *to_replace = src; | ||
71 | if (s->to_replace) { | ||
72 | to_replace = s->to_replace; | ||
73 | @@ -XXX,XX +XXX,XX @@ static void mirror_exit(Job *job, void *opaque) | ||
74 | bdrv_drained_end(target_bs); | ||
75 | if (local_err) { | ||
76 | error_report_err(local_err); | ||
77 | - data->ret = -EPERM; | ||
78 | + ret = -EPERM; | ||
79 | } | ||
80 | } | ||
81 | if (s->to_replace) { | ||
82 | @@ -XXX,XX +XXX,XX @@ static void mirror_exit(Job *job, void *opaque) | ||
83 | blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort); | ||
84 | |||
85 | bs_opaque->job = NULL; | ||
86 | - job_completed(job, data->ret); | ||
87 | |||
88 | - g_free(data); | ||
89 | bdrv_drained_end(src); | ||
90 | bdrv_unref(mirror_top_bs); | ||
91 | bdrv_unref(src); | ||
92 | + | ||
93 | + job->ret = ret; | ||
94 | } | ||
95 | |||
96 | static void mirror_throttle(MirrorBlockJob *s) | ||
97 | @@ -XXX,XX +XXX,XX @@ static int mirror_flush(MirrorBlockJob *s) | ||
98 | static int coroutine_fn mirror_run(Job *job, Error **errp) | ||
99 | { | ||
100 | MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); | ||
101 | - MirrorExitData *data; | ||
102 | BlockDriverState *bs = s->mirror_top_bs->backing->bs; | ||
103 | BlockDriverState *target_bs = blk_bs(s->target); | ||
104 | bool need_drain = true; | ||
105 | @@ -XXX,XX +XXX,XX @@ immediate_exit: | ||
106 | g_free(s->in_flight_bitmap); | ||
107 | bdrv_dirty_iter_free(s->dbi); | ||
108 | |||
109 | - data = g_malloc(sizeof(*data)); | ||
110 | - data->ret = ret; | ||
111 | - | ||
112 | if (need_drain) { | ||
113 | bdrv_drained_begin(bs); | ||
114 | } | ||
115 | |||
116 | - job_defer_to_main_loop(&s->common.job, mirror_exit, data); | ||
117 | return ret; | ||
118 | } | ||
119 | |||
120 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver mirror_job_driver = { | ||
121 | .user_resume = block_job_user_resume, | ||
122 | .drain = block_job_drain, | ||
123 | .run = mirror_run, | ||
124 | + .exit = mirror_exit, | ||
125 | .pause = mirror_pause, | ||
126 | .complete = mirror_complete, | ||
127 | }, | ||
128 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver commit_active_job_driver = { | ||
129 | .user_resume = block_job_user_resume, | ||
130 | .drain = block_job_drain, | ||
131 | .run = mirror_run, | ||
132 | + .exit = mirror_exit, | ||
133 | .pause = mirror_pause, | ||
134 | .complete = mirror_complete, | ||
135 | }, | ||
136 | -- | ||
137 | 2.17.1 | ||
138 | |||
139 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: John Snow <jsnow@redhat.com> | |
2 | |||
3 | Utilize the job_exit shim by not calling job_defer_to_main_loop, and | ||
4 | where applicable, converting the deferred callback into the job_exit | ||
5 | callback. | ||
6 | |||
7 | This converts backup, stream, create, and the unit tests all at once. | ||
8 | Most of these jobs do not see any changes to the order in which they | ||
9 | clean up their resources, except the test-blockjob-txn test, which | ||
10 | now puts down its bs before job_completed is called. | ||
11 | |||
12 | This is safe for the same reason the reordering in the mirror job is | ||
13 | safe, because job_completed no longer runs under two locks, making | ||
14 | the unref safe even if it causes a flush. | ||
15 | |||
16 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
17 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
18 | Message-id: 20180830015734.19765-7-jsnow@redhat.com | ||
19 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
20 | --- | ||
21 | block/backup.c | 16 ---------------- | ||
22 | block/create.c | 14 +++----------- | ||
23 | block/stream.c | 22 +++++++--------------- | ||
24 | tests/test-bdrv-drain.c | 6 ------ | ||
25 | tests/test-blockjob-txn.c | 11 ++--------- | ||
26 | tests/test-blockjob.c | 10 ++++------ | ||
27 | 6 files changed, 16 insertions(+), 63 deletions(-) | ||
28 | |||
29 | diff --git a/block/backup.c b/block/backup.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/block/backup.c | ||
32 | +++ b/block/backup.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static BlockErrorAction backup_error_action(BackupBlockJob *job, | ||
34 | } | ||
35 | } | ||
36 | |||
37 | -typedef struct { | ||
38 | - int ret; | ||
39 | -} BackupCompleteData; | ||
40 | - | ||
41 | -static void backup_complete(Job *job, void *opaque) | ||
42 | -{ | ||
43 | - BackupCompleteData *data = opaque; | ||
44 | - | ||
45 | - job_completed(job, data->ret); | ||
46 | - g_free(data); | ||
47 | -} | ||
48 | - | ||
49 | static bool coroutine_fn yield_and_check(BackupBlockJob *job) | ||
50 | { | ||
51 | uint64_t delay_ns; | ||
52 | @@ -XXX,XX +XXX,XX @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job) | ||
53 | static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
54 | { | ||
55 | BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job); | ||
56 | - BackupCompleteData *data; | ||
57 | BlockDriverState *bs = blk_bs(job->common.blk); | ||
58 | int64_t offset, nb_clusters; | ||
59 | int ret = 0; | ||
60 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
61 | qemu_co_rwlock_unlock(&job->flush_rwlock); | ||
62 | hbitmap_free(job->copy_bitmap); | ||
63 | |||
64 | - data = g_malloc(sizeof(*data)); | ||
65 | - data->ret = ret; | ||
66 | - job_defer_to_main_loop(&job->common.job, backup_complete, data); | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | diff --git a/block/create.c b/block/create.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/block/create.c | ||
73 | +++ b/block/create.c | ||
74 | @@ -XXX,XX +XXX,XX @@ typedef struct BlockdevCreateJob { | ||
75 | Job common; | ||
76 | BlockDriver *drv; | ||
77 | BlockdevCreateOptions *opts; | ||
78 | - int ret; | ||
79 | } BlockdevCreateJob; | ||
80 | |||
81 | -static void blockdev_create_complete(Job *job, void *opaque) | ||
82 | -{ | ||
83 | - BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); | ||
84 | - | ||
85 | - job_completed(job, s->ret); | ||
86 | -} | ||
87 | - | ||
88 | static int coroutine_fn blockdev_create_run(Job *job, Error **errp) | ||
89 | { | ||
90 | BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common); | ||
91 | + int ret; | ||
92 | |||
93 | job_progress_set_remaining(&s->common, 1); | ||
94 | - s->ret = s->drv->bdrv_co_create(s->opts, errp); | ||
95 | + ret = s->drv->bdrv_co_create(s->opts, errp); | ||
96 | job_progress_update(&s->common, 1); | ||
97 | |||
98 | qapi_free_BlockdevCreateOptions(s->opts); | ||
99 | - job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL); | ||
100 | |||
101 | - return s->ret; | ||
102 | + return ret; | ||
103 | } | ||
104 | |||
105 | static const JobDriver blockdev_create_job_driver = { | ||
106 | diff --git a/block/stream.c b/block/stream.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/block/stream.c | ||
109 | +++ b/block/stream.c | ||
110 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn stream_populate(BlockBackend *blk, | ||
111 | return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ); | ||
112 | } | ||
113 | |||
114 | -typedef struct { | ||
115 | - int ret; | ||
116 | -} StreamCompleteData; | ||
117 | - | ||
118 | -static void stream_complete(Job *job, void *opaque) | ||
119 | +static void stream_exit(Job *job) | ||
120 | { | ||
121 | StreamBlockJob *s = container_of(job, StreamBlockJob, common.job); | ||
122 | BlockJob *bjob = &s->common; | ||
123 | - StreamCompleteData *data = opaque; | ||
124 | BlockDriverState *bs = blk_bs(bjob->blk); | ||
125 | BlockDriverState *base = s->base; | ||
126 | Error *local_err = NULL; | ||
127 | + int ret = job->ret; | ||
128 | |||
129 | - if (!job_is_cancelled(job) && bs->backing && data->ret == 0) { | ||
130 | + if (!job_is_cancelled(job) && bs->backing && ret == 0) { | ||
131 | const char *base_id = NULL, *base_fmt = NULL; | ||
132 | if (base) { | ||
133 | base_id = s->backing_file_str; | ||
134 | @@ -XXX,XX +XXX,XX @@ static void stream_complete(Job *job, void *opaque) | ||
135 | base_fmt = base->drv->format_name; | ||
136 | } | ||
137 | } | ||
138 | - data->ret = bdrv_change_backing_file(bs, base_id, base_fmt); | ||
139 | + ret = bdrv_change_backing_file(bs, base_id, base_fmt); | ||
140 | bdrv_set_backing_hd(bs, base, &local_err); | ||
141 | if (local_err) { | ||
142 | error_report_err(local_err); | ||
143 | - data->ret = -EPERM; | ||
144 | + ret = -EPERM; | ||
145 | goto out; | ||
146 | } | ||
147 | } | ||
148 | @@ -XXX,XX +XXX,XX @@ out: | ||
149 | } | ||
150 | |||
151 | g_free(s->backing_file_str); | ||
152 | - job_completed(job, data->ret); | ||
153 | - g_free(data); | ||
154 | + job->ret = ret; | ||
155 | } | ||
156 | |||
157 | static int coroutine_fn stream_run(Job *job, Error **errp) | ||
158 | { | ||
159 | StreamBlockJob *s = container_of(job, StreamBlockJob, common.job); | ||
160 | - StreamCompleteData *data; | ||
161 | BlockBackend *blk = s->common.blk; | ||
162 | BlockDriverState *bs = blk_bs(blk); | ||
163 | BlockDriverState *base = s->base; | ||
164 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn stream_run(Job *job, Error **errp) | ||
165 | |||
166 | out: | ||
167 | /* Modify backing chain and close BDSes in main loop */ | ||
168 | - data = g_malloc(sizeof(*data)); | ||
169 | - data->ret = ret; | ||
170 | - job_defer_to_main_loop(&s->common.job, stream_complete, data); | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver stream_job_driver = { | ||
175 | .job_type = JOB_TYPE_STREAM, | ||
176 | .free = block_job_free, | ||
177 | .run = stream_run, | ||
178 | + .exit = stream_exit, | ||
179 | .user_resume = block_job_user_resume, | ||
180 | .drain = block_job_drain, | ||
181 | }, | ||
182 | diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c | ||
183 | index XXXXXXX..XXXXXXX 100644 | ||
184 | --- a/tests/test-bdrv-drain.c | ||
185 | +++ b/tests/test-bdrv-drain.c | ||
186 | @@ -XXX,XX +XXX,XX @@ typedef struct TestBlockJob { | ||
187 | bool should_complete; | ||
188 | } TestBlockJob; | ||
189 | |||
190 | -static void test_job_completed(Job *job, void *opaque) | ||
191 | -{ | ||
192 | - job_completed(job, 0); | ||
193 | -} | ||
194 | - | ||
195 | static int coroutine_fn test_job_run(Job *job, Error **errp) | ||
196 | { | ||
197 | TestBlockJob *s = container_of(job, TestBlockJob, common.job); | ||
198 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn test_job_run(Job *job, Error **errp) | ||
199 | job_pause_point(&s->common.job); | ||
200 | } | ||
201 | |||
202 | - job_defer_to_main_loop(&s->common.job, test_job_completed, NULL); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c | ||
207 | index XXXXXXX..XXXXXXX 100644 | ||
208 | --- a/tests/test-blockjob-txn.c | ||
209 | +++ b/tests/test-blockjob-txn.c | ||
210 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
211 | int *result; | ||
212 | } TestBlockJob; | ||
213 | |||
214 | -static void test_block_job_complete(Job *job, void *opaque) | ||
215 | +static void test_block_job_exit(Job *job) | ||
216 | { | ||
217 | BlockJob *bjob = container_of(job, BlockJob, job); | ||
218 | BlockDriverState *bs = blk_bs(bjob->blk); | ||
219 | - int rc = (intptr_t)opaque; | ||
220 | |||
221 | - if (job_is_cancelled(job)) { | ||
222 | - rc = -ECANCELED; | ||
223 | - } | ||
224 | - | ||
225 | - job_completed(job, rc); | ||
226 | bdrv_unref(bs); | ||
227 | } | ||
228 | |||
229 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn test_block_job_run(Job *job, Error **errp) | ||
230 | } | ||
231 | } | ||
232 | |||
233 | - job_defer_to_main_loop(job, test_block_job_complete, | ||
234 | - (void *)(intptr_t)s->rc); | ||
235 | return s->rc; | ||
236 | } | ||
237 | |||
238 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver test_block_job_driver = { | ||
239 | .user_resume = block_job_user_resume, | ||
240 | .drain = block_job_drain, | ||
241 | .run = test_block_job_run, | ||
242 | + .exit = test_block_job_exit, | ||
243 | }, | ||
244 | }; | ||
245 | |||
246 | diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c | ||
247 | index XXXXXXX..XXXXXXX 100644 | ||
248 | --- a/tests/test-blockjob.c | ||
249 | +++ b/tests/test-blockjob.c | ||
250 | @@ -XXX,XX +XXX,XX @@ typedef struct CancelJob { | ||
251 | bool completed; | ||
252 | } CancelJob; | ||
253 | |||
254 | -static void cancel_job_completed(Job *job, void *opaque) | ||
255 | +static void cancel_job_exit(Job *job) | ||
256 | { | ||
257 | - CancelJob *s = opaque; | ||
258 | + CancelJob *s = container_of(job, CancelJob, common.job); | ||
259 | s->completed = true; | ||
260 | - job_completed(job, 0); | ||
261 | } | ||
262 | |||
263 | static void cancel_job_complete(Job *job, Error **errp) | ||
264 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp) | ||
265 | |||
266 | while (!s->should_complete) { | ||
267 | if (job_is_cancelled(&s->common.job)) { | ||
268 | - goto defer; | ||
269 | + return 0; | ||
270 | } | ||
271 | |||
272 | if (!job_is_ready(&s->common.job) && s->should_converge) { | ||
273 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp) | ||
274 | job_sleep_ns(&s->common.job, 100000); | ||
275 | } | ||
276 | |||
277 | - defer: | ||
278 | - job_defer_to_main_loop(&s->common.job, cancel_job_completed, s); | ||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | @@ -XXX,XX +XXX,XX @@ static const BlockJobDriver test_cancel_driver = { | ||
283 | .user_resume = block_job_user_resume, | ||
284 | .drain = block_job_drain, | ||
285 | .run = cancel_job_run, | ||
286 | + .exit = cancel_job_exit, | ||
287 | .complete = cancel_job_complete, | ||
288 | }, | ||
289 | }; | ||
290 | -- | ||
291 | 2.17.1 | ||
292 | |||
293 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: John Snow <jsnow@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | "0x%u" format is very misleading, replace by "0x%x". | 3 | Rename opaque_job to job to be consistent with other job implementations. |
4 | Rename 'job', the BackupBlockJob object, to 's' to also be consistent. | ||
4 | 5 | ||
5 | Found running: | 6 | Suggested-by: Eric Blake <eblake@redhat.com> |
7 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
9 | Message-id: 20180830015734.19765-8-jsnow@redhat.com | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | block/backup.c | 62 +++++++++++++++++++++++++------------------------- | ||
13 | 1 file changed, 31 insertions(+), 31 deletions(-) | ||
6 | 14 | ||
7 | $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' hw/ | 15 | diff --git a/block/backup.c b/block/backup.c |
8 | |||
9 | Inspired-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
12 | Message-id: 20220323114718.58714-3-philippe.mathieu.daude@gmail.com | ||
13 | Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> | ||
14 | --- | ||
15 | hw/i386/sgx.c | 2 +- | ||
16 | hw/i386/trace-events | 6 +++--- | ||
17 | hw/misc/trace-events | 4 ++-- | ||
18 | hw/scsi/trace-events | 4 ++-- | ||
19 | 4 files changed, 8 insertions(+), 8 deletions(-) | ||
20 | |||
21 | diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/i386/sgx.c | 17 | --- a/block/backup.c |
24 | +++ b/hw/i386/sgx.c | 18 | +++ b/block/backup.c |
25 | @@ -XXX,XX +XXX,XX @@ void pc_machine_init_sgx_epc(PCMachineState *pcms) | 19 | @@ -XXX,XX +XXX,XX @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job) |
20 | bdrv_dirty_iter_free(dbi); | ||
21 | } | ||
22 | |||
23 | -static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
24 | +static int coroutine_fn backup_run(Job *job, Error **errp) | ||
25 | { | ||
26 | - BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job); | ||
27 | - BlockDriverState *bs = blk_bs(job->common.blk); | ||
28 | + BackupBlockJob *s = container_of(job, BackupBlockJob, common.job); | ||
29 | + BlockDriverState *bs = blk_bs(s->common.blk); | ||
30 | int64_t offset, nb_clusters; | ||
31 | int ret = 0; | ||
32 | |||
33 | - QLIST_INIT(&job->inflight_reqs); | ||
34 | - qemu_co_rwlock_init(&job->flush_rwlock); | ||
35 | + QLIST_INIT(&s->inflight_reqs); | ||
36 | + qemu_co_rwlock_init(&s->flush_rwlock); | ||
37 | |||
38 | - nb_clusters = DIV_ROUND_UP(job->len, job->cluster_size); | ||
39 | - job_progress_set_remaining(&job->common.job, job->len); | ||
40 | + nb_clusters = DIV_ROUND_UP(s->len, s->cluster_size); | ||
41 | + job_progress_set_remaining(job, s->len); | ||
42 | |||
43 | - job->copy_bitmap = hbitmap_alloc(nb_clusters, 0); | ||
44 | - if (job->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { | ||
45 | - backup_incremental_init_copy_bitmap(job); | ||
46 | + s->copy_bitmap = hbitmap_alloc(nb_clusters, 0); | ||
47 | + if (s->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { | ||
48 | + backup_incremental_init_copy_bitmap(s); | ||
49 | } else { | ||
50 | - hbitmap_set(job->copy_bitmap, 0, nb_clusters); | ||
51 | + hbitmap_set(s->copy_bitmap, 0, nb_clusters); | ||
26 | } | 52 | } |
27 | 53 | ||
28 | if ((sgx_epc->base + sgx_epc->size) < sgx_epc->base) { | 54 | |
29 | - error_report("Size of all 'sgx-epc' =0x%"PRIu64" causes EPC to wrap", | 55 | - job->before_write.notify = backup_before_write_notify; |
30 | + error_report("Size of all 'sgx-epc' =0x%"PRIx64" causes EPC to wrap", | 56 | - bdrv_add_before_write_notifier(bs, &job->before_write); |
31 | sgx_epc->size); | 57 | + s->before_write.notify = backup_before_write_notify; |
32 | exit(EXIT_FAILURE); | 58 | + bdrv_add_before_write_notifier(bs, &s->before_write); |
59 | |||
60 | - if (job->sync_mode == MIRROR_SYNC_MODE_NONE) { | ||
61 | + if (s->sync_mode == MIRROR_SYNC_MODE_NONE) { | ||
62 | /* All bits are set in copy_bitmap to allow any cluster to be copied. | ||
63 | * This does not actually require them to be copied. */ | ||
64 | - while (!job_is_cancelled(&job->common.job)) { | ||
65 | + while (!job_is_cancelled(job)) { | ||
66 | /* Yield until the job is cancelled. We just let our before_write | ||
67 | * notify callback service CoW requests. */ | ||
68 | - job_yield(&job->common.job); | ||
69 | + job_yield(job); | ||
70 | } | ||
71 | - } else if (job->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { | ||
72 | - ret = backup_run_incremental(job); | ||
73 | + } else if (s->sync_mode == MIRROR_SYNC_MODE_INCREMENTAL) { | ||
74 | + ret = backup_run_incremental(s); | ||
75 | } else { | ||
76 | /* Both FULL and TOP SYNC_MODE's require copying.. */ | ||
77 | - for (offset = 0; offset < job->len; | ||
78 | - offset += job->cluster_size) { | ||
79 | + for (offset = 0; offset < s->len; | ||
80 | + offset += s->cluster_size) { | ||
81 | bool error_is_read; | ||
82 | int alloced = 0; | ||
83 | |||
84 | - if (yield_and_check(job)) { | ||
85 | + if (yield_and_check(s)) { | ||
86 | break; | ||
87 | } | ||
88 | |||
89 | - if (job->sync_mode == MIRROR_SYNC_MODE_TOP) { | ||
90 | + if (s->sync_mode == MIRROR_SYNC_MODE_TOP) { | ||
91 | int i; | ||
92 | int64_t n; | ||
93 | |||
94 | /* Check to see if these blocks are already in the | ||
95 | * backing file. */ | ||
96 | |||
97 | - for (i = 0; i < job->cluster_size;) { | ||
98 | + for (i = 0; i < s->cluster_size;) { | ||
99 | /* bdrv_is_allocated() only returns true/false based | ||
100 | * on the first set of sectors it comes across that | ||
101 | * are are all in the same state. | ||
102 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
103 | * needed but at some point that is always the case. */ | ||
104 | alloced = | ||
105 | bdrv_is_allocated(bs, offset + i, | ||
106 | - job->cluster_size - i, &n); | ||
107 | + s->cluster_size - i, &n); | ||
108 | i += n; | ||
109 | |||
110 | if (alloced || n == 0) { | ||
111 | @@ -XXX,XX +XXX,XX @@ static int coroutine_fn backup_run(Job *opaque_job, Error **errp) | ||
112 | if (alloced < 0) { | ||
113 | ret = alloced; | ||
114 | } else { | ||
115 | - ret = backup_do_cow(job, offset, job->cluster_size, | ||
116 | + ret = backup_do_cow(s, offset, s->cluster_size, | ||
117 | &error_is_read, false); | ||
118 | } | ||
119 | if (ret < 0) { | ||
120 | /* Depending on error action, fail now or retry cluster */ | ||
121 | BlockErrorAction action = | ||
122 | - backup_error_action(job, error_is_read, -ret); | ||
123 | + backup_error_action(s, error_is_read, -ret); | ||
124 | if (action == BLOCK_ERROR_ACTION_REPORT) { | ||
125 | break; | ||
126 | } else { | ||
127 | - offset -= job->cluster_size; | ||
128 | + offset -= s->cluster_size; | ||
129 | continue; | ||
130 | } | ||
131 | } | ||
132 | } | ||
33 | } | 133 | } |
34 | diff --git a/hw/i386/trace-events b/hw/i386/trace-events | 134 | |
35 | index XXXXXXX..XXXXXXX 100644 | 135 | - notifier_with_return_remove(&job->before_write); |
36 | --- a/hw/i386/trace-events | 136 | + notifier_with_return_remove(&s->before_write); |
37 | +++ b/hw/i386/trace-events | 137 | |
38 | @@ -XXX,XX +XXX,XX @@ vtd_fault_disabled(void) "Fault processing disabled for context entry" | 138 | /* wait until pending backup_do_cow() calls have completed */ |
39 | vtd_replay_ce_valid(const char *mode, uint8_t bus, uint8_t dev, uint8_t fn, uint16_t domain, uint64_t hi, uint64_t lo) "%s: replay valid context device %02"PRIx8":%02"PRIx8".%02"PRIx8" domain 0x%"PRIx16" hi 0x%"PRIx64" lo 0x%"PRIx64 | 139 | - qemu_co_rwlock_wrlock(&job->flush_rwlock); |
40 | vtd_replay_ce_invalid(uint8_t bus, uint8_t dev, uint8_t fn) "replay invalid context device %02"PRIx8":%02"PRIx8".%02"PRIx8 | 140 | - qemu_co_rwlock_unlock(&job->flush_rwlock); |
41 | vtd_page_walk_level(uint64_t addr, uint32_t level, uint64_t start, uint64_t end) "walk (base=0x%"PRIx64", level=%"PRIu32") iova range 0x%"PRIx64" - 0x%"PRIx64 | 141 | - hbitmap_free(job->copy_bitmap); |
42 | -vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "domain 0x%"PRIu16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d" | 142 | + qemu_co_rwlock_wrlock(&s->flush_rwlock); |
43 | +vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "domain 0x%"PRIx16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d" | 143 | + qemu_co_rwlock_unlock(&s->flush_rwlock); |
44 | vtd_page_walk_one_skip_map(uint64_t iova, uint64_t mask, uint64_t translated) "iova 0x%"PRIx64" mask 0x%"PRIx64" translated 0x%"PRIx64 | 144 | + hbitmap_free(s->copy_bitmap); |
45 | vtd_page_walk_one_skip_unmap(uint64_t iova, uint64_t mask) "iova 0x%"PRIx64" mask 0x%"PRIx64 | 145 | |
46 | vtd_page_walk_skip_read(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to unable to read" | 146 | return ret; |
47 | vtd_page_walk_skip_reserve(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to rsrv set" | 147 | } |
48 | vtd_switch_address_space(uint8_t bus, uint8_t slot, uint8_t fn, bool on) "Device %02x:%02x.%x switching address space (iommu enabled=%d)" | ||
49 | vtd_as_unmap_whole(uint8_t bus, uint8_t slot, uint8_t fn, uint64_t iova, uint64_t size) "Device %02x:%02x.%x start 0x%"PRIx64" size 0x%"PRIx64 | ||
50 | -vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIu16", iova 0x%"PRIx64 | ||
51 | -vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIu16" %d" | ||
52 | +vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIx16", iova 0x%"PRIx64 | ||
53 | +vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIx16" %d" | ||
54 | vtd_irq_generate(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" data 0x%"PRIx64 | ||
55 | vtd_reg_read(uint64_t addr, uint64_t size) "addr 0x%"PRIx64" size 0x%"PRIx64 | ||
56 | vtd_reg_write(uint64_t addr, uint64_t size, uint64_t val) "addr 0x%"PRIx64" size 0x%"PRIx64" value 0x%"PRIx64 | ||
57 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/misc/trace-events | ||
60 | +++ b/hw/misc/trace-events | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | # See docs/devel/tracing.rst for syntax documentation. | ||
63 | |||
64 | # allwinner-cpucfg.c | ||
65 | -allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32 | ||
66 | +allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIx32 | ||
67 | allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 | ||
68 | allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32 | ||
69 | |||
70 | @@ -XXX,XX +XXX,XX @@ imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" PRIx64 "value 0x%08 | ||
71 | |||
72 | # mos6522.c | ||
73 | mos6522_set_counter(int index, unsigned int val) "T%d.counter=%d" | ||
74 | -mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d counter=0x%"PRId64 " delta_next=0x%"PRId64 | ||
75 | +mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d counter=0x%"PRIx64 " delta_next=0x%"PRIx64 | ||
76 | mos6522_set_sr_int(void) "set sr_int" | ||
77 | mos6522_write(uint64_t addr, const char *name, uint64_t val) "reg=0x%"PRIx64 " [%s] val=0x%"PRIx64 | ||
78 | mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " [%s] val=0x%x" | ||
79 | diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/hw/scsi/trace-events | ||
82 | +++ b/hw/scsi/trace-events | ||
83 | @@ -XXX,XX +XXX,XX @@ lsi_bad_phase_interrupt(void) "Phase mismatch interrupt" | ||
84 | lsi_bad_selection(uint32_t id) "Selected absent target %"PRIu32 | ||
85 | lsi_do_dma_unavailable(void) "DMA no data available" | ||
86 | lsi_do_dma(uint64_t addr, int len) "DMA addr=0x%"PRIx64" len=%d" | ||
87 | -lsi_queue_command(uint32_t tag) "Queueing tag=0x%"PRId32 | ||
88 | +lsi_queue_command(uint32_t tag) "Queueing tag=0x%"PRIx32 | ||
89 | lsi_add_msg_byte_error(void) "MSG IN data too long" | ||
90 | lsi_add_msg_byte(uint8_t data) "MSG IN 0x%02x" | ||
91 | lsi_reselect(int id) "Reselected target %d" | ||
92 | @@ -XXX,XX +XXX,XX @@ lsi_do_msgout_noop(void) "MSG: No Operation" | ||
93 | lsi_do_msgout_extended(uint8_t msg, uint8_t len) "Extended message 0x%x (len %d)" | ||
94 | lsi_do_msgout_ignored(const char *msg) "%s (ignored)" | ||
95 | lsi_do_msgout_simplequeue(uint8_t select_tag) "SIMPLE queue tag=0x%x" | ||
96 | -lsi_do_msgout_abort(uint32_t tag) "MSG: ABORT TAG tag=0x%"PRId32 | ||
97 | +lsi_do_msgout_abort(uint32_t tag) "MSG: ABORT TAG tag=0x%"PRIx32 | ||
98 | lsi_do_msgout_clearqueue(uint32_t tag) "MSG: CLEAR QUEUE tag=0x%"PRIx32 | ||
99 | lsi_do_msgout_busdevicereset(uint32_t tag) "MSG: BUS DEVICE RESET tag=0x%"PRIx32 | ||
100 | lsi_do_msgout_select(int id) "Select LUN %d" | ||
101 | -- | 148 | -- |
102 | 2.35.1 | 149 | 2.17.1 |
103 | 150 | ||
104 | 151 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Jobs are now expected to return their retcode on the stack, from the | ||
4 | .run callback, so we can remove that argument. | ||
5 | |||
6 | job_cancel does not need to set -ECANCELED because job_completed will | ||
7 | update the return code itself if the job was canceled. | ||
8 | |||
9 | While we're here, make job_completed static to job.c and remove it from | ||
10 | job.h; move the documentation of return code to the .run() callback and | ||
11 | to the job->ret property, accordingly. | ||
12 | |||
13 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
14 | Message-id: 20180830015734.19765-9-jsnow@redhat.com | ||
15 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
16 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
17 | --- | ||
18 | include/qemu/job.h | 28 +++++++++++++++------------- | ||
19 | job.c | 11 ++++++----- | ||
20 | trace-events | 2 +- | ||
21 | 3 files changed, 22 insertions(+), 19 deletions(-) | ||
22 | |||
23 | diff --git a/include/qemu/job.h b/include/qemu/job.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/qemu/job.h | ||
26 | +++ b/include/qemu/job.h | ||
27 | @@ -XXX,XX +XXX,XX @@ typedef struct Job { | ||
28 | /** Estimated progress_current value at the completion of the job */ | ||
29 | int64_t progress_total; | ||
30 | |||
31 | - /** ret code passed to job_completed. */ | ||
32 | + /** | ||
33 | + * Return code from @run and/or @prepare callback(s). | ||
34 | + * Not final until the job has reached the CONCLUDED status. | ||
35 | + * 0 on success, -errno on failure. | ||
36 | + */ | ||
37 | int ret; | ||
38 | |||
39 | /** | ||
40 | @@ -XXX,XX +XXX,XX @@ struct JobDriver { | ||
41 | /** Enum describing the operation */ | ||
42 | JobType job_type; | ||
43 | |||
44 | - /** Mandatory: Entrypoint for the Coroutine. */ | ||
45 | + /** | ||
46 | + * Mandatory: Entrypoint for the Coroutine. | ||
47 | + * | ||
48 | + * This callback will be invoked when moving from CREATED to RUNNING. | ||
49 | + * | ||
50 | + * If this callback returns nonzero, the job transaction it is part of is | ||
51 | + * aborted. If it returns zero, the job moves into the WAITING state. If it | ||
52 | + * is the last job to complete in its transaction, all jobs in the | ||
53 | + * transaction move from WAITING to PENDING. | ||
54 | + */ | ||
55 | int coroutine_fn (*run)(Job *job, Error **errp); | ||
56 | |||
57 | /** | ||
58 | @@ -XXX,XX +XXX,XX @@ void job_early_fail(Job *job); | ||
59 | /** Moves the @job from RUNNING to READY */ | ||
60 | void job_transition_to_ready(Job *job); | ||
61 | |||
62 | -/** | ||
63 | - * @job: The job being completed. | ||
64 | - * @ret: The status code. | ||
65 | - * | ||
66 | - * Marks @job as completed. If @ret is non-zero, the job transaction it is part | ||
67 | - * of is aborted. If @ret is zero, the job moves into the WAITING state. If it | ||
68 | - * is the last job to complete in its transaction, all jobs in the transaction | ||
69 | - * move from WAITING to PENDING. | ||
70 | - */ | ||
71 | -void job_completed(Job *job, int ret); | ||
72 | - | ||
73 | /** Asynchronously complete the specified @job. */ | ||
74 | void job_complete(Job *job, Error **errp); | ||
75 | |||
76 | diff --git a/job.c b/job.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/job.c | ||
79 | +++ b/job.c | ||
80 | @@ -XXX,XX +XXX,XX @@ void job_drain(Job *job) | ||
81 | } | ||
82 | } | ||
83 | |||
84 | +static void job_completed(Job *job); | ||
85 | + | ||
86 | static void job_exit(void *opaque) | ||
87 | { | ||
88 | Job *job = (Job *)opaque; | ||
89 | @@ -XXX,XX +XXX,XX @@ static void job_exit(void *opaque) | ||
90 | job->driver->exit(job); | ||
91 | aio_context_release(aio_context); | ||
92 | } | ||
93 | - job_completed(job, job->ret); | ||
94 | + job_completed(job); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | @@ -XXX,XX +XXX,XX @@ static void job_completed_txn_success(Job *job) | ||
99 | } | ||
100 | } | ||
101 | |||
102 | -void job_completed(Job *job, int ret) | ||
103 | +static void job_completed(Job *job) | ||
104 | { | ||
105 | assert(job && job->txn && !job_is_completed(job)); | ||
106 | |||
107 | - job->ret = ret; | ||
108 | job_update_rc(job); | ||
109 | - trace_job_completed(job, ret, job->ret); | ||
110 | + trace_job_completed(job, job->ret); | ||
111 | if (job->ret) { | ||
112 | job_completed_txn_abort(job); | ||
113 | } else { | ||
114 | @@ -XXX,XX +XXX,XX @@ void job_cancel(Job *job, bool force) | ||
115 | } | ||
116 | job_cancel_async(job, force); | ||
117 | if (!job_started(job)) { | ||
118 | - job_completed(job, -ECANCELED); | ||
119 | + job_completed(job); | ||
120 | } else if (job->deferred_to_main_loop) { | ||
121 | job_completed_txn_abort(job); | ||
122 | } else { | ||
123 | diff --git a/trace-events b/trace-events | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/trace-events | ||
126 | +++ b/trace-events | ||
127 | @@ -XXX,XX +XXX,XX @@ gdbstub_err_checksum_incorrect(uint8_t expected, uint8_t got) "got command packe | ||
128 | # job.c | ||
129 | job_state_transition(void *job, int ret, const char *legal, const char *s0, const char *s1) "job %p (ret: %d) attempting %s transition (%s-->%s)" | ||
130 | job_apply_verb(void *job, const char *state, const char *verb, const char *legal) "job %p in state %s; applying verb %s (%s)" | ||
131 | -job_completed(void *job, int ret, int jret) "job %p ret %d corrected ret %d" | ||
132 | +job_completed(void *job, int ret) "job %p ret %d" | ||
133 | |||
134 | # job-qmp.c | ||
135 | qmp_job_cancel(void *job) "job %p" | ||
136 | -- | ||
137 | 2.17.1 | ||
138 | |||
139 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: John Snow <jsnow@redhat.com> | ||
1 | 2 | ||
3 | Now that the job infrastructure is handling the job_completed call for | ||
4 | all implemented jobs, we can remove the interface that allowed jobs to | ||
5 | schedule their own completion. | ||
6 | |||
7 | Signed-off-by: John Snow <jsnow@redhat.com> | ||
8 | Reviewed-by: Max Reitz <mreitz@redhat.com> | ||
9 | Message-id: 20180830015734.19765-10-jsnow@redhat.com | ||
10 | Signed-off-by: Max Reitz <mreitz@redhat.com> | ||
11 | --- | ||
12 | include/qemu/job.h | 17 ----------------- | ||
13 | job.c | 40 ++-------------------------------------- | ||
14 | 2 files changed, 2 insertions(+), 55 deletions(-) | ||
15 | |||
16 | diff --git a/include/qemu/job.h b/include/qemu/job.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/qemu/job.h | ||
19 | +++ b/include/qemu/job.h | ||
20 | @@ -XXX,XX +XXX,XX @@ void job_finalize(Job *job, Error **errp); | ||
21 | */ | ||
22 | void job_dismiss(Job **job, Error **errp); | ||
23 | |||
24 | -typedef void JobDeferToMainLoopFn(Job *job, void *opaque); | ||
25 | - | ||
26 | -/** | ||
27 | - * @job: The job | ||
28 | - * @fn: The function to run in the main loop | ||
29 | - * @opaque: The opaque value that is passed to @fn | ||
30 | - * | ||
31 | - * This function must be called by the main job coroutine just before it | ||
32 | - * returns. @fn is executed in the main loop with the job AioContext acquired. | ||
33 | - * | ||
34 | - * Block jobs must call bdrv_unref(), bdrv_close(), and anything that uses | ||
35 | - * bdrv_drain_all() in the main loop. | ||
36 | - * | ||
37 | - * The @job AioContext is held while @fn executes. | ||
38 | - */ | ||
39 | -void job_defer_to_main_loop(Job *job, JobDeferToMainLoopFn *fn, void *opaque); | ||
40 | - | ||
41 | /** | ||
42 | * Synchronously finishes the given @job. If @finish is given, it is called to | ||
43 | * trigger completion or cancellation of the job. | ||
44 | diff --git a/job.c b/job.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/job.c | ||
47 | +++ b/job.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void coroutine_fn job_co_entry(void *opaque) | ||
49 | assert(job && job->driver && job->driver->run); | ||
50 | job_pause_point(job); | ||
51 | job->ret = job->driver->run(job, &job->err); | ||
52 | - if (!job->deferred_to_main_loop) { | ||
53 | - job->deferred_to_main_loop = true; | ||
54 | - aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
55 | - job_exit, | ||
56 | - job); | ||
57 | - } | ||
58 | + job->deferred_to_main_loop = true; | ||
59 | + aio_bh_schedule_oneshot(qemu_get_aio_context(), job_exit, job); | ||
60 | } | ||
61 | |||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ void job_complete(Job *job, Error **errp) | ||
64 | job->driver->complete(job, errp); | ||
65 | } | ||
66 | |||
67 | - | ||
68 | -typedef struct { | ||
69 | - Job *job; | ||
70 | - JobDeferToMainLoopFn *fn; | ||
71 | - void *opaque; | ||
72 | -} JobDeferToMainLoopData; | ||
73 | - | ||
74 | -static void job_defer_to_main_loop_bh(void *opaque) | ||
75 | -{ | ||
76 | - JobDeferToMainLoopData *data = opaque; | ||
77 | - Job *job = data->job; | ||
78 | - AioContext *aio_context = job->aio_context; | ||
79 | - | ||
80 | - aio_context_acquire(aio_context); | ||
81 | - data->fn(data->job, data->opaque); | ||
82 | - aio_context_release(aio_context); | ||
83 | - | ||
84 | - g_free(data); | ||
85 | -} | ||
86 | - | ||
87 | -void job_defer_to_main_loop(Job *job, JobDeferToMainLoopFn *fn, void *opaque) | ||
88 | -{ | ||
89 | - JobDeferToMainLoopData *data = g_malloc(sizeof(*data)); | ||
90 | - data->job = job; | ||
91 | - data->fn = fn; | ||
92 | - data->opaque = opaque; | ||
93 | - job->deferred_to_main_loop = true; | ||
94 | - | ||
95 | - aio_bh_schedule_oneshot(qemu_get_aio_context(), | ||
96 | - job_defer_to_main_loop_bh, data); | ||
97 | -} | ||
98 | - | ||
99 | int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp) | ||
100 | { | ||
101 | Error *local_err = NULL; | ||
102 | -- | ||
103 | 2.17.1 | ||
104 | |||
105 | diff view generated by jsdifflib |