diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2016-07-04 19:10:01 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2016-07-13 13:26:02 +0200 |
commit | 0b8b8753e4d94901627b3e86431230f2319215c4 (patch) | |
tree | f258eafcb1b3ad4fc50434de2ba4e622de9fc353 /block | |
parent | 7e70cdba9f220bef3f3481c663c066c2b80469aa (diff) |
coroutine: move entry argument to qemu_coroutine_create
In practice the entry argument is always known at creation time, and
it is confusing that sometimes qemu_coroutine_enter is used with a
non-NULL argument to re-enter a coroutine (this happens in
block/sheepdog.c and tests/test-coroutine.c). So pass the opaque value
at creation time, for consistency with e.g. aio_bh_new.
Mostly done with the following semantic patch:
@ entry1 @
expression entry, arg, co;
@@
- co = qemu_coroutine_create(entry);
+ co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry2 @
expression entry, arg;
identifier co;
@@
- Coroutine *co = qemu_coroutine_create(entry);
+ Coroutine *co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry3 @
expression entry, arg;
@@
- qemu_coroutine_enter(qemu_coroutine_create(entry), arg);
+ qemu_coroutine_enter(qemu_coroutine_create(entry, arg));
@ reentry @
expression co;
@@
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
except for the aforementioned few places where the semantic patch
stumbled (as expected) and for test_co_queue, which would otherwise
produce an uninitialized variable warning.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/backup.c | 4 | ||||
-rw-r--r-- | block/blkdebug.c | 4 | ||||
-rwxr-xr-x | block/blkreplay.c | 2 | ||||
-rw-r--r-- | block/block-backend.c | 8 | ||||
-rw-r--r-- | block/commit.c | 4 | ||||
-rw-r--r-- | block/gluster.c | 2 | ||||
-rw-r--r-- | block/io.c | 45 | ||||
-rw-r--r-- | block/iscsi.c | 4 | ||||
-rw-r--r-- | block/linux-aio.c | 2 | ||||
-rw-r--r-- | block/mirror.c | 6 | ||||
-rw-r--r-- | block/nbd-client.c | 6 | ||||
-rw-r--r-- | block/nfs.c | 2 | ||||
-rw-r--r-- | block/qcow.c | 4 | ||||
-rw-r--r-- | block/qcow2.c | 4 | ||||
-rw-r--r-- | block/qed.c | 4 | ||||
-rw-r--r-- | block/sheepdog.c | 14 | ||||
-rw-r--r-- | block/ssh.c | 2 | ||||
-rw-r--r-- | block/stream.c | 4 | ||||
-rw-r--r-- | block/vmdk.c | 4 |
19 files changed, 63 insertions, 62 deletions
diff --git a/block/backup.c b/block/backup.c index dce66142f3..2c0532314f 100644 --- a/block/backup.c +++ b/block/backup.c @@ -576,9 +576,9 @@ void backup_start(const char *job_id, BlockDriverState *bs, bdrv_op_block_all(target, job->common.blocker); job->common.len = len; - job->common.co = qemu_coroutine_create(backup_run); + job->common.co = qemu_coroutine_create(backup_run, job); block_job_txn_add_job(txn, &job->common); - qemu_coroutine_enter(job->common.co, job); + qemu_coroutine_enter(job->common.co); return; error: diff --git a/block/blkdebug.c b/block/blkdebug.c index bbaa33fdd8..fb29283f80 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -621,7 +621,7 @@ static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag) QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) { if (!strcmp(r->tag, tag)) { - qemu_coroutine_enter(r->co, NULL); + qemu_coroutine_enter(r->co); return 0; } } @@ -647,7 +647,7 @@ static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs, } QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) { if (!strcmp(r->tag, tag)) { - qemu_coroutine_enter(r->co, NULL); + qemu_coroutine_enter(r->co); ret = 0; } } diff --git a/block/blkreplay.c b/block/blkreplay.c index 70650e4be1..3368c8c98d 100755 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -65,7 +65,7 @@ static int64_t blkreplay_getlength(BlockDriverState *bs) static void blkreplay_bh_cb(void *opaque) { Request *req = opaque; - qemu_coroutine_enter(req->co, NULL); + qemu_coroutine_enter(req->co); qemu_bh_delete(req->bh); g_free(req); } diff --git a/block/block-backend.c b/block/block-backend.c index a862f6577b..0d7b801107 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -836,8 +836,8 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf, .ret = NOT_DONE, }; - co = qemu_coroutine_create(co_entry); - qemu_coroutine_enter(co, &rwco); + co = qemu_coroutine_create(co_entry, &rwco); + qemu_coroutine_enter(co); aio_context = blk_get_aio_context(blk); while (rwco.ret == NOT_DONE) { @@ -950,8 +950,8 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes, acb->bh = NULL; acb->has_returned = false; - co = qemu_coroutine_create(co_entry); - qemu_coroutine_enter(co, acb); + co = qemu_coroutine_create(co_entry, acb); + qemu_coroutine_enter(co); acb->has_returned = true; if (acb->rwco.ret != NOT_DONE) { diff --git a/block/commit.c b/block/commit.c index 23368fa65b..8b534d7c95 100644 --- a/block/commit.c +++ b/block/commit.c @@ -278,10 +278,10 @@ void commit_start(const char *job_id, BlockDriverState *bs, s->backing_file_str = g_strdup(backing_file_str); s->on_error = on_error; - s->common.co = qemu_coroutine_create(commit_run); + s->common.co = qemu_coroutine_create(commit_run, s); trace_commit_start(bs, base, top, s, s->common.co, opaque); - qemu_coroutine_enter(s->common.co, s); + qemu_coroutine_enter(s->common.co); } diff --git a/block/gluster.c b/block/gluster.c index 16f7778a50..406c1e6357 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -233,7 +233,7 @@ static void qemu_gluster_complete_aio(void *opaque) qemu_bh_delete(acb->bh); acb->bh = NULL; - qemu_coroutine_enter(acb->coroutine, NULL); + qemu_coroutine_enter(acb->coroutine); } /* diff --git a/block/io.c b/block/io.c index 708690898f..2887394633 100644 --- a/block/io.c +++ b/block/io.c @@ -195,7 +195,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) qemu_bh_delete(data->bh); bdrv_drain_poll(data->bs); data->done = true; - qemu_coroutine_enter(co, NULL); + qemu_coroutine_enter(co); } static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) @@ -599,8 +599,8 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset, } else { AioContext *aio_context = bdrv_get_aio_context(child->bs); - co = qemu_coroutine_create(bdrv_rw_co_entry); - qemu_coroutine_enter(co, &rwco); + co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco); + qemu_coroutine_enter(co); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } @@ -799,7 +799,7 @@ static void bdrv_co_io_em_complete(void *opaque, int ret) CoroutineIOCompletion *co = opaque; co->ret = ret; - qemu_coroutine_enter(co->coroutine, NULL); + qemu_coroutine_enter(co->coroutine); } static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, @@ -1752,8 +1752,9 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs, } else { AioContext *aio_context = bdrv_get_aio_context(bs); - co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry); - qemu_coroutine_enter(co, &data); + co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry, + &data); + qemu_coroutine_enter(co); while (!data.done) { aio_poll(aio_context, true); } @@ -1901,9 +1902,9 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, .is_read = is_read, .ret = -EINPROGRESS, }; - Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry); + Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data); - qemu_coroutine_enter(co, &data); + qemu_coroutine_enter(co); while (data.ret == -EINPROGRESS) { aio_poll(bdrv_get_aio_context(bs), true); } @@ -2113,8 +2114,8 @@ static BlockAIOCB *bdrv_co_aio_rw_vector(BdrvChild *child, acb->req.flags = flags; acb->is_write = is_write; - co = qemu_coroutine_create(bdrv_co_do_rw); - qemu_coroutine_enter(co, acb); + co = qemu_coroutine_create(bdrv_co_do_rw, acb); + qemu_coroutine_enter(co); bdrv_co_maybe_schedule_bh(acb); return &acb->common; @@ -2141,8 +2142,8 @@ BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs, acb->need_bh = true; acb->req.error = -EINPROGRESS; - co = qemu_coroutine_create(bdrv_aio_flush_co_entry); - qemu_coroutine_enter(co, acb); + co = qemu_coroutine_create(bdrv_aio_flush_co_entry, acb); + qemu_coroutine_enter(co); bdrv_co_maybe_schedule_bh(acb); return &acb->common; @@ -2171,8 +2172,8 @@ BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs, acb->req.error = -EINPROGRESS; acb->req.sector = sector_num; acb->req.nb_sectors = nb_sectors; - co = qemu_coroutine_create(bdrv_aio_discard_co_entry); - qemu_coroutine_enter(co, acb); + co = qemu_coroutine_create(bdrv_aio_discard_co_entry, acb); + qemu_coroutine_enter(co); bdrv_co_maybe_schedule_bh(acb); return &acb->common; @@ -2313,8 +2314,8 @@ int bdrv_flush(BlockDriverState *bs) } else { AioContext *aio_context = bdrv_get_aio_context(bs); - co = qemu_coroutine_create(bdrv_flush_co_entry); - qemu_coroutine_enter(co, &flush_co); + co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co); + qemu_coroutine_enter(co); while (flush_co.ret == NOT_DONE) { aio_poll(aio_context, true); } @@ -2442,8 +2443,8 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) } else { AioContext *aio_context = bdrv_get_aio_context(bs); - co = qemu_coroutine_create(bdrv_discard_co_entry); - qemu_coroutine_enter(co, &rwco); + co = qemu_coroutine_create(bdrv_discard_co_entry, &rwco); + qemu_coroutine_enter(co); while (rwco.ret == NOT_DONE) { aio_poll(aio_context, true); } @@ -2505,9 +2506,9 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) /* Fast-path if already in coroutine context */ bdrv_co_ioctl_entry(&data); } else { - Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry); + Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry, &data); - qemu_coroutine_enter(co, &data); + qemu_coroutine_enter(co); while (data.ret == -EINPROGRESS) { aio_poll(bdrv_get_aio_context(bs), true); } @@ -2535,8 +2536,8 @@ BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, acb->req.error = -EINPROGRESS; acb->req.req = req; acb->req.buf = buf; - co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry); - qemu_coroutine_enter(co, acb); + co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry, acb); + qemu_coroutine_enter(co); bdrv_co_maybe_schedule_bh(acb); return &acb->common; diff --git a/block/iscsi.c b/block/iscsi.c index 434cb37107..cf1e9e7f66 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -152,7 +152,7 @@ static void iscsi_co_generic_bh_cb(void *opaque) struct IscsiTask *iTask = opaque; iTask->complete = 1; qemu_bh_delete(iTask->bh); - qemu_coroutine_enter(iTask->co, NULL); + qemu_coroutine_enter(iTask->co); } static void iscsi_retry_timer_expired(void *opaque) @@ -160,7 +160,7 @@ static void iscsi_retry_timer_expired(void *opaque) struct IscsiTask *iTask = opaque; iTask->complete = 1; if (iTask->co) { - qemu_coroutine_enter(iTask->co, NULL); + qemu_coroutine_enter(iTask->co); } } diff --git a/block/linux-aio.c b/block/linux-aio.c index 7df8651581..5c104bd3cd 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -94,7 +94,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb) laiocb->ret = ret; if (laiocb->co) { - qemu_coroutine_enter(laiocb->co, NULL); + qemu_coroutine_enter(laiocb->co); } else { laiocb->common.cb(laiocb->common.opaque, ret); qemu_aio_unref(laiocb); diff --git a/block/mirror.c b/block/mirror.c index 705fbc0052..71e5ad4377 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -121,7 +121,7 @@ static void mirror_iteration_done(MirrorOp *op, int ret) g_free(op); if (s->waiting_for_io) { - qemu_coroutine_enter(s->common.co, NULL); + qemu_coroutine_enter(s->common.co); } } @@ -901,9 +901,9 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs, bdrv_op_block_all(target, s->common.blocker); - s->common.co = qemu_coroutine_create(mirror_run); + s->common.co = qemu_coroutine_create(mirror_run, s); trace_mirror_start(bs, s, s->common.co, opaque); - qemu_coroutine_enter(s->common.co, s); + qemu_coroutine_enter(s->common.co); } void mirror_start(const char *job_id, BlockDriverState *bs, diff --git a/block/nbd-client.c b/block/nbd-client.c index 420bce89f3..4cc408d206 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -38,7 +38,7 @@ static void nbd_recv_coroutines_enter_all(NbdClientSession *s) for (i = 0; i < MAX_NBD_REQUESTS; i++) { if (s->recv_coroutine[i]) { - qemu_coroutine_enter(s->recv_coroutine[i], NULL); + qemu_coroutine_enter(s->recv_coroutine[i]); } } } @@ -99,7 +99,7 @@ static void nbd_reply_ready(void *opaque) } if (s->recv_coroutine[i]) { - qemu_coroutine_enter(s->recv_coroutine[i], NULL); + qemu_coroutine_enter(s->recv_coroutine[i]); return; } @@ -111,7 +111,7 @@ static void nbd_restart_write(void *opaque) { BlockDriverState *bs = opaque; - qemu_coroutine_enter(nbd_get_client_session(bs)->send_coroutine, NULL); + qemu_coroutine_enter(nbd_get_client_session(bs)->send_coroutine); } static int nbd_co_send_request(BlockDriverState *bs, diff --git a/block/nfs.c b/block/nfs.c index 15d6832c4c..8602a44211 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -104,7 +104,7 @@ static void nfs_co_generic_bh_cb(void *opaque) NFSRPC *task = opaque; task->complete = 1; qemu_bh_delete(task->bh); - qemu_coroutine_enter(task->co, NULL); + qemu_coroutine_enter(task->co); } static void diff --git a/block/qcow.c b/block/qcow.c index ac849bd47c..0c7b75bc76 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -948,8 +948,8 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num, .nb_sectors = nb_sectors, .ret = -EINPROGRESS, }; - co = qemu_coroutine_create(qcow_write_co_entry); - qemu_coroutine_enter(co, &data); + co = qemu_coroutine_create(qcow_write_co_entry, &data); + qemu_coroutine_enter(co); while (data.ret == -EINPROGRESS) { aio_poll(aio_context, true); } diff --git a/block/qcow2.c b/block/qcow2.c index a5ea19b0b6..a6bca735e5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2570,8 +2570,8 @@ static int qcow2_write(BlockDriverState *bs, int64_t sector_num, .nb_sectors = nb_sectors, .ret = -EINPROGRESS, }; - co = qemu_coroutine_create(qcow2_write_co_entry); - qemu_coroutine_enter(co, &data); + co = qemu_coroutine_create(qcow2_write_co_entry, &data); + qemu_coroutine_enter(co); while (data.ret == -EINPROGRESS) { aio_poll(aio_context, true); } diff --git a/block/qed.c b/block/qed.c index f619d82c6e..426f3cb447 100644 --- a/block/qed.c +++ b/block/qed.c @@ -708,7 +708,7 @@ static void qed_is_allocated_cb(void *opaque, int ret, uint64_t offset, size_t l } if (cb->co) { - qemu_coroutine_enter(cb->co, NULL); + qemu_coroutine_enter(cb->co); } } @@ -1425,7 +1425,7 @@ static void coroutine_fn qed_co_pwrite_zeroes_cb(void *opaque, int ret) cb->done = true; cb->ret = ret; if (cb->co) { - qemu_coroutine_enter(cb->co, NULL); + qemu_coroutine_enter(cb->co); } } diff --git a/block/sheepdog.c b/block/sheepdog.c index ef5d044ab9..e739c56f08 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -495,7 +495,7 @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) static void coroutine_fn sd_finish_aiocb(SheepdogAIOCB *acb) { - qemu_coroutine_enter(acb->coroutine, NULL); + qemu_coroutine_enter(acb->coroutine); qemu_aio_unref(acb); } @@ -636,7 +636,7 @@ static void restart_co_req(void *opaque) { Coroutine *co = opaque; - qemu_coroutine_enter(co, NULL); + qemu_coroutine_enter(co); } typedef struct SheepdogReqCo { @@ -726,8 +726,8 @@ static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr, if (qemu_in_coroutine()) { do_co_req(&srco); } else { - co = qemu_coroutine_create(do_co_req); - qemu_coroutine_enter(co, &srco); + co = qemu_coroutine_create(do_co_req, &srco); + qemu_coroutine_enter(co); while (!srco.finished) { aio_poll(aio_context, true); } @@ -925,17 +925,17 @@ static void co_read_response(void *opaque) BDRVSheepdogState *s = opaque; if (!s->co_recv) { - s->co_recv = qemu_coroutine_create(aio_read_response); + s->co_recv = qemu_coroutine_create(aio_read_response, opaque); } - qemu_coroutine_enter(s->co_recv, opaque); + qemu_coroutine_enter(s->co_recv); } static void co_write_request(void *opaque) { BDRVSheepdogState *s = opaque; - qemu_coroutine_enter(s->co_send, NULL); + qemu_coroutine_enter(s->co_send); } /* diff --git a/block/ssh.c b/block/ssh.c index 06928ed939..bcbb0e4223 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -777,7 +777,7 @@ static void restart_coroutine(void *opaque) DPRINTF("co=%p", co); - qemu_coroutine_enter(co, NULL); + qemu_coroutine_enter(co); } static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs) diff --git a/block/stream.c b/block/stream.c index 54c8cd8f57..2e7c6547d2 100644 --- a/block/stream.c +++ b/block/stream.c @@ -235,7 +235,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->backing_file_str = g_strdup(backing_file_str); s->on_error = on_error; - s->common.co = qemu_coroutine_create(stream_run); + s->common.co = qemu_coroutine_create(stream_run, s); trace_stream_start(bs, base, s, s->common.co, opaque); - qemu_coroutine_enter(s->common.co, s); + qemu_coroutine_enter(s->common.co); } diff --git a/block/vmdk.c b/block/vmdk.c index d73f4314ba..c9914f718f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1686,8 +1686,8 @@ static int vmdk_write_compressed(BlockDriverState *bs, .nb_sectors = nb_sectors, .ret = -EINPROGRESS, }; - co = qemu_coroutine_create(vmdk_co_write_compressed); - qemu_coroutine_enter(co, &data); + co = qemu_coroutine_create(vmdk_co_write_compressed, &data); + qemu_coroutine_enter(co); while (data.ret == -EINPROGRESS) { aio_poll(aio_context, true); } |