From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 7AA1CC432BE for ; Wed, 1 Sep 2021 15:42:22 +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 051A760F3A for ; Wed, 1 Sep 2021 15:42:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 051A760F3A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLSNX-0005Wg-Sr for qemu-devel@archiver.kernel.org; Wed, 01 Sep 2021 11:42:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLRzQ-0005MB-BG for qemu-devel@nongnu.org; Wed, 01 Sep 2021 11:17:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLRzO-0003mM-1m for qemu-devel@nongnu.org; Wed, 01 Sep 2021 11:17:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630509441; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pA8KdcqXP2kmo4Kd3McR9IkUAKKssIl/xZYVTCDPy1Y=; b=UTvZkj+CjSmrgRN6C8RSpwf9JCmAcC2QcMIPkkVhQQYUoFRXTTcYmysCXLi8diwPs/gINu d/Adi2yrGiJRFqbepZvR+fwZEQFMbet22KK2i+GpSwmRF9uX7UL1FlzJ3sTtC2bFOD6ngN vTp92ozd0emD2jDGIhjArfcyGhT3/E4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-14o84Fn_P1u9VL8XUfOfvA-1; Wed, 01 Sep 2021 11:17:19 -0400 X-MC-Unique: 14o84Fn_P1u9VL8XUfOfvA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70451801A92; Wed, 1 Sep 2021 15:17:18 +0000 (UTC) Received: from localhost (unknown [10.39.193.250]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E88236A05B; Wed, 1 Sep 2021 15:17:17 +0000 (UTC) From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PULL 26/56] block-copy: move detecting fleecing scheme to block-copy Date: Wed, 1 Sep 2021 17:15:49 +0200 Message-Id: <20210901151619.689075-27-hreitz@redhat.com> In-Reply-To: <20210901151619.689075-1-hreitz@redhat.com> References: <20210901151619.689075-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=170.10.133.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 , Peter Maydell , Hanna Reitz , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Vladimir Sementsov-Ogievskiy We want to simplify initialization interface of copy-before-write filter as we are going to make it public. So, let's detect fleecing scheme exactly in block-copy code, to not pass this information through extra levels. Why not just set BDRV_REQ_SERIALISING unconditionally: because we are going to implement new more efficient fleecing scheme which will not rely on backing feature. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz Message-Id: <20210824083856.17408-7-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz --- block/copy-before-write.h | 2 +- include/block/block-copy.h | 3 +-- block/backup.c | 21 +-------------------- block/block-copy.c | 24 +++++++++++++++++++++--- block/copy-before-write.c | 4 ++-- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/block/copy-before-write.h b/block/copy-before-write.h index 5977b7aa31..f37e2249ae 100644 --- a/block/copy-before-write.h +++ b/block/copy-before-write.h @@ -34,7 +34,7 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *source, const char *filter_node_name, uint64_t cluster_size, BackupPerf *perf, - BdrvRequestFlags write_flags, + bool compress, BlockCopyState **bcs, Error **errp); void bdrv_cbw_drop(BlockDriverState *bs); diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 5c8278895c..734389d32a 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -26,8 +26,7 @@ typedef struct BlockCopyCallState BlockCopyCallState; BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, bool use_copy_range, - BdrvRequestFlags write_flags, - Error **errp); + bool compress, Error **errp); void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm); diff --git a/block/backup.c b/block/backup.c index ac91821b08..84f9a5f02c 100644 --- a/block/backup.c +++ b/block/backup.c @@ -407,7 +407,6 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, int64_t len, target_len; BackupBlockJob *job = NULL; int64_t cluster_size; - BdrvRequestFlags write_flags; BlockDriverState *cbw = NULL; BlockCopyState *bcs = NULL; @@ -504,26 +503,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, goto error; } - /* - * If source is in backing chain of target assume that target is going to be - * used for "image fleecing", i.e. it should represent a kind of snapshot of - * source at backup-start point in time. And target is going to be read by - * somebody (for example, used as NBD export) during backup job. - * - * In this case, we need to add BDRV_REQ_SERIALISING write flag to avoid - * intersection of backup writes and third party reads from target, - * otherwise reading from target we may occasionally read already updated by - * guest data. - * - * For more information see commit f8d59dfb40bb and test - * tests/qemu-iotests/222 - */ - write_flags = (bdrv_chain_contains(target, bs) ? BDRV_REQ_SERIALISING : 0) | - (compress ? BDRV_REQ_WRITE_COMPRESSED : 0), - cbw = bdrv_cbw_append(bs, target, filter_node_name, - cluster_size, perf, - write_flags, &bcs, errp); + cluster_size, perf, compress, &bcs, errp); if (!cbw) { goto error; } diff --git a/block/block-copy.c b/block/block-copy.c index 0becad52da..58b4345a5a 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -317,10 +317,11 @@ static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *target) BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, int64_t cluster_size, bool use_copy_range, - BdrvRequestFlags write_flags, Error **errp) + bool compress, Error **errp) { BlockCopyState *s; BdrvDirtyBitmap *copy_bitmap; + bool is_fleecing; copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL, errp); @@ -329,6 +330,22 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, } bdrv_disable_dirty_bitmap(copy_bitmap); + /* + * If source is in backing chain of target assume that target is going to be + * used for "image fleecing", i.e. it should represent a kind of snapshot of + * source at backup-start point in time. And target is going to be read by + * somebody (for example, used as NBD export) during backup job. + * + * In this case, we need to add BDRV_REQ_SERIALISING write flag to avoid + * intersection of backup writes and third party reads from target, + * otherwise reading from target we may occasionally read already updated by + * guest data. + * + * For more information see commit f8d59dfb40bb and test + * tests/qemu-iotests/222 + */ + is_fleecing = bdrv_chain_contains(target->bs, source->bs); + s = g_new(BlockCopyState, 1); *s = (BlockCopyState) { .source = source, @@ -336,7 +353,8 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, .copy_bitmap = copy_bitmap, .cluster_size = cluster_size, .len = bdrv_dirty_bitmap_size(copy_bitmap), - .write_flags = write_flags, + .write_flags = (is_fleecing ? BDRV_REQ_SERIALISING : 0) | + (compress ? BDRV_REQ_WRITE_COMPRESSED : 0), .mem = shres_create(BLOCK_COPY_MAX_MEM), .max_transfer = QEMU_ALIGN_DOWN( block_copy_max_transfer(source, target), @@ -351,7 +369,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target, * behalf). */ s->method = COPY_READ_WRITE_CLUSTER; - } else if (write_flags & BDRV_REQ_WRITE_COMPRESSED) { + } else if (compress) { /* Compression supports only cluster-size writes and no copy-range. */ s->method = COPY_READ_WRITE_CLUSTER; } else { diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 0dc5a107cf..4337076c1c 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -171,7 +171,7 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *source, const char *filter_node_name, uint64_t cluster_size, BackupPerf *perf, - BdrvRequestFlags write_flags, + bool compress, BlockCopyState **bcs, Error **errp) { @@ -218,7 +218,7 @@ BlockDriverState *bdrv_cbw_append(BlockDriverState *source, state->cluster_size = cluster_size; state->bcs = block_copy_state_new(top->backing, state->target, cluster_size, perf->use_copy_range, - write_flags, errp); + compress, errp); if (!state->bcs) { error_prepend(errp, "Cannot create block-copy-state: "); goto fail; -- 2.31.1