@@ -513,8 +513,8 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
TestBlockJob *s = container_of(job, TestBlockJob, common.job);
job_transition_to_ready(&s->common.job);
- while (!s->should_complete) {
- s->n++;
+ while (!qatomic_read(&s->should_complete)) {
+ qatomic_inc(&s->n);
g_assert(qemu_get_current_aio_context() == job->aio_context);
/* Avoid job_sleep_ns() because it marks the job as !busy. We want to
@@ -533,7 +533,7 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
static void test_job_complete(Job *job, Error **errp)
{
TestBlockJob *s = container_of(job, TestBlockJob, common.job);
- s->should_complete = true;
+ qatomic_set(&s->should_complete, true);
}
BlockJobDriver test_job_driver = {
@@ -564,28 +564,28 @@ static void test_attach_blockjob(void)
0, 0, NULL, NULL, &error_abort);
job_start(&tjob->common.job);
- while (tjob->n == 0) {
+ while (qatomic_read(&tjob->n) == 0) {
aio_poll(qemu_get_aio_context(), false);
}
blk_set_aio_context(blk, ctx, &error_abort);
tjob->n = 0;
- while (tjob->n == 0) {
+ while (qatomic_read(&tjob->n) == 0) {
aio_poll(qemu_get_aio_context(), false);
}
blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
tjob->n = 0;
- while (tjob->n == 0) {
+ while (qatomic_read(&tjob->n) == 0) {
aio_poll(qemu_get_aio_context(), false);
}
blk_set_aio_context(blk, ctx, &error_abort);
tjob->n = 0;
- while (tjob->n == 0) {
+ while (qatomic_read(&tjob->n) == 0) {
aio_poll(qemu_get_aio_context(), false);
}
This patch resolves potential data races involving access to TestBlockJob fields in test-block-iothread.c. Fixes: 93c60f3862 ("test-block-iothread: Job coroutine thread after AioContext switch") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2809 Signed-off-by: Vitalii Mordan <mordan@ispras.ru> --- tests/unit/test-block-iothread.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)