From nobody Wed May 15 17:04:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556904112; cv=none; d=zoho.com; s=zohoarc; b=S1WLGLz3fGceTRFsBd8cZJuy3O9PRsX9pzj5ynnBJNFmOjgie3dSNaKS/DsTZwYz+B8L7vUptyJwaeKuBV66a7VLxecVElFvVIqTh2ugkBeqD8eefClLp1guzAtJehzg3J4vFytZ67vgRVWWFT+4jz6MCA378NI5v2Oj9ztSugs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556904112; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Fa3zUl4qGOmz7fly/TjLY0GfEEqoWouXtKD0NY11eNA=; b=F1fhdpz+etIYdfPrr1NAwhMj+mUbmbGFaudOPzrMC7uE51zzK4u+gtZNpSuD7jKMVum2qHI0SsQBNjHd6vk6JoSwqoA7SGz0EhQQryVqy4oOTcLuBUGNwFvk5Tb+K4ZaTdVYRYn+cP5a+z6RiKuxqYI/o+qgfEearVOsfSxhTUE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556904112296140.8749169049737; Fri, 3 May 2019 10:21:52 -0700 (PDT) Received: from localhost ([127.0.0.1]:45015 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMbsQ-0004OH-9o for importer@patchew.org; Fri, 03 May 2019 13:21:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMboy-0001yV-Me for qemu-devel@nongnu.org; Fri, 03 May 2019 13:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMbox-00058t-QA for qemu-devel@nongnu.org; Fri, 03 May 2019 13:18:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37578) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMbov-0004zQ-M0; Fri, 03 May 2019 13:18:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1094E3097041; Fri, 3 May 2019 17:17:56 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-106.ams2.redhat.com [10.36.116.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0123C5D6A6; Fri, 3 May 2019 17:17:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 3 May 2019 19:17:43 +0200 Message-Id: <20190503171744.21589-2-kwolf@redhat.com> In-Reply-To: <20190503171744.21589-1-kwolf@redhat.com> References: <20190503171744.21589-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 03 May 2019 17:17:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] blockjob: Fix coroutine thread after AioContext change X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit 463e0be10 ('blockjob: add AioContext attached callback') tried to make block jobs robust against AioContext changes of their main node, but it never made sure that the job coroutine actually runs in the new thread. Instead of waking up the job coroutine in whatever thread it ran before, let's always pass the AioContext where it should be running now. Signed-off-by: Kevin Wolf --- job.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/job.c b/job.c index da8e4b7bf2..2167d53717 100644 --- a/job.c +++ b/job.c @@ -432,7 +432,7 @@ void job_enter_cond(Job *job, bool(*fn)(Job *job)) timer_del(&job->sleep_timer); job->busy =3D true; job_unlock(); - aio_co_wake(job->co); + aio_co_enter(job->aio_context, job->co); } =20 void job_enter(Job *job) --=20 2.20.1 From nobody Wed May 15 17:04:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556904018; cv=none; d=zoho.com; s=zohoarc; b=ZiPkaExpNrevwysJ+I6/cX8uTyjtJofn9VHBy+dtgKYsQa06dqNij3+8mmDTFXcZ6+Etv2AfBi3v7dCSKJV2NB52luWJ/QJQ5HtAKmeypXeAj7Y3Z8AiNEopKWOgtGm9zTp0yJNuPiuMuXGmSsemQMI+GmWFJMCNjSUMO8U7wpQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556904018; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vFG010/GDsUlyD2PvY69Czi2PplmHh6B9VAlhUKQUCQ=; b=X09N88jEfenlhdD/S8EFwERa0oC/QNxJS1TPNJLaTv6SQaS5ltZsqJmC0ocb2PBHwQFaqiGTurY0Fxb0zJmKaqlm2zcCBZE+dIRc41pZgQwYUCsv7Ld+4sU7Ieg3TrGlv+BYO5EWT6Q+Gk5vSDf9nnhxjpyD6YZ6gGu9rAtDNLg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556904018692188.8022363989976; Fri, 3 May 2019 10:20:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:44967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMbr5-0003Gj-JU for importer@patchew.org; Fri, 03 May 2019 13:20:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMboz-0001zE-Eb for qemu-devel@nongnu.org; Fri, 03 May 2019 13:18:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hMboy-00059P-AM for qemu-devel@nongnu.org; Fri, 03 May 2019 13:18:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hMbot-00050C-PA; Fri, 03 May 2019 13:18:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 726AE309708D; Fri, 3 May 2019 17:17:57 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-106.ams2.redhat.com [10.36.116.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 602305D6A6; Fri, 3 May 2019 17:17:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 3 May 2019 19:17:44 +0200 Message-Id: <20190503171744.21589-3-kwolf@redhat.com> In-Reply-To: <20190503171744.21589-1-kwolf@redhat.com> References: <20190503171744.21589-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 03 May 2019 17:17:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] test-block-iothread: Job coroutine thread after AioContext switch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This tests that a job coroutine always runs in the right iothread after the AioContext of its main node has changed. Signed-off-by: Kevin Wolf --- tests/test-block-iothread.c | 107 ++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c index 97ac0b159d..036ed9a3b3 100644 --- a/tests/test-block-iothread.c +++ b/tests/test-block-iothread.c @@ -354,6 +354,111 @@ static void test_sync_op(const void *opaque) blk_unref(blk); } =20 +typedef struct TestBlockJob { + BlockJob common; + bool should_complete; + int n; +} TestBlockJob; + +static int test_job_prepare(Job *job) +{ + g_assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + return 0; +} + +static int coroutine_fn test_job_run(Job *job, Error **errp) +{ + TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); + + job_transition_to_ready(&s->common.job); + while (!s->should_complete) { + s->n++; + g_assert(qemu_get_current_aio_context() =3D=3D job->aio_context); + + /* Avoid job_sleep_ns() because it marks the job as !busy. We want= to + * emulate some actual activity (probably some I/O) here so that t= he + * drain involved in AioContext switches has to wait for this acti= vity + * to stop. */ + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000); + + job_pause_point(&s->common.job); + } + + g_assert(qemu_get_current_aio_context() =3D=3D job->aio_context); + return 0; +} + +static void test_job_complete(Job *job, Error **errp) +{ + TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); + s->should_complete =3D true; +} + +BlockJobDriver test_job_driver =3D { + .job_driver =3D { + .instance_size =3D sizeof(TestBlockJob), + .free =3D block_job_free, + .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, + .run =3D test_job_run, + .complete =3D test_job_complete, + .prepare =3D test_job_prepare, + }, +}; + +static void test_attach_blockjob(void) +{ + IOThread *iothread =3D iothread_new(); + AioContext *ctx =3D iothread_get_aio_context(iothread); + BlockBackend *blk; + BlockDriverState *bs; + TestBlockJob *tjob; + + blk =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs =3D bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_ab= ort); + blk_insert_bs(blk, bs, &error_abort); + + tjob =3D block_job_create("job0", &test_job_driver, NULL, bs, + 0, BLK_PERM_ALL, + 0, 0, NULL, NULL, &error_abort); + job_start(&tjob->common.job); + + while (tjob->n =3D=3D 0) { + aio_poll(qemu_get_aio_context(), false); + } + + blk_set_aio_context(blk, ctx); + + tjob->n =3D 0; + while (tjob->n =3D=3D 0) { + aio_poll(qemu_get_aio_context(), false); + } + + aio_context_acquire(ctx); + blk_set_aio_context(blk, qemu_get_aio_context()); + aio_context_release(ctx); + + tjob->n =3D 0; + while (tjob->n =3D=3D 0) { + aio_poll(qemu_get_aio_context(), false); + } + + blk_set_aio_context(blk, ctx); + + tjob->n =3D 0; + while (tjob->n =3D=3D 0) { + aio_poll(qemu_get_aio_context(), false); + } + + aio_context_acquire(ctx); + job_complete_sync(&tjob->common.job, &error_abort); + blk_set_aio_context(blk, qemu_get_aio_context()); + aio_context_release(ctx); + + bdrv_unref(bs); + blk_unref(blk); +} + int main(int argc, char **argv) { int i; @@ -368,5 +473,7 @@ int main(int argc, char **argv) g_test_add_data_func(t->name, t, test_sync_op); } =20 + g_test_add_func("/attach/blockjob", test_attach_blockjob); + return g_test_run(); } --=20 2.20.1