From nobody Wed Oct 29 09:10:29 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 1524585421214831.5615881868225; Tue, 24 Apr 2018 08:57:01 -0700 (PDT) Received: from localhost ([::1]:59277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB0JQ-0007bm-Aq for importer@patchew.org; Tue, 24 Apr 2018 11:57:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAzpW-0008NV-Cr for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:26:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAzpU-00006r-Cw for qemu-devel@nongnu.org; Tue, 24 Apr 2018 11:26:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59842 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 1fAzpP-0008PS-3I; Tue, 24 Apr 2018 11:25:59 -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 9FAF6406C7AC; Tue, 24 Apr 2018 15:25:58 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-100.ams2.redhat.com [10.36.117.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9054E2026990; Tue, 24 Apr 2018 15:25:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 24 Apr 2018 17:25:09 +0200 Message-Id: <20180424152515.25664-28-kwolf@redhat.com> In-Reply-To: <20180424152515.25664-1-kwolf@redhat.com> References: <20180424152515.25664-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]); Tue, 24 Apr 2018 15:25:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 24 Apr 2018 15:25:58 +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] [RFC PATCH 27/33] job: Move .complete callback to Job 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, jcody@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org, mreitz@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" This moves the .complete callback that tells a READY job to complete from BlockJobDriver to JobDriver. The wrapper function job_complete() doesn't require anything block job specific any more and can be moved to Job. Signed-off-by: Kevin Wolf --- include/block/blockjob.h | 10 ---------- include/block/blockjob_int.h | 6 ------ include/qemu/job.h | 8 ++++++++ block/mirror.c | 10 +++++----- blockdev.c | 2 +- blockjob.c | 23 +++++------------------ job.c | 16 ++++++++++++++++ tests/test-bdrv-drain.c | 6 +++--- tests/test-blockjob.c | 10 +++++----- 9 files changed, 43 insertions(+), 48 deletions(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 8477fc5a78..91fdbc9042 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -154,16 +154,6 @@ void block_job_set_speed(BlockJob *job, int64_t speed,= Error **errp); void block_job_cancel(BlockJob *job, bool force); =20 /** - * block_job_complete: - * @job: The job to be completed. - * @errp: Error object. - * - * Asynchronously complete the specified job. - */ -void block_job_complete(BlockJob *job, Error **errp); - - -/** * block_job_finalize: * @job: The job to fully commit and finish. * @errp: Error object. diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h index c8bcfa917a..fb81d7a09f 100644 --- a/include/block/blockjob_int.h +++ b/include/block/blockjob_int.h @@ -39,12 +39,6 @@ struct BlockJobDriver { JobDriver job_driver; =20 /** - * Optional callback for job types whose completion must be triggered - * manually. - */ - void (*complete)(BlockJob *job, Error **errp); - - /** * If the callback is not NULL, prepare will be invoked when all the j= obs * belonging to the same transaction complete; or upon this job's comp= letion * if it is not in a transaction. diff --git a/include/qemu/job.h b/include/qemu/job.h index e73ca7fd43..6132cf8e21 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -167,6 +167,12 @@ struct JobDriver { */ void (*user_resume)(Job *job); =20 + /** + * Optional callback for job types whose completion must be triggered + * manually. + */ + void (*complete)(Job *job, Error **errp); + /* * 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 @@ -339,6 +345,8 @@ Job *job_get(const char *id); /** The @job could not be started, free it. */ void job_early_fail(Job *job); =20 +/** Asynchronously complete the specified @job. */ +void job_complete(Job *job, Error **errp);; =20 typedef void JobDeferToMainLoopFn(Job *job, void *opaque); =20 diff --git a/block/mirror.c b/block/mirror.c index 5a83973661..9eb5a21cd9 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -901,16 +901,16 @@ immediate_exit: job_defer_to_main_loop(&s->common.job, mirror_exit, data); } =20 -static void mirror_complete(BlockJob *job, Error **errp) +static void mirror_complete(Job *job, Error **errp) { - MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); + MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockDriverState *target; =20 target =3D blk_bs(s->target); =20 if (!s->synced) { error_setg(errp, "The active block job '%s' cannot be completed", - job->job.id); + job->id); return; } =20 @@ -991,8 +991,8 @@ static const BlockJobDriver mirror_job_driver =3D { .drain =3D block_job_drain, .start =3D mirror_run, .pause =3D mirror_pause, + .complete =3D mirror_complete, }, - .complete =3D mirror_complete, .attached_aio_context =3D mirror_attached_aio_context, .drain =3D mirror_drain, }; @@ -1006,8 +1006,8 @@ static const BlockJobDriver commit_active_job_driver = =3D { .drain =3D block_job_drain, .start =3D mirror_run, .pause =3D mirror_pause, + .complete =3D mirror_complete, }, - .complete =3D mirror_complete, .attached_aio_context =3D mirror_attached_aio_context, .drain =3D mirror_drain, }; diff --git a/blockdev.c b/blockdev.c index fb7a3142e7..31aac7dae6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3894,7 +3894,7 @@ void qmp_block_job_complete(const char *device, Error= **errp) } =20 trace_qmp_block_job_complete(job); - block_job_complete(job, errp); + job_complete(&job->job, errp); aio_context_release(aio_context); } =20 diff --git a/blockjob.c b/blockjob.c index e211127b79..f4010988d4 100644 --- a/blockjob.c +++ b/blockjob.c @@ -482,24 +482,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, u= int64_t n) return ratelimit_calculate_delay(&job->limit, n); } =20 -void block_job_complete(BlockJob *job, Error **errp) -{ - /* Should not be reachable via external interface for internal jobs */ - assert(job->job.id); - if (job_apply_verb(&job->job, JOB_VERB_COMPLETE, errp)) { - return; - } - if (job->job.pause_count || job_is_cancelled(&job->job) || - !job->driver->complete) - { - error_setg(errp, "The active block job '%s' cannot be completed", - job->job.id); - return; - } - - job->driver->complete(job, errp); -} - void block_job_finalize(BlockJob *job, Error **errp) { assert(job && job->job.id && job->txn); @@ -572,6 +554,11 @@ void block_job_cancel_sync_all(void) } } =20 +static void block_job_complete(BlockJob *job, Error **errp) +{ + job_complete(&job->job, errp); +} + int block_job_complete_sync(BlockJob *job, Error **errp) { return block_job_finish_sync(job, &block_job_complete, errp); diff --git a/job.c b/job.c index dc7a54bbbc..dd68eb13f7 100644 --- a/job.c +++ b/job.c @@ -556,6 +556,22 @@ int job_finalize_single(Job *job) return 0; } =20 +void job_complete(Job *job, Error **errp) +{ + /* Should not be reachable via external interface for internal jobs */ + assert(job->id); + if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) { + return; + } + if (job->pause_count || job_is_cancelled(job) || !job->driver->complet= e) { + error_setg(errp, "The active block job '%s' cannot be completed", + job->id); + return; + } + + job->driver->complete(job, errp); +} + =20 typedef struct { Job *job; diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 58ea5663f0..b428aaca68 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -514,9 +514,9 @@ static void coroutine_fn test_job_start(void *opaque) job_defer_to_main_loop(&s->common.job, test_job_completed, NULL); } =20 -static void test_job_complete(BlockJob *job, Error **errp) +static void test_job_complete(Job *job, Error **errp) { - TestBlockJob *s =3D container_of(job, TestBlockJob, common); + TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); s->should_complete =3D true; } =20 @@ -527,8 +527,8 @@ BlockJobDriver test_job_driver =3D { .user_resume =3D block_job_user_resume, .drain =3D block_job_drain, .start =3D test_job_start, + .complete =3D test_job_complete, }, - .complete =3D test_job_complete, }; =20 static void test_blockjob_common(enum drain_type drain_type) diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 592a13613d..e44c608327 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -171,9 +171,9 @@ static void cancel_job_completed(Job *job, void *opaque) block_job_completed(bjob, 0); } =20 -static void cancel_job_complete(BlockJob *job, Error **errp) +static void cancel_job_complete(Job *job, Error **errp) { - CancelJob *s =3D container_of(job, CancelJob, common); + CancelJob *s =3D container_of(job, CancelJob, common.job); s->should_complete =3D true; } =20 @@ -204,8 +204,8 @@ static const BlockJobDriver test_cancel_driver =3D { .user_resume =3D block_job_user_resume, .drain =3D block_job_drain, .start =3D cancel_job_start, + .complete =3D cancel_job_complete, }, - .complete =3D cancel_job_complete, }; =20 static CancelJob *create_common(BlockJob **pjob) @@ -333,7 +333,7 @@ static void test_cancel_pending(void) block_job_enter(job); assert(job->job.status =3D=3D JOB_STATUS_READY); =20 - block_job_complete(job, &error_abort); + job_complete(&job->job, &error_abort); block_job_enter(job); while (!s->completed) { aio_poll(qemu_get_aio_context(), true); @@ -357,7 +357,7 @@ static void test_cancel_concluded(void) block_job_enter(job); assert(job->job.status =3D=3D JOB_STATUS_READY); =20 - block_job_complete(job, &error_abort); + job_complete(&job->job, &error_abort); block_job_enter(job); while (!s->completed) { aio_poll(qemu_get_aio_context(), true); --=20 2.13.6