From nobody Wed Nov 5 07:53:10 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 153361695719857.95994695292836; Mon, 6 Aug 2018 21:42:37 -0700 (PDT) Received: from localhost ([::1]:37303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmtpL-00040C-NO for importer@patchew.org; Tue, 07 Aug 2018 00:42:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmth7-0004ku-6j for qemu-devel@nongnu.org; Tue, 07 Aug 2018 00:34:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmth5-0001MA-3v for qemu-devel@nongnu.org; Tue, 07 Aug 2018 00:34:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45964 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 1fmtgx-0001DW-6H; Tue, 07 Aug 2018 00:33:55 -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 B715381663C7; Tue, 7 Aug 2018 04:33:54 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-197.bos.redhat.com [10.18.17.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C73B20180F4; Tue, 7 Aug 2018 04:33:54 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 7 Aug 2018 00:33:40 -0400 Message-Id: <20180807043349.27196-13-jsnow@redhat.com> In-Reply-To: <20180807043349.27196-1-jsnow@redhat.com> References: <20180807043349.27196-1-jsnow@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.8]); Tue, 07 Aug 2018 04:33:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 07 Aug 2018 04:33:54 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jsnow@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 12/21] jobs: allow entrypoints to return status code 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, John Snow , Jeff Cody , Markus Armbruster , "Dr. David Alan Gilbert" , jtc@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of awkwardly setting the return code in the job object, we can just return this on the stack and catch it in the caller. This also has the side-effect of changing the "opaque" type in the entrypoint to the more specific "Job" type, so change function signatures accordingly. Signed-off-by: John Snow --- block/backup.c | 6 +++--- block/commit.c | 6 +++--- block/create.c | 8 +++++--- block/mirror.c | 6 +++--- block/stream.c | 6 +++--- include/qemu/job.h | 2 +- job.c | 2 +- tests/test-bdrv-drain.c | 6 ++++-- tests/test-blockjob-txn.c | 13 ++++++------- tests/test-blockjob.c | 9 ++++++--- 10 files changed, 35 insertions(+), 29 deletions(-) diff --git a/block/backup.c b/block/backup.c index af6ee5ab54..c903416c5f 100644 --- a/block/backup.c +++ b/block/backup.c @@ -468,9 +468,9 @@ static void backup_incremental_init_copy_bitmap(BackupB= lockJob *job) bdrv_dirty_iter_free(dbi); } =20 -static void coroutine_fn backup_run(void *opaque) +static int coroutine_fn backup_run(Job *opaque_job) { - BackupBlockJob *job =3D opaque; + BackupBlockJob *job =3D container_of(opaque_job, BackupBlockJob, commo= n.job); BlockDriverState *bs =3D blk_bs(job->common.blk); int64_t offset, nb_clusters; int ret =3D 0; @@ -571,7 +571,7 @@ static void coroutine_fn backup_run(void *opaque) qemu_co_rwlock_unlock(&job->flush_rwlock); hbitmap_free(job->copy_bitmap); =20 - job->common.job.ret =3D ret; + return ret; } =20 static const BlockJobDriver backup_job_driver =3D { diff --git a/block/commit.c b/block/commit.c index 5bed098d5f..22712cac2d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -127,9 +127,9 @@ static void commit_exit(Job *job) job->ret =3D ret; } =20 -static void coroutine_fn commit_run(void *opaque) +static int coroutine_fn commit_run(Job *job) { - CommitBlockJob *s =3D opaque; + CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); int64_t offset; uint64_t delay_ns =3D 0; int ret =3D 0; @@ -202,7 +202,7 @@ static void coroutine_fn commit_run(void *opaque) out: qemu_vfree(buf); =20 - s->common.job.ret =3D ret; + return ret; } =20 static const BlockJobDriver commit_job_driver =3D { diff --git a/block/create.c b/block/create.c index 3aeafc68cf..9de55b973a 100644 --- a/block/create.c +++ b/block/create.c @@ -36,15 +36,17 @@ typedef struct BlockdevCreateJob { BlockdevCreateOptions *opts; } BlockdevCreateJob; =20 -static void coroutine_fn blockdev_create_run(void *opaque) +static int coroutine_fn blockdev_create_run(Job *job) { - BlockdevCreateJob *s =3D opaque; + int ret; + BlockdevCreateJob *s =3D container_of(job, BlockdevCreateJob, common); =20 job_progress_set_remaining(&s->common, 1); - s->common.ret =3D s->drv->bdrv_co_create(s->opts, &s->common.err); + ret =3D s->drv->bdrv_co_create(s->opts, &s->common.err); job_progress_update(&s->common, 1); =20 qapi_free_BlockdevCreateOptions(s->opts); + return ret; } =20 static const JobDriver blockdev_create_job_driver =3D { diff --git a/block/mirror.c b/block/mirror.c index e3404e2518..acf874393e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -808,9 +808,9 @@ static int mirror_flush(MirrorBlockJob *s) return ret; } =20 -static void coroutine_fn mirror_run(void *opaque) +static int coroutine_fn mirror_run(Job *job) { - MirrorBlockJob *s =3D opaque; + MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; BlockDriverState *target_bs =3D blk_bs(s->target); bool need_drain =3D true; @@ -1034,7 +1034,7 @@ immediate_exit: bdrv_drained_begin(bs); } =20 - s->common.job.ret =3D ret; + return ret; } =20 static void mirror_complete(Job *job, Error **errp) diff --git a/block/stream.c b/block/stream.c index 163cd6431c..2bdbca779d 100644 --- a/block/stream.c +++ b/block/stream.c @@ -92,9 +92,9 @@ out: job->ret =3D ret; } =20 -static void coroutine_fn stream_run(void *opaque) +static int coroutine_fn stream_run(Job *job) { - StreamBlockJob *s =3D opaque; + StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockBackend *blk =3D s->common.blk; BlockDriverState *bs =3D blk_bs(blk); BlockDriverState *base =3D s->base; @@ -197,7 +197,7 @@ static void coroutine_fn stream_run(void *opaque) =20 out: /* Modify backing chain and close BDSes in main loop */ - s->common.job.ret =3D ret; + return ret; } =20 static const BlockJobDriver stream_job_driver =3D { diff --git a/include/qemu/job.h b/include/qemu/job.h index 02df75f45d..eef03bb06d 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -169,7 +169,7 @@ struct JobDriver { JobType job_type; =20 /** Mandatory: Entrypoint for the Coroutine. */ - CoroutineEntry *start; + int coroutine_fn (*start)(Job *job); =20 /** * If the callback is not NULL, it will be invoked when the job transi= tions diff --git a/job.c b/job.c index fa6a1cd62c..09ce8900df 100644 --- a/job.c +++ b/job.c @@ -558,7 +558,7 @@ static void coroutine_fn job_co_entry(void *opaque) =20 assert(job && job->driver && job->driver->start); job_pause_point(job); - job->driver->start(job); + job->ret =3D job->driver->start(job); job->deferred_to_main_loop =3D true; aio_bh_schedule_oneshot(qemu_get_aio_context(), job_exit, job); } diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index f30310596c..64188970e8 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -752,9 +752,9 @@ typedef struct TestBlockJob { bool should_complete; } TestBlockJob; =20 -static void coroutine_fn test_job_start(void *opaque) +static int coroutine_fn test_job_start(Job *job) { - TestBlockJob *s =3D opaque; + TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); =20 job_transition_to_ready(&s->common.job); while (!s->should_complete) { @@ -764,6 +764,8 @@ static void coroutine_fn test_job_start(void *opaque) qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); job_pause_point(&s->common.job); } + + return 0; } =20 static void test_job_complete(Job *job, Error **errp) diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 307726d089..1128490c19 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -32,24 +32,23 @@ static void test_block_job_exit(Job *job) bdrv_unref(bs); } =20 -static void coroutine_fn test_block_job_run(void *opaque) +static int coroutine_fn test_block_job_run(Job *job) { - TestBlockJob *s =3D opaque; - BlockJob *job =3D &s->common; + TestBlockJob *s =3D container_of(job, TestBlockJob, common.job); =20 while (s->iterations--) { if (s->use_timer) { - job_sleep_ns(&job->job, 0); + job_sleep_ns(job, 0); } else { - job_yield(&job->job); + job_yield(job); } =20 - if (job_is_cancelled(&job->job)) { + if (job_is_cancelled(job)) { break; } } =20 - s->common.job.ret =3D s->rc; + return s->rc; } =20 typedef struct { diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 20563bde4f..7f6df29bcf 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -175,13 +175,13 @@ static void cancel_job_complete(Job *job, Error **err= p) s->should_complete =3D true; } =20 -static void coroutine_fn cancel_job_start(void *opaque) +static int coroutine_fn cancel_job_start(Job *job) { - CancelJob *s =3D opaque; + CancelJob *s =3D container_of(job, CancelJob, common.job); =20 while (!s->should_complete) { if (job_is_cancelled(&s->common.job)) { - return; + goto out; } =20 if (!job_is_ready(&s->common.job) && s->should_converge) { @@ -190,6 +190,9 @@ static void coroutine_fn cancel_job_start(void *opaque) =20 job_sleep_ns(&s->common.job, 100000); } + + out: + return 0; } =20 static const BlockJobDriver test_cancel_driver =3D { --=20 2.14.4