Skip to content

Commit 0b8b875

Browse files
bonzinikevmw
authored andcommitted
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>
1 parent 7e70cdb commit 0b8b875

37 files changed

+130
-131
lines changed

block.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ int bdrv_create(BlockDriver *drv, const char* filename,
329329
/* Fast-path if already in coroutine context */
330330
bdrv_create_co_entry(&cco);
331331
} else {
332-
co = qemu_coroutine_create(bdrv_create_co_entry);
333-
qemu_coroutine_enter(co, &cco);
332+
co = qemu_coroutine_create(bdrv_create_co_entry, &cco);
333+
qemu_coroutine_enter(co);
334334
while (cco.ret == NOT_DONE) {
335335
aio_poll(qemu_get_aio_context(), true);
336336
}

block/backup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@ void backup_start(const char *job_id, BlockDriverState *bs,
576576

577577
bdrv_op_block_all(target, job->common.blocker);
578578
job->common.len = len;
579-
job->common.co = qemu_coroutine_create(backup_run);
579+
job->common.co = qemu_coroutine_create(backup_run, job);
580580
block_job_txn_add_job(txn, &job->common);
581-
qemu_coroutine_enter(job->common.co, job);
581+
qemu_coroutine_enter(job->common.co);
582582
return;
583583

584584
error:

block/blkdebug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
621621

622622
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) {
623623
if (!strcmp(r->tag, tag)) {
624-
qemu_coroutine_enter(r->co, NULL);
624+
qemu_coroutine_enter(r->co);
625625
return 0;
626626
}
627627
}
@@ -647,7 +647,7 @@ static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
647647
}
648648
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) {
649649
if (!strcmp(r->tag, tag)) {
650-
qemu_coroutine_enter(r->co, NULL);
650+
qemu_coroutine_enter(r->co);
651651
ret = 0;
652652
}
653653
}

block/blkreplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int64_t blkreplay_getlength(BlockDriverState *bs)
6565
static void blkreplay_bh_cb(void *opaque)
6666
{
6767
Request *req = opaque;
68-
qemu_coroutine_enter(req->co, NULL);
68+
qemu_coroutine_enter(req->co);
6969
qemu_bh_delete(req->bh);
7070
g_free(req);
7171
}

block/block-backend.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf,
836836
.ret = NOT_DONE,
837837
};
838838

839-
co = qemu_coroutine_create(co_entry);
840-
qemu_coroutine_enter(co, &rwco);
839+
co = qemu_coroutine_create(co_entry, &rwco);
840+
qemu_coroutine_enter(co);
841841

