From nobody Wed Oct 29 22:54:59 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525884571844135.81103307889737; Wed, 9 May 2018 09:49:31 -0700 (PDT) Received: from localhost ([::1]:57653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSHO-0003i8-GI for importer@patchew.org; Wed, 09 May 2018 12:49:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGRwW-0005nl-Nw for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGRwV-0002Wh-1j for qemu-devel@nongnu.org; Wed, 09 May 2018 12:27:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50618 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGRwR-0002P5-AO; Wed, 09 May 2018 12:27:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A6B54059FE1; Wed, 9 May 2018 16:27:46 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BA4E2023433; Wed, 9 May 2018 16:27:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:26:22 +0200 Message-Id: <20180509162637.15575-28-kwolf@redhat.com> In-Reply-To: <20180509162637.15575-1-kwolf@redhat.com> References: <20180509162637.15575-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 09 May 2018 16:27:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 09 May 2018 16:27:46 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 27/42] job: Add job_drain() 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, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" block_job_drain() contains a blk_drain() call which cannot be moved to Job, so add a new JobDriver callback JobDriver.drain which has a common implementation for all BlockJobs. In addition to this we keep the existing BlockJobDriver.drain callback that is called by the common drain implementation for all block jobs. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/blockjob_int.h | 12 ++++++++++++ include/qemu/job.h | 13 +++++++++++++ block/backup.c | 1 + block/commit.c | 1 + block/mirror.c | 2 ++ block/stream.c | 1 + blockjob.c | 20 ++++++++++---------- job.c | 11 +++++++++++ tests/test-bdrv-drain.c | 1 + tests/test-blockjob-txn.c | 1 + tests/test-blockjob.c | 2 ++ 11 files changed, 55 insertions(+), 10 deletions(-) diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index bf2b762808..38fe22d7e0 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -65,6 +65,10 @@ struct BlockJobDriver { * If the callback is not NULL, it will be invoked when the job has to= be * synchronously cancelled or completed; it should drain BlockDriverSt= ates * as required to ensure progress. + * + * Block jobs must use the default implementation for job_driver.drain, + * which will in turn call this callback after doing generic block job + * stuff. */ void (*drain)(BlockJob *job); }; @@ -112,6 +116,14 @@ void block_job_free(Job *job); void block_job_user_resume(Job *job); =20 /** + * block_job_drain: + * Callback to be used for JobDriver.drain in all block jobs. Drains the m= ain + * block node associated with the block jobs and calls BlockJobDriver.drai= n for + * job-specific actions. + */ +void block_job_drain(Job *job); + +/** * block_job_yield: * @job: The job that calls the function. * diff --git a/include/qemu/job.h b/include/qemu/job.h index b96ec10413..49e254f01a 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -167,6 +167,13 @@ struct JobDriver { */ void (*user_resume)(Job *job); =20 + /* + * If the callback is not NULL, it will be invoked when the job has to= be + * synchronously cancelled or completed; it should drain any activities + * as required to ensure progress. + */ + void (*drain)(Job *job); + /** * If the callback is not NULL, it will be invoked when all the jobs * belonging to the same transaction complete; or upon this job's @@ -325,6 +332,12 @@ bool job_user_paused(Job *job); */ void job_user_resume(Job *job, Error **errp); =20 +/* + * Drain any activities as required to ensure progress. This can be called= in a + * loop to synchronously complete a job. + */ +void job_drain(Job *job); + /** * Get the next element from the list of block jobs after @job, or the * first one if @job is %NULL. diff --git a/block/backup.c b/block/backup.c index bd31282924..ca7d990b21 100644 --- a/block/backup.c +++ b/block/backup.c @@ -529,6 +529,7 @@ static const BlockJobDriver backup_job_driver =3D { .job_type =3D JOB_TYPE_BACKUP, .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, .start =3D backup_run, .commit =3D backup_commit, .abort =3D backup_abort, diff --git a/block/commit.c b/block/commit.c index e53b2d7d55..02a8af9127 100644 --- a/block/commit.c +++ b/block/commit.c @@ -221,6 +221,7 @@ static const BlockJobDriver commit_job_driver =3D { .job_type =3D JOB_TYPE_COMMIT, .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, .start =3D commit_run, }, }; diff --git a/block/mirror.c b/block/mirror.c index f18240e34c..4ab7e088ee 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -992,6 +992,7 @@ static const BlockJobDriver mirror_job_driver =3D { .job_type =3D JOB_TYPE_MIRROR, .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, .start =3D mirror_run, .pause =3D mirror_pause, }, @@ -1006,6 +1007,7 @@ static const BlockJobDriver commit_active_job_driver = =3D { .job_type =3D JOB_TYPE_COMMIT, .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, .start =3D mirror_run, .pause =3D mirror_pause, }, diff --git a/block/stream.c b/block/stream.c index eee02538ed..b996278ab3 100644 --- a/block/stream.c +++ b/block/stream.c @@ -215,6 +215,7 @@ static const BlockJobDriver stream_job_driver =3D { .free =3D block_job_free, .start =3D stream_run, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, }, }; =20 diff --git a/blockjob.c b/blockjob.c index ca88e166e1..76d9cb32b3 100644 --- a/blockjob.c +++ b/blockjob.c @@ -170,14 +170,13 @@ static void block_job_attached_aio_context(AioContext= *new_context, job_resume(&job->job); } =20 -static void block_job_drain(BlockJob *job) +void block_job_drain(Job *job) { - /* If job is !job->job.busy this kicks it into the next pause point. */ - block_job_enter(job); + BlockJob *bjob =3D container_of(job, BlockJob, job); =20 - blk_drain(job->blk); - if (job->driver->drain) { - job->driver->drain(job); + blk_drain(bjob->blk); + if (bjob->driver->drain) { + bjob->driver->drain(bjob); } } =20 @@ -191,7 +190,7 @@ static void block_job_detach_aio_context(void *opaque) job_pause(&job->job); =20 while (!job->job.paused && !job_is_completed(&job->job)) { - block_job_drain(job); + job_drain(&job->job); } =20 job->job.aio_context =3D NULL; @@ -328,11 +327,11 @@ static int block_job_finish_sync(BlockJob *job, job_unref(&job->job); return -EBUSY; } - /* block_job_drain calls block_job_enter, and it should be enough to - * induce progress until the job completes or moves to the main thread. + /* job_drain calls job_enter, and it should be enough to induce progre= ss + * until the job completes or moves to the main thread. */ while (!job->job.deferred_to_main_loop && !job_is_completed(&job->job)= ) { - block_job_drain(job); + job_drain(&job->job); } while (!job_is_completed(&job->job)) { aio_poll(qemu_get_aio_context(), true); @@ -714,6 +713,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, assert(is_block_job(&job->job)); assert(job->job.driver->free =3D=3D &block_job_free); assert(job->job.driver->user_resume =3D=3D &block_job_user_resume); + assert(job->job.driver->drain =3D=3D &block_job_drain); =20 job->driver =3D driver; job->blk =3D blk; diff --git a/job.c b/job.c index 4591e09e92..6cc05f4476 100644 --- a/job.c +++ b/job.c @@ -367,6 +367,17 @@ void coroutine_fn job_sleep_ns(Job *job, int64_t ns) job_pause_point(job); } =20 +void job_drain(Job *job) +{ + /* If job is !busy this kicks it into the next pause point. */ + job_enter(job); + + if (job->driver->drain) { + job->driver->drain(job); + } +} + + /** * All jobs must allow a pause point before entering their job proper. This * ensures that jobs can be paused prior to being started, then resumed la= ter. diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index c993512f66..58ea5663f0 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -525,6 +525,7 @@ BlockJobDriver test_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, .start =3D test_job_start, }, .complete =3D test_job_complete, diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 60e9fa2298..1572f8d96f 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -79,6 +79,7 @@ static const BlockJobDriver test_block_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, .start =3D test_block_job_run, }, }; diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 1fe6803fe0..592a13613d 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -21,6 +21,7 @@ static const BlockJobDriver test_block_job_driver =3D { .instance_size =3D sizeof(BlockJob), .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, }, }; =20 @@ -201,6 +202,7 @@ static const BlockJobDriver test_cancel_driver =3D { .instance_size =3D sizeof(CancelJob), .free =3D block_job_free, .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, .start =3D cancel_job_start, }, .complete =3D cancel_job_complete, --=20 2.13.6