From nobody Sat Feb 7 06:39:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1557156989; cv=none; d=zoho.com; s=zohoarc; b=l7LhgLlfm0bmvrnn41WAQfASNEkX0SIQP5XQ5qhSJlgbJ0fi3AZYAASuRmYxAIjfFWIIyC73LTlj8PQSDOvU6A/AKx3IxXreJGFIOADbNpfjrx/SCuyrS5S4FKIlIcCe7kIoYXk1rgB1LvBBjSGrtaHFP69Ks0umjan+zK3PeE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557156989; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=n29kOWkLlnhGqe402tmxxAvBhnAiCj7lMOtW4VvW7kk=; b=Ut4hk4BLagUL4M+QPMnsTx98PcjXJ+hAMH86QPxw+wyl8066nlYeEjG3zkP8ATyWys3+BP7p/6K8e/o8PrD3UkQby2Y+IHKddq3Cl+v6Pg+37ZlZmMOZM4I0REecZO5vvxvkihwesinCE42vhnm9UVZnp/U/E/Wx+5oif1qCzeI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557156988950396.90389128508195; Mon, 6 May 2019 08:36:28 -0700 (PDT) Received: from localhost ([127.0.0.1]:58334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNffE-0007yJ-KU for importer@patchew.org; Mon, 06 May 2019 11:36:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNfdX-0006wD-6o for qemu-devel@nongnu.org; Mon, 06 May 2019 11:34:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNfdV-0005xA-Pr for qemu-devel@nongnu.org; Mon, 06 May 2019 11:34:39 -0400 Received: from relay.sw.ru ([185.231.240.75]:48336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNfdV-0005vj-Hv; Mon, 06 May 2019 11:34:37 -0400 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hNfdP-0004Z1-7K; Mon, 06 May 2019 18:34:31 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Mon, 6 May 2019 18:34:29 +0300 Message-Id: <20190506153429.52737-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190506153429.52737-1-vsementsov@virtuozzo.com> References: <20190506153429.52737-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v6 3/3] block/stream: introduce a bottom node 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, berto@igalia.com, wencongyang2@huawei.com, xiechanglong.d@gmail.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, andrey.shinkevich@virtuozzo.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Andrey Shinkevich The bottom node is the intermediate block device that has the base as its backing image. It is used instead of the base node while a block stream job is running to avoid dependency on the base that may change due to the parallel jobs. The change may take place due to a filter node as well that is inserted between the base and the intermediate bottom node. It occurs when the base node is the top one for another commit or stream job. After the introduction of the bottom node, don't freeze its backing child, that's the base, anymore. Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block/stream.c | 49 +++++++++++++++++++++--------------------- tests/qemu-iotests/245 | 4 ++-- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/block/stream.c b/block/stream.c index 65b13b27e0..fc97c89f81 100644 --- a/block/stream.c +++ b/block/stream.c @@ -31,7 +31,7 @@ enum { =20 typedef struct StreamBlockJob { BlockJob common; - BlockDriverState *base; + BlockDriverState *bottom; BlockdevOnError on_error; char *backing_file_str; bool bs_read_only; @@ -54,7 +54,7 @@ static void stream_abort(Job *job) =20 if (s->chain_frozen) { BlockJob *bjob =3D &s->common; - bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->base); + bdrv_unfreeze_backing_chain(blk_bs(bjob->blk), s->bottom); } } =20 @@ -63,11 +63,11 @@ static int stream_prepare(Job *job) StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockJob *bjob =3D &s->common; BlockDriverState *bs =3D blk_bs(bjob->blk); - BlockDriverState *base =3D s->base; + BlockDriverState *base =3D backing_bs(s->bottom); Error *local_err =3D NULL; int ret =3D 0; =20 - bdrv_unfreeze_backing_chain(bs, base); + bdrv_unfreeze_backing_chain(bs, s->bottom); s->chain_frozen =3D false; =20 if (bs->backing) { @@ -110,7 +110,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) 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; + bool enable_cor =3D !backing_bs(s->bottom); int64_t len; int64_t offset =3D 0; uint64_t delay_ns =3D 0; @@ -119,7 +119,8 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) int64_t n =3D 0; /* bytes */ void *buf; =20 - if (!bs->backing) { + if (bs =3D=3D s->bottom) { + /* Nothing to stream */ return 0; } =20 @@ -136,7 +137,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) * backing chain since the copy-on-read operation does not take base i= nto * account. */ - if (!base) { + if (enable_cor) { bdrv_enable_copy_on_read(bs); } =20 @@ -159,9 +160,8 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } else if (ret >=3D 0) { /* Copy if allocated in the intermediate images. Limit to the * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ - ret =3D bdrv_is_allocated_above(backing_bs(bs), base, false, + ret =3D bdrv_is_allocated_above(backing_bs(bs), s->bottom, tru= e, offset, n, &n); - /* Finish early if end of backing file has been reached */ if (ret =3D=3D 0 && n =3D=3D 0) { n =3D len - offset; @@ -198,7 +198,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } } =20 - if (!base) { + if (enable_cor) { bdrv_disable_copy_on_read(bs); } =20 @@ -230,8 +230,10 @@ void stream_start(const char *job_id, BlockDriverState= *bs, StreamBlockJob *s; BlockDriverState *iter; bool bs_read_only; + int basic_flags =3D BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGE= D; + BlockDriverState *bottom =3D bdrv_find_overlay(bs, base); =20 - if (bdrv_freeze_backing_chain(bs, base, errp) < 0) { + if (bdrv_freeze_backing_chain(bs, bottom, errp) < 0) { return; } =20 @@ -248,26 +250,25 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, * already have our own plans. Also don't allow resize as the image si= ze is * queried only at the job start and then cached. */ s =3D block_job_create(job_id, &stream_job_driver, NULL, bs, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | - BLK_PERM_GRAPH_MOD, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANG= ED | - BLK_PERM_WRITE, + basic_flags | BLK_PERM_GRAPH_MOD, + basic_flags | BLK_PERM_WRITE, speed, creation_flags, NULL, NULL, errp); if (!s) { goto fail; } =20 - /* Block all intermediate nodes between bs and base, because they will - * disappear from the chain after this operation. The streaming job re= ads - * every block only once, assuming that it doesn't change, so block wr= ites - * and resizes. */ - for (iter =3D backing_bs(bs); iter && iter !=3D base; iter =3D backing= _bs(iter)) { - block_job_add_bdrv(&s->common, "intermediate node", iter, 0, - BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHA= NGED, - &error_abort); + /* + * Block all intermediate nodes between bs and bottom (inclusive), bec= ause + * they will disappear from the chain after this operation. The stream= ing + * job reads every block only once, assuming that it doesn't change, so + * forbid writes and resizes. + */ + for (iter =3D bs; iter !=3D bottom; iter =3D backing_bs(iter)) { + block_job_add_bdrv(&s->common, "intermediate node", backing_bs(ite= r), + 0, basic_flags, &error_abort); } =20 - s->base =3D base; + s->bottom =3D bottom; s->backing_file_str =3D g_strdup(backing_file_str); s->bs_read_only =3D bs_read_only; s->chain_frozen =3D true; diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245 index a04c6235c1..006f9f72f0 100644 --- a/tests/qemu-iotests/245 +++ b/tests/qemu-iotests/245 @@ -865,9 +865,9 @@ class TestBlockdevReopen(iotests.QMPTestCase): device =3D 'hd0', base_node =3D 'hd2', speed = =3D 512 * 1024) self.assert_qmp(result, 'return', {}) =20 - # We can't remove hd2 while the stream job is ongoing + # We can remove hd2 while the stream job is ongoing opts['backing']['backing'] =3D None - self.reopen(opts, {}, "Cannot change 'backing' link from 'hd1' to = 'hd2'") + self.reopen(opts, {}) =20 # We can't remove hd1 while the stream job is ongoing opts['backing'] =3D None --=20 2.18.0