842842
aio_context = blk_get_aio_context(blk);
843843
while (rwco.ret == NOT_DONE) {
@@ -950,8 +950,8 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
950950
acb->bh = NULL;
951951
acb->has_returned = false;
952952

953-
co = qemu_coroutine_create(co_entry);
954-
qemu_coroutine_enter(co, acb);
953+
co = qemu_coroutine_create(co_entry, acb);
954+
qemu_coroutine_enter(co);
955955

956956
acb->has_returned = true;
957957
if (acb->rwco.ret != NOT_DONE) {

block/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ void commit_start(const char *job_id, BlockDriverState *bs,
278278
s->backing_file_str = g_strdup(backing_file_str);
279279

280280
s->on_error = on_error;
281-
s->common.co = qemu_coroutine_create(commit_run);
281+
s->common.co = qemu_coroutine_create(commit_run, s);
282282

283283
trace_commit_start(bs, base, top, s, s->common.co, opaque);
284-
qemu_coroutine_enter(s->common.co, s);
284+
qemu_coroutine_enter(s->common.co);
285285
}
286286

287287

block/gluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void qemu_gluster_complete_aio(void *opaque)
233233

234234
qemu_bh_delete(acb->bh);
235235
acb->bh = NULL;
236-
qemu_coroutine_enter(acb->coroutine, NULL);
236+
qemu_coroutine_enter(acb->coroutine);
237237
}
238238

239239
/*

block/io.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static void bdrv_co_drain_bh_cb(void *opaque)
195195
qemu_bh_delete(data->bh);
196196
bdrv_drain_poll(data->bs);
197197
data->done = true;
198-
qemu_coroutine_enter(co, NULL);
198+
qemu_coroutine_enter(co);
199199
}
200200

201201
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,
599599
} else {
600600
AioContext *aio_context = bdrv_get_aio_context(child->bs);
601601

602-
co = qemu_coroutine_create(bdrv_rw_co_entry);
603-
qemu_coroutine_enter(co, &rwco);
602+
co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco);
603+
qemu_coroutine_enter(co);
604604
while (rwco.ret == NOT_DONE) {
605605
aio_poll(aio_context, true);
606606
}
@@ -799,7 +799,7 @@ static void bdrv_co_io_em_complete(void *opaque, int ret)
799799
CoroutineIOCompletion *co = opaque;
800800

801801
co->ret = ret;
802-
qemu_coroutine_enter(co->coroutine, NULL);
802+
qemu_coroutine_enter(co->coroutine);
803803
}
804804

805805
static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs,
@@ -1752,8 +1752,9 @@ int64_t bdrv_get_block_status_above(BlockDriverState *bs,
17521752
} else {
17531753
AioContext *aio_context = bdrv_get_aio_context(bs);
17541754

1755-
co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry);
1756-
qemu_coroutine_enter(co, &data);
1755+
co = qemu_coroutine_create(bdrv_get_block_status_above_co_entry,
1756+
&data);
1757+
qemu_coroutine_enter(co);
17571758
while (!data.done) {
17581759
aio_poll(aio_context, true);
17591760
}
@@ -1901,9 +1902,9 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
19011902
.is_read = is_read,
19021903
.ret = -EINPROGRESS,
19031904
};
1904-
Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry);
1905+
Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data);
19051906

1906-
qemu_coroutine_enter(co, &data);
1907+
qemu_coroutine_enter(co);
19071908
while (data.ret == -EINPROGRESS) {
19081909
aio_poll(bdrv_get_aio_context(bs), true);
19091910
}
@@ -2113,8 +2114,8 @@ static BlockAIOCB *bdrv_co_aio_rw_vector(BdrvChild *child,
21132114
acb->req.flags = flags;
21142115
acb->is_write = is_write;
21152116

2116-
co = qemu_coroutine_create(bdrv_co_do_rw);
2117-
qemu_coroutine_enter(co, acb);
2117+
co = qemu_coroutine_create(bdrv_co_do_rw, acb);
2118+
qemu_coroutine_enter(co);
21182119

21192120
bdrv_co_maybe_schedule_bh(acb);
21202121
return &acb->common;
@@ -2141,8 +2142,8 @@ BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs,
21412142
acb->need_bh = true;
21422143
acb->req.error = -EINPROGRESS;
21432144

2144-
co = qemu_coroutine_create(bdrv_aio_flush_co_entry);
2145-
qemu_coroutine_enter(co, acb);
2145+
co = qemu_coroutine_create(bdrv_aio_flush_co_entry, acb);
2146+
qemu_coroutine_enter(co);
21462147

21472148
bdrv_co_maybe_schedule_bh(acb);
21482149
return &acb->common;
@@ -2171,8 +2172,8 @@ BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs,
21712172
acb->req.error = -EINPROGRESS;
21722173
acb->req.sector = sector_num;
21732174
acb->req.nb_sectors = nb_sectors;
2174-
co = qemu_coroutine_create(bdrv_aio_discard_co_entry);
2175-
qemu_coroutine_enter(co, acb);
2175+
co = qemu_coroutine_create(bdrv_aio_discard_co_entry, acb);
2176+
qemu_coroutine_enter(co);
21762177

21772178
bdrv_co_maybe_schedule_bh(acb);
21782179
return &acb->common;
@@ -2313,8 +2314,8 @@ int bdrv_flush(BlockDriverState *bs)
23132314
} else {
23142315
AioContext *aio_context = bdrv_get_aio_context(bs);
23152316

2316-
co = qemu_coroutine_create(bdrv_flush_co_entry);
2317-
qemu_coroutine_enter(co, &flush_co);
2317+
co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co);
2318+
qemu_coroutine_enter(co);
23182319
while (flush_co.ret == NOT_DONE) {
23192320
aio_poll(aio_context, true);
23202321
}
@@ -2442,8 +2443,8 @@ int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
24422443
} else {
24432444
AioContext *aio_context = bdrv_get_aio_context(bs);
24442445

2445-
co = qemu_coroutine_create(bdrv_discard_co_entry);
2446-
qemu_coroutine_enter(co, &rwco);
2446+
co = qemu_coroutine_create(bdrv_discard_co_entry, &rwco);
2447+
qemu_coroutine_enter(co);
24472448
while (rwco.ret == NOT_DONE) {
24482449
aio_poll(aio_context, true);
24492450
}
@@ -2505,9 +2506,9 @@ int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
25052506
/* Fast-path if already in coroutine context */
25062507
bdrv_co_ioctl_entry(&data);
25072508
} else {
2508-
Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry);
2509+
Coroutine *co = qemu_coroutine_create(bdrv_co_ioctl_entry, &data);
25092510

2510-
qemu_coroutine_enter(co, &data);
2511+
qemu_coroutine_enter(co);
25112512
while (data.ret == -EINPROGRESS) {
25122513
aio_poll(bdrv_get_aio_context(bs), true);
25132514
}
@@ -2535,8 +2536,8 @@ BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
25352536
acb->req.error = -EINPROGRESS;
25362537
acb->req.req = req;
25372538
acb->req.buf = buf;
2538-
co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry);
2539-
qemu_coroutine_enter(co, acb);
2539+
co = qemu_coroutine_create(bdrv_co_aio_ioctl_entry, acb);
2540+
qemu_coroutine_enter(co);
25402541

25412542
bdrv_co_maybe_schedule_bh(acb);
25422543
return &acb->common;

block/iscsi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ static void iscsi_co_generic_bh_cb(void *opaque)
152152
struct IscsiTask *iTask = opaque;
153153
iTask->complete = 1;
154154
qemu_bh_delete(iTask->bh);
155-
qemu_coroutine_enter(iTask->co, NULL);
155+
qemu_coroutine_enter(iTask->co);
156156
}
157157

158158
static void iscsi_retry_timer_expired(void *opaque)
159159
{
160160
struct IscsiTask *iTask = opaque;
161161
iTask->complete = 1;
162162
if (iTask->co) {
163-
qemu_coroutine_enter(iTask->co, NULL);
163+
qemu_coroutine_enter(iTask->co);
164164
}
165165
}
166166

block/linux-aio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void qemu_laio_process_completion(struct qemu_laiocb *laiocb)
9494

9595
laiocb->ret = ret;
9696
if (laiocb->co) {
97-
qemu_coroutine_enter(laiocb->co, NULL);
97+
qemu_coroutine_enter(laiocb->co);
9898
} else {
9999
laiocb->common.cb(laiocb->common.opaque, ret);
100100
qemu_aio_unref(laiocb);

0 commit comments

Comments
 (0)