From nobody Thu May 2 16:32:30 2024 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=1573922173; cv=none; d=zoho.com; s=zohoarc; b=NdAVPuKt76hgMuh3TrSbq1QLGO2f3SNWhWvObRSJ4HBM2eeHAq55AhSpdJYLHGo59DPXI/M7Gz6/F/ecJloP9It9TUD4dl4oj8VYnD38zJg0Nn+BWSL/fGDNdAkY34S5W1iLoU/4pkwwpIZ7KI/HXfivWiW0+EORHndImvw5A04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573922173; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dhgoBuuSq9e0Wv36sY//39mqAuKUSgIvu7swaNCySpg=; b=gWmugTGqOBjdJX35UT1MOA5N5n2ToxbJGO593TIdiNwch9MO6VR2+fPBzAYMo6REEixE5IlXAzgjDkeSoQkmheaE53kSW1LENT2R3JZPUAklZjilSssNhm6+uVrrpVJ2k957KjALpznciH8IZadmoynwzqjOpWo+ISoPemjw3PI= 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 1573922173294677.4698701161888; Sat, 16 Nov 2019 08:36:13 -0800 (PST) Received: from localhost ([::1]:48960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW13T-00074P-Ri for importer@patchew.org; Sat, 16 Nov 2019 11:36:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58881) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW11j-00053v-C7 for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iW11h-0005Th-T4 for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:23 -0500 Received: from relay.sw.ru ([185.231.240.75]:37810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iW11f-0005RQ-1y; Sat, 16 Nov 2019 11:34:19 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iW11Y-0005cn-5v; Sat, 16 Nov 2019 19:34:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 1/4] block/io: fix bdrv_co_block_status_above Date: Sat, 16 Nov 2019 19:34:07 +0300 Message-Id: <20191116163410.12129-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191116163410.12129-1-vsementsov@virtuozzo.com> References: <20191116163410.12129-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_co_block_status_above has several problems with handling short backing files: 1. With want_zeros=3Dtrue, it may return ret with BDRV_BLOCK_ZERO but without BDRV_BLOCK_ALLOCATED flag, when actually short backing file which produces these after-EOF zeros is inside requested backing sequesnce. 2. With want_zeros=3Dfalse, it will just stop inside requested region, if we have unallocated region in top node when underlying backing is short. Fix these things, making logic about short backing files clearer. Note that 154 output changed, because now bdrv_block_status_above don't merge unallocated zeros with zeros after EOF (which are actually "allocated" in POV of read from backing-chain top) and is_zero() just don't understand that the whole head or tail is zero. We may update is_zero to call bdrv_block_status_above several times, or add flag to bdrv_block_status_above that we are not interested in ALLOCATED flag, so ranges with different ALLOCATED status may be merged, but actually, it seems that we'd better don't care about this corner case. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 41 ++++++++++++++++++++++++++++---------- tests/qemu-iotests/154.out | 4 ++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/block/io.c b/block/io.c index f75777f5ea..4d7fa99bd2 100644 --- a/block/io.c +++ b/block/io.c @@ -2434,25 +2434,44 @@ static int coroutine_fn bdrv_co_block_status_above(= BlockDriverState *bs, ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { - break; + return ret; } - if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { + if (*pnum =3D=3D 0) { + if (first) { + return ret; + } + /* - * Reading beyond the end of the file continues to read - * zeroes, but we can only widen the result to the - * unallocated length we learned from an earlier - * iteration. + * Reads from bs for selected region will return zeroes, produ= ced + * because current level is short. We should consider it as + * allocated. + * + * TODO: Should we report p as file here? */ + assert(ret & BDRV_BLOCK_EOF); *pnum =3D bytes; + return BDRV_BLOCK_ZERO | BDRV_BLOCK_ALLOCATED; } - if (ret & (BDRV_BLOCK_ZERO | BDRV_BLOCK_DATA)) { - break; + if (ret & BDRV_BLOCK_ALLOCATED) { + /* We've found the node and the status, we must return. */ + + if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { + /* + * This level also responsible for reads after EOF inside + * unallocated region in previous level. + */ + *pnum =3D bytes; + } + + return ret; } - /* [offset, pnum] unallocated on this layer, which could be only - * the first part of [offset, bytes]. */ - bytes =3D MIN(bytes, *pnum); + + /* Proceed to backing */ + assert(*pnum <=3D bytes); + bytes =3D *pnum; first =3D false; } + return ret; } =20 diff --git a/tests/qemu-iotests/154.out b/tests/qemu-iotests/154.out index fa3673317f..a203dfcadd 100644 --- a/tests/qemu-iotests/154.out +++ b/tests/qemu-iotests/154.out @@ -310,13 +310,13 @@ wrote 512/512 bytes at offset 134217728 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 2048/2048 bytes allocated at offset 128 MiB [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": fals= e}, -{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": fa= lse}] +{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": t= rue, "offset": OFFSET}] Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134219776 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 512/512 bytes at offset 134219264 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 2048/2048 bytes allocated at offset 128 MiB [{ "start": 0, "length": 134217728, "depth": 1, "zero": true, "data": fals= e}, -{ "start": 134217728, "length": 2048, "depth": 0, "zero": true, "data": fa= lse}] +{ "start": 134217728, "length": 2048, "depth": 0, "zero": false, "data": t= rue, "offset": OFFSET}] Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134219776 backing_file= =3DTEST_DIR/t.IMGFMT.base wrote 1024/1024 bytes at offset 134218240 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) --=20 2.21.0 From nobody Thu May 2 16:32:30 2024 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=1573922186; cv=none; d=zoho.com; s=zohoarc; b=C09y2epnrDbM2F6oqFN9VAe7c3iJYGG936vJmJFjJ1jVkER9YZ5kjAoKPVR/AWqEIO+Bpvpume2YeSyRHDenG3gnxyLsuQcFh2XK4opOq21v2UPu5Tjr4uvtTuzIaZ58nSYul9JhTG6r3fyIZxmW0EHcI3dPDZTgZA92/Y7+Yeo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573922186; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GNR6oK41a9I3Us/lMwEmPR2NK4pSNFss2+ANjjzPxzw=; b=DqKklPk22ox9A3RAhfgK5nouyovCse0TChuLlvJTMz6u6+ElxzlL+arLK0Z5VLTSg6gZg+pn/ME+ENp53laSVdihfKWO08z0XuCr3AV9AJMAJzKutXKrWPRFZkvu51SR9UQvbwejX4/QvXIX5UHPmCXDYVtbfBjs8bcWsZS4ZFw= 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 1573922186719812.3957964500837; Sat, 16 Nov 2019 08:36:26 -0800 (PST) Received: from localhost ([::1]:48962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW13c-0007Os-Lb for importer@patchew.org; Sat, 16 Nov 2019 11:36:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58866) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW11i-00052v-S8 for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iW11h-0005TU-NG for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:22 -0500 Received: from relay.sw.ru ([185.231.240.75]:37816) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iW11f-0005RT-3q; Sat, 16 Nov 2019 11:34:19 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iW11Y-0005cn-96; Sat, 16 Nov 2019 19:34:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 2/4] block/io: bdrv_common_block_status_above: support include_base Date: Sat, 16 Nov 2019 19:34:08 +0300 Message-Id: <20191116163410.12129-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191116163410.12129-1-vsementsov@virtuozzo.com> References: <20191116163410.12129-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In order to reuse bdrv_common_block_status_above in bdrv_is_allocated_above, let's support include_base parameter. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf --- block/io.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 4d7fa99bd2..df3ecf2430 100644 --- a/block/io.c +++ b/block/io.c @@ -2196,6 +2196,7 @@ int bdrv_flush_all(void) typedef struct BdrvCoBlockStatusData { BlockDriverState *bs; BlockDriverState *base; + bool include_base; bool want_zero; int64_t offset; int64_t bytes; @@ -2418,6 +2419,7 @@ early_out: =20 static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, @@ -2429,8 +2431,8 @@ static int coroutine_fn bdrv_co_block_status_above(Bl= ockDriverState *bs, int ret =3D 0; bool first =3D true; =20 - assert(bs !=3D base); - for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { + assert(include_base || bs !=3D base); + for (p =3D bs; include_base || p !=3D base; p =3D backing_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); if (ret < 0) { @@ -2466,6 +2468,10 @@ static int coroutine_fn bdrv_co_block_status_above(B= lockDriverState *bs, return ret; } =20 + if (p =3D=3D base) { + break; + } + /* Proceed to backing */ assert(*pnum <=3D bytes); bytes =3D *pnum; @@ -2481,7 +2487,7 @@ static void coroutine_fn bdrv_block_status_above_co_e= ntry(void *opaque) BdrvCoBlockStatusData *data =3D opaque; =20 data->ret =3D bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, + data->include_base, data->want_= zero, data->offset, data->bytes, data->pnum, data->map, data->fi= le); data->done =3D true; @@ -2495,6 +2501,7 @@ static void coroutine_fn bdrv_block_status_above_co_e= ntry(void *opaque) */ static int bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, + bool include_base, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, @@ -2504,6 +2511,7 @@ static int bdrv_common_block_status_above(BlockDriver= State *bs, BdrvCoBlockStatusData data =3D { .bs =3D bs, .base =3D base, + .include_base =3D include_base, .want_zero =3D want_zero, .offset =3D offset, .bytes =3D bytes, @@ -2528,7 +2536,7 @@ int bdrv_block_status_above(BlockDriverState *bs, Blo= ckDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) { - return bdrv_common_block_status_above(bs, base, true, offset, bytes, + return bdrv_common_block_status_above(bs, base, false, true, offset, b= ytes, pnum, map, file); } =20 @@ -2545,7 +2553,7 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t offset, int ret; int64_t dummy; =20 - ret =3D bdrv_common_block_status_above(bs, backing_bs(bs), false, offs= et, + ret =3D bdrv_common_block_status_above(bs, bs, true, false, offset, bytes, pnum ? pnum : &dummy, NULL, NULL); if (ret < 0) { --=20 2.21.0 From nobody Thu May 2 16:32:30 2024 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=1573922204; cv=none; d=zoho.com; s=zohoarc; b=V7CrKALDXm7WmRVeFEo54euApYhukXYvjkgX7GSYJU/llTarAWcoo0+nMbZhaFHZMXdEFg+H0CK6nu2nTC15wX3JHj9Bv32L/Tp7jWZ/qrikI0H53wX9lRgRuGqjh47F46UxnikqHoWH3lso7KtwTINl4wBBl06kJyz9jbii+fY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573922204; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PlPAAB7R/KUBVo6XLcV5kU+z6zeYClKX47OgC201kcM=; b=PpeuO4mdAq8w0MABNLsR10R3gBaeBcG94Hu6z+RklWQMv4HhJg4uKqHVtH3Enz2IFSn0IdmuHNUUyzSe5bW9n9qVydldVdZQH1A4kEj9Hb17yCBAD/GxtuDYT0AqANv9IqeMKfCQCnnNwk1+QR6XNzZi/uwKQBjK0MTgR8WI9a8= 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 1573922204167773.9371925632627; Sat, 16 Nov 2019 08:36:44 -0800 (PST) Received: from localhost ([::1]:48966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW13y-0007f0-Va for importer@patchew.org; Sat, 16 Nov 2019 11:36:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58854) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW11i-00051u-Ec for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iW11h-0005TB-9L for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:22 -0500 Received: from relay.sw.ru ([185.231.240.75]:37800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iW11f-0005RU-3r; Sat, 16 Nov 2019 11:34:19 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iW11Y-0005cn-GP; Sat, 16 Nov 2019 19:34:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 3/4] block/io: bdrv_common_block_status_above: support bs == base Date: Sat, 16 Nov 2019 19:34:09 +0300 Message-Id: <20191116163410.12129-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191116163410.12129-1-vsementsov@virtuozzo.com> References: <20191116163410.12129-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We are going to reuse bdrv_common_block_status_above in bdrv_is_allocated_above. bdrv_is_allocated_above may be called with include_base =3D=3D false and still bs =3D=3D base (for ex. from img_rebase= ()). So, support this corner case. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf --- block/io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index df3ecf2430..f05b2e8ecc 100644 --- a/block/io.c +++ b/block/io.c @@ -2431,7 +2431,11 @@ static int coroutine_fn bdrv_co_block_status_above(B= lockDriverState *bs, int ret =3D 0; bool first =3D true; =20 - assert(include_base || bs !=3D base); + if (!include_base && bs =3D=3D base) { + *pnum =3D bytes; + return 0; + } + for (p =3D bs; include_base || p !=3D base; p =3D backing_bs(p)) { ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, file); --=20 2.21.0 From nobody Thu May 2 16:32:30 2024 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=1573922281; cv=none; d=zoho.com; s=zohoarc; b=QhDBdxtuxDMavK9WEJ2aKmGK5gaHLvd3zxQ8duBc9WGQ9kGislgng0mrQiZpwVXpJBoIjJilM7rT5WuuuuC9CqTPZcVYS8Z4dnNJRzL4sU4kZxH4NzWGFboXXZWgqp51Bx0WGl4QDULi2a2hCbPbEhAsfczHUhHdD6Y71rqbFBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573922281; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pBNtoLbOwYefw/hq7Bcv8uA8xQ7zPgKfc0DzgE8qNXo=; b=mNPshyTDE/Sesp0LvgtGxlNN9rsbcEIrNKv7xf8oDX2LCAoZXw9xS8TSa34tRsGzgcL7aMb4NsSvWQEbZ1NaITjcja+5961V7d5FSFMvNke5WzS74SA2YtOg8amThbOGV1E8oGnrbam5zpLwttFu3dj4f5Jp6zXk3UqD/wOAqds= 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 1573922281698132.0635681115716; Sat, 16 Nov 2019 08:38:01 -0800 (PST) Received: from localhost ([::1]:48998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW15E-0001Uh-Ib for importer@patchew.org; Sat, 16 Nov 2019 11:38:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58856) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iW11i-000529-IN for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iW11h-0005TG-D3 for qemu-devel@nongnu.org; Sat, 16 Nov 2019 11:34:22 -0500 Received: from relay.sw.ru ([185.231.240.75]:37806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iW11f-0005RS-1m; Sat, 16 Nov 2019 11:34:19 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iW11Y-0005cn-Ju; Sat, 16 Nov 2019 19:34:12 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 4/4] block/io: fix bdrv_is_allocated_above Date: Sat, 16 Nov 2019 19:34:10 +0300 Message-Id: <20191116163410.12129-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191116163410.12129-1-vsementsov@virtuozzo.com> References: <20191116163410.12129-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_is_allocated_above wrongly handles short backing files: it reports after-EOF space as UNALLOCATED which is wrong, as on read the data is generated on the level of short backing file (if all overlays has unallocated area at that place). Reusing bdrv_common_block_status_above fixes the issue and unifies code path. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/block/io.c b/block/io.c index f05b2e8ecc..6946120587 100644 --- a/block/io.c +++ b/block/io.c @@ -2581,52 +2581,19 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState= *bs, int64_t offset, * at 'offset + *pnum' may return the same allocation status (in other * words, the result is not necessarily the maximum possible range); * but 'pnum' will only be 0 when end of file is reached. - * */ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t bytes, int64_t *pnum) { - BlockDriverState *intermediate; - int ret; - int64_t n =3D bytes; - - assert(base || !include_base); - - intermediate =3D top; - while (include_base || intermediate !=3D base) { - int64_t pnum_inter; - int64_t size_inter; - - assert(intermediate); - ret =3D bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter= ); - if (ret < 0) { - return ret; - } - if (ret) { - *pnum =3D pnum_inter; - return 1; - } - - size_inter =3D bdrv_getlength(intermediate); - if (size_inter < 0) { - return size_inter; - } - if (n > pnum_inter && - (intermediate =3D=3D top || offset + pnum_inter < size_inter))= { - n =3D pnum_inter; - } - - if (intermediate =3D=3D base) { - break; - } - - intermediate =3D backing_bs(intermediate); + int ret =3D bdrv_common_block_status_above(top, base, include_base, fa= lse, + offset, bytes, pnum, NULL, NU= LL); + if (ret < 0) { + return ret; } =20 - *pnum =3D n; - return 0; + return !!(ret & BDRV_BLOCK_ALLOCATED); } =20 typedef struct BdrvVmstateCo { --=20 2.21.0 From nobody Thu May 2 16:32:30 2024 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=1574267149; cv=none; d=zoho.com; s=zohoarc; b=f1BzxtTON0IBwgPlyD29yu3gTbmvL+z7tu3kPOQVt/aAldjLEHIqsdXVtpawkgeUWECaa8YkskEeviWywXHRV4GFa1nIbS6uwfirifOL8a+AUtmNfHJvbNEZxPQaX0ltp4peG6FOVVb6Go+oizG6A/o56y1Exhw2JBMFnFNf7dU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574267149; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eUPjvurFIs86uikST4258rcgMOx4P4iix7ykUvmoByg=; b=AccrY7UUnv3eNNTEya/HhVdyZtZjuSFBqochsgDClXXwUA63V9i+mHTTX5gk6cYxbo2IruC2tTWoESV/Nk3bL/rWrSeDN1BeeZLWnggkdZQuBDax++6XcePaLqegi1GG6P/eVseETRrBhm5C02V30a9FqZUyWVRDCYM4zeO1epE= 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 1574267149889296.2896310812615; Wed, 20 Nov 2019 08:25:49 -0800 (PST) Received: from localhost ([::1]:60232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iXSnc-0000pf-Qw for importer@patchew.org; Wed, 20 Nov 2019 11:25:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44320) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iXSmC-00073x-3i for qemu-devel@nongnu.org; Wed, 20 Nov 2019 11:24:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iXSmA-0003ZU-PX for qemu-devel@nongnu.org; Wed, 20 Nov 2019 11:24:20 -0500 Received: from relay.sw.ru ([185.231.240.75]:53030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iXSm7-0003XS-7E; Wed, 20 Nov 2019 11:24:15 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1iXSlu-0007ga-Ps; Wed, 20 Nov 2019 19:24:02 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 5/4] iotests: add commit top->base cases to 274 Date: Wed, 20 Nov 2019 19:24:02 +0300 Message-Id: <20191120162402.24707-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191116163410.12129-1-vsementsov@virtuozzo.com> References: <20191116163410.12129-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These cases are fixed by previous patches around block_status and is_allocated. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/274 | 20 ++++++++++++ tests/qemu-iotests/274.out | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/tests/qemu-iotests/274 b/tests/qemu-iotests/274 index f3b71e2859..492fc7b251 100755 --- a/tests/qemu-iotests/274 +++ b/tests/qemu-iotests/274 @@ -115,6 +115,26 @@ with iotests.FilePath('base') as base, \ iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, mid) iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= mid) =20 + iotests.log('=3D=3D=3D Testing qemu-img commit (top -> base) =3D=3D=3D= ') + + create_chain() + iotests.qemu_img_log('commit', '-b', base, top) + iotests.img_info_log(base) + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= base) + + iotests.log('=3D=3D=3D Testing QMP active commit (top -> base) =3D=3D= =3D') + + create_chain() + with create_vm() as vm: + vm.launch() + vm.qmp_log('block-commit', device=3D'top', base_node=3D'base', + job_id=3D'job0', auto_dismiss=3DFalse) + vm.run_job('job0', wait=3D5) + + iotests.img_info_log(mid) + iotests.qemu_io_log('-c', 'read -P 1 0 %d' % size_short, base) + iotests.qemu_io_log('-c', 'read -P 0 %d %d' % (size_short, size_diff),= base) =20 iotests.log('=3D=3D Resize tests =3D=3D') =20 diff --git a/tests/qemu-iotests/274.out b/tests/qemu-iotests/274.out index def0ac7d27..8f59a4a123 100644 --- a/tests/qemu-iotests/274.out +++ b/tests/qemu-iotests/274.out @@ -126,6 +126,69 @@ read 1048576/1048576 bytes at offset 0 read 1048576/1048576 bytes at offset 1048576 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 +=3D=3D=3D Testing qemu-img commit (top -> base) =3D=3D=3D +Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D2097152 cluster_size=3D= 65536 lazy_refcounts=3Doff refcount_bits=3D16 + +Formatting 'TEST_DIR/PID-mid', fmt=3Dqcow2 size=3D1048576 backing_file=3DT= EST_DIR/PID-base cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D= 16 + +Formatting 'TEST_DIR/PID-top', fmt=3Dqcow2 size=3D2097152 backing_file=3DT= EST_DIR/PID-mid cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 + +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Image committed. + +image: TEST_IMG +file format: IMGFMT +virtual size: 2 MiB (2097152 bytes) +cluster_size: 65536 +Format specific information: + compat: 1.1 + lazy refcounts: false + refcount bits: 16 + corrupt: false + +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Testing QMP active commit (top -> base) =3D=3D=3D +Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D2097152 cluster_size=3D= 65536 lazy_refcounts=3Doff refcount_bits=3D16 + +Formatting 'TEST_DIR/PID-mid', fmt=3Dqcow2 size=3D1048576 backing_file=3DT= EST_DIR/PID-base cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D= 16 + +Formatting 'TEST_DIR/PID-top', fmt=3Dqcow2 size=3D2097152 backing_file=3DT= EST_DIR/PID-mid cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 + +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +{"execute": "block-commit", "arguments": {"auto-dismiss": false, "base-nod= e": "base", "device": "top", "job-id": "job0"}} +{"return": {}} +{"execute": "job-complete", "arguments": {"id": "job0"}} +{"return": {}} +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0,= "type": "commit"}, "event": "BLOCK_JOB_READY", "timestamp": {"microseconds= ": "USECS", "seconds": "SECS"}} +{"data": {"device": "job0", "len": 1048576, "offset": 1048576, "speed": 0,= "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"microsec= onds": "USECS", "seconds": "SECS"}} +{"execute": "job-dismiss", "arguments": {"id": "job0"}} +{"return": {}} +image: TEST_IMG +file format: IMGFMT +virtual size: 1 MiB (1048576 bytes) +cluster_size: 65536 +backing file: TEST_DIR/PID-base +Format specific information: + compat: 1.1 + lazy refcounts: false + refcount bits: 16 + corrupt: false + +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + =3D=3D Resize tests =3D=3D Formatting 'TEST_DIR/PID-base', fmt=3Dqcow2 size=3D6442450944 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 --=20 2.21.0