From nobody Wed Nov 5 07:53:08 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 1533617172663176.24650687054896; Mon, 6 Aug 2018 21:46:12 -0700 (PDT) Received: from localhost ([::1]:37328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmtsp-0007mi-IC for importer@patchew.org; Tue, 07 Aug 2018 00:46:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmth7-0004lp-NN for qemu-devel@nongnu.org; Tue, 07 Aug 2018 00:34:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmth6-0001Mv-1u for qemu-devel@nongnu.org; Tue, 07 Aug 2018 00:34:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51576 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 1fmtgy-0001E8-Lp; Tue, 07 Aug 2018 00:33:56 -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 1F406402242D; Tue, 7 Aug 2018 04:33:56 +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 C910F20180F6; Tue, 7 Aug 2018 04:33:55 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 7 Aug 2018 00:33:44 -0400 Message-Id: <20180807043349.27196-17-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.6]); Tue, 07 Aug 2018 04:33:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 07 Aug 2018 04:33:56 +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 16/21] block/commit: refactor commit to use job callbacks 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" Use the component callbacks; prepare, commit, abort, and clean. NB: prepare is only called when the job has not yet failed; and abort can be called after prepare. complete -> prepare -> abort -> clean complete -> abort -> clean Signed-off-by: John Snow --- block/commit.c | 94 +++++++++++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/block/commit.c b/block/commit.c index 1a4a56795f..6673a0544e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -35,7 +35,9 @@ typedef struct CommitBlockJob { BlockJob common; BlockDriverState *commit_top_bs; BlockBackend *top; + BlockDriverState *top_bs; BlockBackend *base; + BlockDriverState *base_bs; BlockdevOnError on_error; int base_flags; char *backing_file_str; @@ -71,37 +73,37 @@ static int coroutine_fn commit_populate(BlockBackend *b= s, BlockBackend *base, static void commit_exit(Job *job) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); - BlockJob *bjob =3D &s->common; - BlockDriverState *top =3D blk_bs(s->top); - BlockDriverState *base =3D blk_bs(s->base); - BlockDriverState *commit_top_bs =3D s->commit_top_bs; - int ret =3D job->ret; - bool remove_commit_top_bs =3D false; + + s->top_bs =3D blk_bs(s->top); + s->base_bs =3D blk_bs(s->base); =20 /* Make sure commit_top_bs and top stay around until bdrv_replace_node= () */ - bdrv_ref(top); - bdrv_ref(commit_top_bs); + bdrv_ref(s->top_bs); + bdrv_ref(s->commit_top_bs); +} =20 - /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before - * the normal backing chain can be restored. */ - blk_unref(s->base); +static int commit_prepare(Job *job) +{ + CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); =20 - if (!job_is_cancelled(job) && ret =3D=3D 0) { - /* success */ - ret =3D bdrv_drop_intermediate(s->commit_top_bs, base, - s->backing_file_str); - } else { - /* XXX Can (or should) we somehow keep 'consistent read' blocked e= ven - * after the failed/cancelled commit job is gone? If we already wr= ote - * something to base, the intermediate images aren't valid any mor= e. */ - remove_commit_top_bs =3D true; - } + /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE befo= re + * the normal backing chain can be restored. */ + blk_unref(s->base); + s->base =3D NULL; + + return bdrv_drop_intermediate(s->commit_top_bs, s->base_bs, + s->backing_file_str); +} + +static void commit_exit_common(Job *job) +{ + CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); =20 /* restore base open flags here if appropriate (e.g., change the base = back * to r/o). These reopens do not need to be atomic, since we won't abo= rt * even on failure here */ - if (s->base_flags !=3D bdrv_get_flags(base)) { - bdrv_reopen(base, s->base_flags, NULL); + if (s->base_flags !=3D bdrv_get_flags(s->base_bs)) { + bdrv_reopen(s->base_bs, s->base_flags, NULL); } g_free(s->backing_file_str); blk_unref(s->top); @@ -110,21 +112,43 @@ static void commit_exit(Job *job) * job_finish_sync()), job_completed() won't free it and therefore the * blockers on the intermediate nodes remain. This would cause * bdrv_set_backing_hd() to fail. */ - block_job_remove_all_bdrv(bjob); + block_job_remove_all_bdrv(&s->common); +} + +static void commit_commit(Job *job) +{ + commit_exit_common(job); +} + +static void commit_abort(Job *job) +{ + CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); + + if (s->base) { + blk_unref(s->base); + } + + commit_exit_common(job); + + /* XXX Can (or should) we somehow keep 'consistent read' blocked even + * after the failed/cancelled commit job is gone? If we already wrote + * something to base, the intermediate images aren't valid any more. */ =20 /* If bdrv_drop_intermediate() didn't already do that, remove the comm= it * filter driver from the backing chain. Do this as the final step so = that * the 'consistent read' permission can be granted. */ - if (remove_commit_top_bs) { - bdrv_child_try_set_perm(commit_top_bs->backing, 0, BLK_PERM_ALL, - &error_abort); - bdrv_replace_node(commit_top_bs, backing_bs(commit_top_bs), - &error_abort); - } + bdrv_child_try_set_perm(s->commit_top_bs->backing, 0, BLK_PERM_ALL, + &error_abort); + bdrv_replace_node(s->commit_top_bs, backing_bs(s->commit_top_bs), + &error_abort); +} =20 - bdrv_unref(commit_top_bs); - bdrv_unref(top); - job->ret =3D ret; +static void commit_clean(Job *job) +{ + CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); + + bdrv_unref(s->commit_top_bs); + bdrv_unref(s->top_bs); } =20 static int coroutine_fn commit_run(Job *job) @@ -214,6 +238,10 @@ static const BlockJobDriver commit_job_driver =3D { .drain =3D block_job_drain, .start =3D commit_run, .exit =3D commit_exit, + .prepare =3D commit_prepare, + .commit =3D commit_commit, + .abort =3D commit_abort, + .clean =3D commit_clean }, }; =20 --=20 2.14.4