From patchwork Mon Jul 12 11:53:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12370811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 599C7C07E99 for ; Mon, 12 Jul 2021 11:56:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBD6261004 for ; Mon, 12 Jul 2021 11:56:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBD6261004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2uXb-00035c-1M for qemu-devel@archiver.kernel.org; Mon, 12 Jul 2021 07:56:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uVy-0000D8-Bz; Mon, 12 Jul 2021 07:54:22 -0400 Received: from mout.web.de ([212.227.17.12]:53449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uVv-0005tw-M7; Mon, 12 Jul 2021 07:54:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1626090839; bh=pxzzQbjQHGmEgHR63nik675WL0F0T3YSIqZLGM4zN8s=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=EwSdXiI1qo8TOb2UO8fmhZWWp7XRe1uk6LbUWPkSRVjjYEd6j2kT+rL6nykX+QNOF HPqE0Ji5Qx+6re1f7fqMFYli5MGbm2jA73GHtVLZPVnVfUzWRnFdK95tNSOoDDLwvk 5Fw638s6aLIliUPErNQ/2+F2XisKzrrEY141AAy0= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([88.130.61.76]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LyUkU-1l7LqT1LNO-015rTr; Mon, 12 Jul 2021 13:53:59 +0200 Date: Mon, 12 Jul 2021 13:53:58 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v5 1/5] replication: Remove s->active_disk Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:X+G9sxvYSLuMoQyYcZwbBOTHFYyaSrTEchBHOr/KP3SOizxO8vl MnxFD26wlHmOv9mo7lbeL66rctaokwhERu2inbaKe3mCTLPWWCvjJ+lkjpABTYI1nXWuLIS cwcsN+x9GdtbFBgHcg9Y+S27ThWs1ZZWpNG2tl6KW0l2G90v50XnCZxRCUPGexlYpyjMIOn xIiwJ4c24ukqY/mrQqFfA== X-UI-Out-Filterresults: notjunk:1;V03:K0:6DTqnbOKSXA=:v6bcy5me4rf+G2eadCwmWa A+lxWlfjhpncy7vRhPAAEbJCORKy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rMrr IaVqqOZysgenKqWQO35BtSg3DpKl7OHp635 Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: 1 X-Spam_score: 0.1 X-Spam_bar: / X-Spam_report: (0.1 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block , Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" s->active_disk is bs->file. Remove it and use local variables instead. Signed-off-by: Lukas Straub Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/replication.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index 774e15df16..9ad2dfdc69 100644 --- a/block/replication.c +++ b/block/replication.c @@ -35,7 +35,6 @@ typedef enum { typedef struct BDRVReplicationState { ReplicationMode mode; ReplicationStage stage; - BdrvChild *active_disk; BlockJob *commit_job; BdrvChild *hidden_disk; BdrvChild *secondary_disk; @@ -307,8 +306,10 @@ out: return ret; } -static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) +static void secondary_do_checkpoint(BlockDriverState *bs, Error **errp) { + BDRVReplicationState *s = bs->opaque; + BdrvChild *active_disk = bs->file; Error *local_err = NULL; int ret; @@ -323,13 +324,13 @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) return; } - if (!s->active_disk->bs->drv) { + if (!active_disk->bs->drv) { error_setg(errp, "Active disk %s is ejected", - s->active_disk->bs->node_name); + active_disk->bs->node_name); return; } - ret = bdrv_make_empty(s->active_disk, errp); + ret = bdrv_make_empty(active_disk, errp); if (ret < 0) { return; } @@ -458,6 +459,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; BlockDriverState *top_bs; + BdrvChild *active_disk; int64_t active_length, hidden_length, disk_length; AioContext *aio_context; Error *local_err = NULL; @@ -495,15 +497,14 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, case REPLICATION_MODE_PRIMARY: break; case REPLICATION_MODE_SECONDARY: - s->active_disk = bs->file; - if (!s->active_disk || !s->active_disk->bs || - !s->active_disk->bs->backing) { + active_disk = bs->file; + if (!active_disk || !active_disk->bs || !active_disk->bs->backing) { error_setg(errp, "Active disk doesn't have backing file"); aio_context_release(aio_context); return; } - s->hidden_disk = s->active_disk->bs->backing; + s->hidden_disk = active_disk->bs->backing; if (!s->hidden_disk->bs || !s->hidden_disk->bs->backing) { error_setg(errp, "Hidden disk doesn't have backing file"); aio_context_release(aio_context); @@ -518,7 +519,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, } /* verify the length */ - active_length = bdrv_getlength(s->active_disk->bs); + active_length = bdrv_getlength(active_disk->bs); hidden_length = bdrv_getlength(s->hidden_disk->bs); disk_length = bdrv_getlength(s->secondary_disk->bs); if (active_length < 0 || hidden_length < 0 || disk_length < 0 || @@ -530,9 +531,9 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, } /* Must be true, or the bdrv_getlength() calls would have failed */ - assert(s->active_disk->bs->drv && s->hidden_disk->bs->drv); + assert(active_disk->bs->drv && s->hidden_disk->bs->drv); - if (!s->active_disk->bs->drv->bdrv_make_empty || + if (!active_disk->bs->drv->bdrv_make_empty || !s->hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_empty"); @@ -586,7 +587,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, s->stage = BLOCK_REPLICATION_RUNNING; if (s->mode == REPLICATION_MODE_SECONDARY) { - secondary_do_checkpoint(s, errp); + secondary_do_checkpoint(bs, errp); } s->error = 0; @@ -615,7 +616,7 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp) } if (s->mode == REPLICATION_MODE_SECONDARY) { - secondary_do_checkpoint(s, errp); + secondary_do_checkpoint(bs, errp); } aio_context_release(aio_context); } @@ -652,7 +653,6 @@ static void replication_done(void *opaque, int ret) if (ret == 0) { s->stage = BLOCK_REPLICATION_DONE; - s->active_disk = NULL; s->secondary_disk = NULL; s->hidden_disk = NULL; s->error = 0; @@ -705,7 +705,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) } if (!failover) { - secondary_do_checkpoint(s, errp); + secondary_do_checkpoint(bs, errp); s->stage = BLOCK_REPLICATION_DONE; aio_context_release(aio_context); return; @@ -713,7 +713,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) s->stage = BLOCK_REPLICATION_FAILOVER; s->commit_job = commit_active_start( - NULL, s->active_disk->bs, s->secondary_disk->bs, + NULL, bs->file->bs, s->secondary_disk->bs, JOB_INTERNAL, 0, BLOCKDEV_ON_ERROR_REPORT, NULL, replication_done, bs, true, errp); break; From patchwork Mon Jul 12 11:54:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12370813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82F79C07E99 for ; Mon, 12 Jul 2021 11:57:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 13FBA61004 for ; Mon, 12 Jul 2021 11:57:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13FBA61004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2uYy-0005Ld-7Y for qemu-devel@archiver.kernel.org; Mon, 12 Jul 2021 07:57:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uVw-00009x-U6; Mon, 12 Jul 2021 07:54:20 -0400 Received: from mout.web.de ([212.227.17.12]:50417) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uVu-0005sk-Uv; Mon, 12 Jul 2021 07:54:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1626090843; bh=aY3Mw3hwsf/JlGVdZQgu/Xo23JhYBMtJ8fU+3Y4C52o=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=JGTeAOjFxyEQhyH2qNn+m6mG5ULG5XuaP1Ve/CwJXvlPyoN9NjAHjdzfMmvDYO1tj CTpftEKQqFlh2q3uYA2l3X94xLjTFG8XtbXzdEp8//K6BFucX91WWEdPj0QiVKXsTs uN9aqQ9gGDCH+w7brLcImwE1EJttJQrF40Eskr7A= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([88.130.61.76]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M28WJ-1m0yZ82SRV-002Y8d; Mon, 12 Jul 2021 13:54:03 +0200 Date: Mon, 12 Jul 2021 13:54:01 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v5 2/5] replication: Reduce usage of s->hidden_disk and s->secondary_disk Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:aTD/jUkY9HIl09Fy3RdWJBgW9gT+cUK1u9XRCubmwJdS8qkuRDc 4EX3IYm1swi0PGkU3fFqK3lKdpnvwy6a5LJUv6J9jVQNMV1E9IkkBOm4BySHvg361JgZIOY XSE9qZK55rZ3WKObBHxEVArW/uDunVjWbt0nS2kU1d2uIdYsWQiDVETaz+V22d8i/EQE12o OhlrdtuN/CoLbqrxopkJw== X-UI-Out-Filterresults: notjunk:1;V03:K0:1xRWH4pzFXk=:yMA+6uj8utghZ3Yf6Y2OqV SlYdKuJZ4e+tXDhqTp8IHDqG43KjBrg090m103vjNLO7iLnHp9RGoktHOfDynKoNwu/FfkeJs IxlxlTXpffgvpd22S5CfoHPs+KVWO+wstfhTFtrfuwj4dtlczF/mBrT7u9SplDmQsyoz1NxCg lDjtmXAwEFpCIULSriBeidz5oDDOfe0SMFxwOoy6CvoE1eQIwFLOKm+G9/mqlsTHKb7OGMSmu 6okszG8+CPMWGh+ytGfTp+nasL2PrNpML4zzTOV1I2tIkoo0Emh/IgOiePhzcxXjmwg30ETvy LOHCdc6QTJSqJdgH46C3XXJgG5sRr5imh9FGHlxh2zTt7MtwWr5QUOFb0D7WiS26Awu9oaFAi vHqBnH8gK2yU0FZlZJZrNsjKj997DWUMl+Oga24/rXoZk5sXTVhTzsfr9U4Dj7/37hQTV2K0+ iu3VlwG43CKmzSMlEaygj9t2MhJPSpnKnq+1xE7+PWwI1OlK4Vv9yTK0tigITsDZ06ZxzVX6b ntGLg0174TXQFDmm1EsQaoe8vLv0xExZASi3madc78UEN/JNt4dqgCTa0XLG9skih+aSV5tt2 h6Ok4mHyFA0PT7QQxrK478yWA0jKMeUZ4ufN/bekv3Kj6c8IIvgFakZu2NfJFICYwPgleqg3F mzKPRfl6fY7nWMtp3iTM9W2acqdQvWhQ7BoBP9nws1LUkChaifgdmTsHpRxn78oA6z8azBffH nm65KcgpS/NS4DBKBu7RNa3tR7aZCbk1eMGZbthpK+G6sl5IfBIX1j0IoiPvj594yRmRUaof3 T35W21mqPAJW5OL0Vj2OwwCJNedBjgwG8BS8NxYpw1Eiv2PrWLzN+EcqCfHf0PMqsisIu3sZa Qsb4FPUl/DezK8T1+Yt5QIaxuQEswQ3q1VJGjWG3oHztghDXj8ab5ZRTqc8pmn9lEdWGiSsxF fubly06RKtB7v8P4TkoqX5OvTnDIIaPEnsfJM687eKLn3Wce6qp7VYHmMl7LNq4+9y2uuFE1f K6opPuGtARuVdesrNplJ0TZW7luONAAfXx+FjjNP68UHc41rEyxNTmE9IdnFuZdevcFpmPlxA PN0/ZW0maJA66JKu2ZYChE9EdgrVw9E0Fr4 Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block , Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In preparation for the next patch, initialize s->hidden_disk and s->secondary_disk later and replace access to them with local variables in the places where they aren't initialized yet. Signed-off-by: Lukas Straub Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/replication.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index 9ad2dfdc69..25bbdf5d4b 100644 --- a/block/replication.c +++ b/block/replication.c @@ -366,27 +366,35 @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, Error **errp) { BDRVReplicationState *s = bs->opaque; + BdrvChild *hidden_disk, *secondary_disk; BlockReopenQueue *reopen_queue = NULL; + /* + * s->hidden_disk and s->secondary_disk may not be set yet, as they will + * only be set after the children are writable. + */ + hidden_disk = bs->file->bs->backing; + secondary_disk = hidden_disk->bs->backing; + if (writable) { - s->orig_hidden_read_only = bdrv_is_read_only(s->hidden_disk->bs); - s->orig_secondary_read_only = bdrv_is_read_only(s->secondary_disk->bs); + s->orig_hidden_read_only = bdrv_is_read_only(hidden_disk->bs); + s->orig_secondary_read_only = bdrv_is_read_only(secondary_disk->bs); } - bdrv_subtree_drained_begin(s->hidden_disk->bs); - bdrv_subtree_drained_begin(s->secondary_disk->bs); + bdrv_subtree_drained_begin(hidden_disk->bs); + bdrv_subtree_drained_begin(secondary_disk->bs); if (s->orig_hidden_read_only) { QDict *opts = qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); - reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, + reopen_queue = bdrv_reopen_queue(reopen_queue, hidden_disk->bs, opts, true); } if (s->orig_secondary_read_only) { QDict *opts = qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); - reopen_queue = bdrv_reopen_queue(reopen_queue, s->secondary_disk->bs, + reopen_queue = bdrv_reopen_queue(reopen_queue, secondary_disk->bs, opts, true); } @@ -401,8 +409,8 @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, } } - bdrv_subtree_drained_end(s->hidden_disk->bs); - bdrv_subtree_drained_end(s->secondary_disk->bs); + bdrv_subtree_drained_end(hidden_disk->bs); + bdrv_subtree_drained_end(secondary_disk->bs); } static void backup_job_cleanup(BlockDriverState *bs) @@ -459,7 +467,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; BlockDriverState *top_bs; - BdrvChild *active_disk; + BdrvChild *active_disk, *hidden_disk, *secondary_disk; int64_t active_length, hidden_length, disk_length; AioContext *aio_context; Error *local_err = NULL; @@ -504,15 +512,15 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, return; } - s->hidden_disk = active_disk->bs->backing; - if (!s->hidden_disk->bs || !s->hidden_disk->bs->backing) { + hidden_disk = active_disk->bs->backing; + if (!hidden_disk->bs || !hidden_disk->bs->backing) { error_setg(errp, "Hidden disk doesn't have backing file"); aio_context_release(aio_context); return; } - s->secondary_disk = s->hidden_disk->bs->backing; - if (!s->secondary_disk->bs || !bdrv_has_blk(s->secondary_disk->bs)) { + secondary_disk = hidden_disk->bs->backing; + if (!secondary_disk->bs || !bdrv_has_blk(secondary_disk->bs)) { error_setg(errp, "The secondary disk doesn't have block backend"); aio_context_release(aio_context); return; @@ -520,8 +528,8 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, /* verify the length */ active_length = bdrv_getlength(active_disk->bs); - hidden_length = bdrv_getlength(s->hidden_disk->bs); - disk_length = bdrv_getlength(s->secondary_disk->bs); + hidden_length = bdrv_getlength(hidden_disk->bs); + disk_length = bdrv_getlength(secondary_disk->bs); if (active_length < 0 || hidden_length < 0 || disk_length < 0 || active_length != hidden_length || hidden_length != disk_length) { error_setg(errp, "Active disk, hidden disk, secondary disk's length" @@ -531,10 +539,10 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, } /* Must be true, or the bdrv_getlength() calls would have failed */ - assert(active_disk->bs->drv && s->hidden_disk->bs->drv); + assert(active_disk->bs->drv && hidden_disk->bs->drv); if (!active_disk->bs->drv->bdrv_make_empty || - !s->hidden_disk->bs->drv->bdrv_make_empty) { + !hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_empty"); aio_context_release(aio_context); @@ -549,6 +557,9 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, return; } + s->hidden_disk = hidden_disk; + s->secondary_disk = secondary_disk; + /* start backup job now */ error_setg(&s->blocker, "Block device is in use by internal backup job"); From patchwork Mon Jul 12 11:54:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12370815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9565C07E99 for ; Mon, 12 Jul 2021 11:58:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A339610E6 for ; Mon, 12 Jul 2021 11:58:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A339610E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2uaE-0008A0-J1 for qemu-devel@archiver.kernel.org; Mon, 12 Jul 2021 07:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW2-0000S7-Ij; Mon, 12 Jul 2021 07:54:26 -0400 Received: from mout.web.de ([217.72.192.78]:45139) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW0-0005wg-S0; Mon, 12 Jul 2021 07:54:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1626090847; bh=XrMo2wXI4WKVbPoMqH3ioO76/a0UaPjfPMhLaxMQpzU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=aIwU6bOisI5LN6VsOiJYlNUh902nie9Xrv5GqhJMf34dEqLpZmX+JqvZ6D8qs2o1q 2Hlv1118OXDSkqOunZ0tVEp8hHSd25xoaKfhawyDaI4//TTQMsYhH1LofF5/Hf3A0Z gYkL8s+sBDnqG55wdh+07XKzzPRiaL61QAud4ZGM= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([88.130.61.76]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N5CUp-1l2eks087J-0119P1; Mon, 12 Jul 2021 13:54:07 +0200 Date: Mon, 12 Jul 2021 13:54:05 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v5 3/5] replication: Properly attach children Message-ID: <4555f4074e16ed97e134ebd91ac5d9012f30fc70.1626090553.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:/3pJ3pjZuHGRFyVzk7IdQFwrfzT2drhh94cE6UeDIiO3LgbLpYw oBu7w29dvI3X3u4ozZpoCyj9dxtYpJCA/ryT9L9o6v3qUFdnZgfyu65MBymRz8hjy7cBugo z8/g3MpQW/XhZlyMotitqqwzR2mRdAByuWh3LaXdogI5rfOVjthrbPmKkTV2Vqu1grEfKLQ lTYUTLFXpGLM1Ewqr77nQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:GH2WfwWWJj8=:iPTiXU8A7Ci2Xg9L+C9s+2 CxsL/9mc4WgfJOvRgoDsKgNTghZFQ/yZGYbGVo+XHqQOH1g2DvQZHSnKqY48LKWcnSo/wsnmH 1toedT/UG+pDdB5nk6OJ0vIE+ZkPElogXJ3v57sZbgOPvAFAAOwb3etOp4JYshWB538pstN57 z6pOKY5DSSBSOMNE7+69eUJN7F/5mAJt9+tcUJU9Nk6NOooythA/W1b3mSeXcyYF6d4e4ecGt XxvVebLFEytpgrJofvnSd6fW8KaaTvdfIysmUc6+pzq6leKThOkA4y+8HkvQjZUiVlgZTjLc5 g/e4YUGuWHHRO49gqKjSQnR7HOqQXJVwLDqqCgj7lkt6BWqL7+ftpe4JyhTMsUEDIcLjMN+1Z JDLnmnbgktbGFdayhOmlJeh0jWR5KeS7+2GlnA+6AMS4UJTZqvXkF2/UwGITRpjvfHZrpPV4p nIMKJsLIPqoIB5sD39qxcmB3xlq4CRxcyVDmke7SS/yGrpAyBuhd+XJaejsSr5DfKzJzu76YT L6f0JBYkcgegMD8/XPeh+LRwuQbqqJso22TroQ7c0/dE8NepaP5Bm/sfNUPQ50NmKmhZWtgHG 1IQsU04YsOXRE0DwD2CBlcEnzFGz1ARW8tKrK000vcXWoo/6Bao7KfRqqck/hS2+c789kNROL QNYfY6bCknt5y4FnKIJg7TsmX5x+YHULDIdfSC777PLLHZ4uEJip/dg8aOdr+WK5AziSt4X3L goqwOK3lUhnBfXPpRfq7OR7cGtISmD8XBQymthmwngvr3NHfHsFbToZeK/NLXiimDuC1kU09u Wn2yV/3Cp4CyDmitCTUzCB/5Dfx+t/hbkD5BXvoqw4IqZhu6ABJGg84o6Joc/HZJBIm+x4qY6 ksVRndXfY7QusIiuFbkSEY/bkC/tsuHSG8Vi1rRzTGXbua/hl6SZxD3pCFH43l41gmBTjVhiw yHfDV66T0SVnSON4Q8UJpPCW3Pll8sSg4cGN2hPtLNYHLYU+RL3zNPbJHDxgUMjkEsAW84aD8 hkoYDF03+ONd+ZWs8B+2KLhBy4eP5V6SSf5y0qm40QI0V/DBNSkYF9yDgodAh3RCu/Gh8XSzC squ83eJAcJX4e/lEWedvLiBQdWdDWWAvo1m Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block , Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The replication driver needs access to the children block-nodes of it's child so it can issue bdrv_make_empty() and bdrv_co_pwritev() to manage the replication. However, it does this by directly copying the BdrvChilds, which is wrong. Fix this by properly attaching the block-nodes with bdrv_attach_child() and requesting the required permissions. This ultimatively fixes a potential crash in replication_co_writev(), because it may write to s->secondary_disk if it is in state BLOCK_REPLICATION_FAILOVER_FAILED, without requesting write permissions first. And now the workaround in secondary_do_checkpoint() can be removed. Signed-off-by: Lukas Straub Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/replication.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index 25bbdf5d4b..b74192f795 100644 --- a/block/replication.c +++ b/block/replication.c @@ -165,7 +165,12 @@ static void replication_child_perm(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - *nperm = BLK_PERM_CONSISTENT_READ; + if (role & BDRV_CHILD_PRIMARY) { + *nperm = BLK_PERM_CONSISTENT_READ; + } else { + *nperm = 0; + } + if ((bs->open_flags & (BDRV_O_INACTIVE | BDRV_O_RDWR)) == BDRV_O_RDWR) { *nperm |= BLK_PERM_WRITE; } @@ -557,8 +562,25 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, return; } - s->hidden_disk = hidden_disk; - s->secondary_disk = secondary_disk; + bdrv_ref(hidden_disk->bs); + s->hidden_disk = bdrv_attach_child(bs, hidden_disk->bs, "hidden disk", + &child_of_bds, BDRV_CHILD_DATA, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + aio_context_release(aio_context); + return; + } + + bdrv_ref(secondary_disk->bs); + s->secondary_disk = bdrv_attach_child(bs, secondary_disk->bs, + "secondary disk", &child_of_bds, + BDRV_CHILD_DATA, &local_err); + if (local_err) { + error_propagate(errp, local_err); + aio_context_release(aio_context); + return; + } /* start backup job now */ error_setg(&s->blocker, @@ -664,7 +686,9 @@ static void replication_done(void *opaque, int ret) if (ret == 0) { s->stage = BLOCK_REPLICATION_DONE; + bdrv_unref_child(bs, s->secondary_disk); s->secondary_disk = NULL; + bdrv_unref_child(bs, s->hidden_disk); s->hidden_disk = NULL; s->error = 0; } else { From patchwork Mon Jul 12 11:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12370817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64E30C07E99 for ; Mon, 12 Jul 2021 11:58:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2620561004 for ; Mon, 12 Jul 2021 11:58:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2620561004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2uaH-0008Fu-BN for qemu-devel@archiver.kernel.org; Mon, 12 Jul 2021 07:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW9-0000WN-1s; Mon, 12 Jul 2021 07:54:33 -0400 Received: from mout.web.de ([212.227.17.12]:38573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW4-0005yX-Ij; Mon, 12 Jul 2021 07:54:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1626090851; bh=aexX3buFrOB7dBsOnfVXQzYeQMJnVRzvUohu2kYYRhg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=Wgz0jZjSBPISwt/sggBRWGT6xZPB++ygWLs//BLaRK2iRDIXkXbkQqDM2ZUMLqkj5 Nk0WxR4O0+qc4u+nD5qQP+wZxeBx4elgBVKHYSZLUmveN7IGSC1XgA0qOy1Eb14do3 PRVO6hN3U8NdvCsGp5Mu2agP1rhxVYoeodRtxOa4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([88.130.61.76]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M5OYl-1lEFbg2cYR-00zXCw; Mon, 12 Jul 2021 13:54:11 +0200 Date: Mon, 12 Jul 2021 13:54:09 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v5 4/5] replication: Assert that children are writable Message-ID: <360083cb9c08e364eb99e232b2705226b23f4503.1626090553.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:dK0CITChRmUTOU9UqL8Gh9Y1vdCDJ4XuNftiKW5RzSnIo4JfeXH YoxXNa6Hp0/HZLBP3JBqur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uw90oWSZF7sKKgjOs SxTDiYt6VYwTJePkFne+6Whuk1P8V4rApsXcHKf5a+xJsRAcyvQyKF7iZbNYWzZHu9JBm+ZsW 9eJbAgHk/jscT1rfJ6fU5vkLpGS/74EYcNX5oJBy42UJ9Y1xKVHLmjlAqX9yJAb5E4vrrRFQr +AO/UAyd6T9WPbz9MAWyTebOGDmxi867A7OyFuKw3FU2aOtQ00yes+m8oNW7xQ1wZ2QmQOaZh Z06/UNhuTuUP3QUp1g/u2gWEO6vWXkiOBQ3 Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block , Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Assert that the children are writable where it's needed. While there is no test-case for the BLOCK_REPLICATION_FAILOVER_FAILED state, this at least ensures that s->secondary_disk is always writable in case replication might go into that state. Signed-off-by: Lukas Straub --- block/replication.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index b74192f795..772bb63374 100644 --- a/block/replication.c +++ b/block/replication.c @@ -261,6 +261,13 @@ static coroutine_fn int replication_co_writev(BlockDriverState *bs, int64_t n; assert(!flags); + assert(top->perm & BLK_PERM_WRITE); + if (s->mode == REPLICATION_MODE_SECONDARY && + s->stage != BLOCK_REPLICATION_NONE && + s->stage != BLOCK_REPLICATION_DONE) { + assert(base->perm & BLK_PERM_WRITE); + } + ret = replication_get_io_status(s); if (ret < 0) { goto out; @@ -318,6 +325,9 @@ static void secondary_do_checkpoint(BlockDriverState *bs, Error **errp) Error *local_err = NULL; int ret; + assert(active_disk->perm & BLK_PERM_WRITE); + assert(s->hidden_disk->perm & BLK_PERM_WRITE); + if (!s->backup_job) { error_setg(errp, "Backup job was cancelled unexpectedly"); return; From patchwork Mon Jul 12 11:54:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 12370819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79996C07E99 for ; Mon, 12 Jul 2021 11:59:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F15F161004 for ; Mon, 12 Jul 2021 11:59:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F15F161004 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2ubK-0002JK-W8 for qemu-devel@archiver.kernel.org; Mon, 12 Jul 2021 07:59:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW9-0000Wl-Fn; Mon, 12 Jul 2021 07:54:33 -0400 Received: from mout.web.de ([212.227.17.11]:57453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2uW5-0005zS-4b; Mon, 12 Jul 2021 07:54:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1626090855; bh=28jQJ+YAJQ1b41afUYKfr8L0ZoTRrU9xPacgIfbcigU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=arUq7sYDu2iVxdXCHtNtMAnunoZFQDdViarfl4qXdErRMR/cnoxJDbe7jnpMKuwi3 Rs01tq7+RK4aTA+4Q5I19OU7wXqT1ZSMnIGGgKOrDab/OUaKAFYDeHhHGqVAzqR/F7 i6ev9sdIhcQf4g1gWyY9rmSm/jIyHxG3cypgFf1o= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from gecko.fritz.box ([88.130.61.76]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1N0qr9-1lFuIU1gHN-00wpxH; Mon, 12 Jul 2021 13:54:15 +0200 Date: Mon, 12 Jul 2021 13:54:13 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v5 5/5] replication: Remove workaround Message-ID: In-Reply-To: References: MIME-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YLoZSGo+tryyym5Oja7uVRtsC1 WAeYmmhKpjB251j+Exu4U225RpIKnf9jBt0L3+yFt8KW1dHRfku+s1jQwhY0G89wL1xLCoK/V 8NpHnkwGqfuCGQv1a1OynRhkhKKc7w7E3QwzVBu59CmBajwg/vZOoRAgv2I4tiiHP7pVJuG71 0yNhRtSVzdt4KRWEBJvwLosjVR9f2Vs4XmFnoT/sxJ/ZttkOvkN/uodDheskWwlRBHP9V5Z1V DDJIBYlN0EirP+YwHuOFot5pzFmCfNaYkVu/uSu00infYtvA6spJ20qrFW0JbB1WhI7AxG79s N81y/VCBnoqFqkKR+v1110MGZBACNjbzCAJ Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-block , Wen Congyang , Xie Changlong , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Remove the workaround introduced in commit 6ecbc6c52672db5c13805735ca02784879ce8285 "replication: Avoid blk_make_empty() on read-only child". It is not needed anymore since s->hidden_disk is guaranteed to be writable when secondary_do_checkpoint() runs. Because replication_start(), _do_checkpoint() and _stop() are only called by COLO migration code and COLO-migration activates all disks via bdrv_invalidate_cache_all() before it calls these functions. Signed-off-by: Lukas Straub Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/replication.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index 772bb63374..1e9dc4d309 100644 --- a/block/replication.c +++ b/block/replication.c @@ -356,17 +356,7 @@ static void secondary_do_checkpoint(BlockDriverState *bs, Error **errp) return; } - BlockBackend *blk = blk_new(qemu_get_current_aio_context(), - BLK_PERM_WRITE, BLK_PERM_ALL); - blk_insert_bs(blk, s->hidden_disk->bs, &local_err); - if (local_err) { - error_propagate(errp, local_err); - blk_unref(blk); - return; - } - - ret = blk_make_empty(blk, errp); - blk_unref(blk); + ret = bdrv_make_empty(s->hidden_disk, errp); if (ret < 0) { return; }