From nobody Sun Apr 28 09:26:28 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557424620; cv=none; d=zoho.com; s=zohoarc; b=LjbAOgfb4nlYZmL3WPbJ7hxU2VBsZD09o1AyEoLlUJCZSBzq0bnD0ZdWwHfwvwyTej/eWnrYPW/VGgo0W2AGgpNH2seaNw11Y/G4lc1E1bEe9f83o0NqP/TiLu397cCpXGo2czPPqhdmaJKqjF23DJB3CZweBoeenluU8N3CAlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557424620; 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:ARC-Authentication-Results; bh=0vWGHX73OgdEl4GG/VsFx7Jtac1oZxZgkmdPj+JVPEI=; b=hsohOVX+tfSEojxAsHIkQ2nCd037zWrYnGpG7nBrIAES72qEEzZcGancVZrhmMTrppn7pP36ZZ8tVikJ0KLEY0/FBHNcAZ4fEOtVu2iDjPDmT9GaKLTZp5RrvF0yQMuIzxSNgSTUVFi9ue1yWgKgtj5KfoqdeTbHSUkC8l7vcvc= 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 1557424620129762.24438064424; Thu, 9 May 2019 10:57:00 -0700 (PDT) Received: from localhost ([127.0.0.1]:58861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnHq-0006Aw-5r for importer@patchew.org; Thu, 09 May 2019 13:56:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnDp-0002jY-Ma for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOnDo-0006CO-Kv for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39408) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hOnDm-0006Ac-C0; Thu, 09 May 2019 13:52:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFC2B80082; Thu, 9 May 2019 17:52:41 +0000 (UTC) Received: from localhost (ovpn-204-168.brq.redhat.com [10.40.204.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 475D160CC0; Thu, 9 May 2019 17:52:41 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 9 May 2019 19:52:35 +0200 Message-Id: <20190509175237.19363-2-mreitz@redhat.com> In-Reply-To: <20190509175237.19363-1-mreitz@redhat.com> References: <20190509175237.19363-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 09 May 2019 17:52:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/3] qemu-img: Allow rebase with no input base 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently, without -u, you cannot add a backing file to an image when it currently has none: $ qemu-img rebase -b base.qcow2 foo.qcow2 qemu-img: Could not open old backing file '': The 'file' block driver requires a file name It is really simple to allow this, though (effectively by setting old_backing_size to 0), so this patch does just that. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 61 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 71c92f142a..cfa44b4153 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3312,26 +3312,30 @@ static int img_rebase(int argc, char **argv) char backing_name[PATH_MAX]; QDict *options =3D NULL; =20 - if (bs->backing_format[0] !=3D '\0') { - options =3D qdict_new(); - qdict_put_str(options, "driver", bs->backing_format); - } - - if (force_share) { - if (!options) { + if (bs->backing) { + if (bs->backing_format[0] !=3D '\0') { options =3D qdict_new(); + qdict_put_str(options, "driver", bs->backing_format); } - qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); - } - bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name)); - blk_old_backing =3D blk_new_open(backing_name, NULL, - options, src_flags, &local_err); - if (!blk_old_backing) { - error_reportf_err(local_err, - "Could not open old backing file '%s': ", - backing_name); - ret =3D -1; - goto out; + + if (force_share) { + if (!options) { + options =3D qdict_new(); + } + qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); + } + bdrv_get_backing_filename(bs, backing_name, sizeof(backing_nam= e)); + blk_old_backing =3D blk_new_open(backing_name, NULL, + options, src_flags, &local_err); + if (!blk_old_backing) { + error_reportf_err(local_err, + "Could not open old backing file '%s': ", + backing_name); + ret =3D -1; + goto out; + } + } else { + blk_old_backing =3D NULL; } =20 if (out_baseimg[0]) { @@ -3384,7 +3388,7 @@ static int img_rebase(int argc, char **argv) */ if (!unsafe) { int64_t size; - int64_t old_backing_size; + int64_t old_backing_size =3D 0; int64_t new_backing_size =3D 0; uint64_t offset; int64_t n; @@ -3400,15 +3404,18 @@ static int img_rebase(int argc, char **argv) ret =3D -1; goto out; } - old_backing_size =3D blk_getlength(blk_old_backing); - if (old_backing_size < 0) { - char backing_name[PATH_MAX]; + if (blk_old_backing) { + old_backing_size =3D blk_getlength(blk_old_backing); + if (old_backing_size < 0) { + char backing_name[PATH_MAX]; =20 - bdrv_get_backing_filename(bs, backing_name, sizeof(backing_nam= e)); - error_report("Could not get size of '%s': %s", - backing_name, strerror(-old_backing_size)); - ret =3D -1; - goto out; + bdrv_get_backing_filename(bs, backing_name, + sizeof(backing_name)); + error_report("Could not get size of '%s': %s", + backing_name, strerror(-old_backing_size)); + ret =3D -1; + goto out; + } } if (blk_new_backing) { new_backing_size =3D blk_getlength(blk_new_backing); --=20 2.21.0 From nobody Sun Apr 28 09:26:28 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557424497; cv=none; d=zoho.com; s=zohoarc; b=dg/umvrpuS7STlzvO9bEzkJJ6c3z9xZx0pE+DjYQEfOnFpAlmEWDljWWkAh8fT+8AJvfDN1F1nqEZ6n2tOXMxEJAuThLIMN5WYbXmiV35JQgU7u9pXUoADOrG7Dyi8SE9/OT5K9jFH1rPeVSo0vXbZ0CU6/+9L7nTvgZd2iG1n8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557424497; 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:ARC-Authentication-Results; bh=yBKCC2eKUT5BDK/Xk2jAhMgCQ1kWot81DHMm6U7j1Pw=; b=VNB9820kBEXjYApSWPC4D2tTwGRLElEMd1OTt+E67hS3WRwX7ZIf7c32nbMSJVZNrkn6fTEcxdaTaW6t21EULURQaHpzC5ogTGMPlcPOKa5BeLipE1H4/gsKY6n5VELsyXyQ/EA59dtvIhwgRDMI73a6R6Ux1XVzfIQvZ2swY0g= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557424497570275.7843708974789; Thu, 9 May 2019 10:54:57 -0700 (PDT) Received: from localhost ([127.0.0.1]:58810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnFo-0003ri-JJ for importer@patchew.org; Thu, 09 May 2019 13:54:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnDs-0002kv-Sw for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOnDr-0006Dt-Rz for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hOnDo-0006CF-NC; Thu, 09 May 2019 13:52:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13433C05683E; Thu, 9 May 2019 17:52:44 +0000 (UTC) Received: from localhost (ovpn-204-168.brq.redhat.com [10.40.204.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A122A19C77; Thu, 9 May 2019 17:52:43 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 9 May 2019 19:52:36 +0200 Message-Id: <20190509175237.19363-3-mreitz@redhat.com> In-Reply-To: <20190509175237.19363-1-mreitz@redhat.com> References: <20190509175237.19363-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 09 May 2019 17:52:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/3] qemu-img: Use zero writes after source backing EOF 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Past the end of the source backing file, we memset() buf_old to zero, so it is clearly easy to use blk_pwrite_zeroes() instead of blk_pwrite() then. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index cfa44b4153..28fba1e7a7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3432,6 +3432,8 @@ static int img_rebase(int argc, char **argv) } =20 for (offset =3D 0; offset < size; offset +=3D n) { + bool buf_old_is_zero =3D false; + /* How many bytes can we handle with the next read? */ n =3D MIN(IO_BUF_SIZE, size - offset); =20 @@ -3452,6 +3454,7 @@ static int img_rebase(int argc, char **argv) */ if (offset >=3D old_backing_size) { memset(buf_old, 0, n); + buf_old_is_zero =3D true; } else { if (offset + n > old_backing_size) { n =3D old_backing_size - offset; @@ -3487,8 +3490,12 @@ static int img_rebase(int argc, char **argv) if (compare_buffers(buf_old + written, buf_new + written, n - written, &pnum)) { - ret =3D blk_pwrite(blk, offset + written, - buf_old + written, pnum, 0); + if (buf_old_is_zero) { + ret =3D blk_pwrite_zeroes(blk, offset + written, p= num, 0); + } else { + ret =3D blk_pwrite(blk, offset + written, + buf_old + written, pnum, 0); + } if (ret < 0) { error_report("Error while writing to COW image: %s= ", strerror(-ret)); --=20 2.21.0 From nobody Sun Apr 28 09:26:28 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557424491; cv=none; d=zoho.com; s=zohoarc; b=lMMKs4zNu+PMHLGmsc9wyevSxFTMYfnS6zbQftm7P2TLnq1UPs05NfyMAZ6YCb3wNVK/x/XC2L9V64tHS9ctImsjTHl6ciAUS/j0nDkhOwbu8ea4Z//mbsAJpYxl7tmNTxYUNknF9C8rCXkurdlKRzTnieMt5CIQxf4duC96zB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557424491; 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:ARC-Authentication-Results; bh=BgFGaPDNJUueaFqS20SGAHWFmFIaDAaubCS3GlOvN48=; b=SEx1fPEzVvL3VI66g8AhyrOjwWKpt5be3xkTDT0oYNjDdKKjhxKVukW9/+3pBivPxnVsnlk2zMPCayvQLp8WsOKywkw36uo8mLeccHHZz/6/3wLq0lg4lRyouL5lNAvazotDes6S9yNubtDFN/GumFhW9d0Zq90PHwoe7rsxLcY= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557424491217854.6175116611299; Thu, 9 May 2019 10:54:51 -0700 (PDT) Received: from localhost ([127.0.0.1]:58808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnFl-0003qa-1y for importer@patchew.org; Thu, 09 May 2019 13:54:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOnDx-0002pS-IM for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOnDw-0006GF-3G for qemu-devel@nongnu.org; Thu, 09 May 2019 13:52:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44112) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hOnDs-0006Dy-MU; Thu, 09 May 2019 13:52:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06CAAC066455; Thu, 9 May 2019 17:52:48 +0000 (UTC) Received: from localhost (ovpn-204-168.brq.redhat.com [10.40.204.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05A3960CC0; Thu, 9 May 2019 17:52:45 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 9 May 2019 19:52:37 +0200 Message-Id: <20190509175237.19363-4-mreitz@redhat.com> In-Reply-To: <20190509175237.19363-1-mreitz@redhat.com> References: <20190509175237.19363-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 09 May 2019 17:52:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/3] iotests: Add test for rebase without input base 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This patch adds a test for rebasing an image that currently does not have a backing file. Signed-off-by: Max Reitz --- tests/qemu-iotests/252 | 124 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/252.out | 39 ++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 164 insertions(+) create mode 100755 tests/qemu-iotests/252 create mode 100644 tests/qemu-iotests/252.out diff --git a/tests/qemu-iotests/252 b/tests/qemu-iotests/252 new file mode 100755 index 0000000000..f6c8f71444 --- /dev/null +++ b/tests/qemu-iotests/252 @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +# +# Tests for rebasing COW images that require zero cluster support +# +# Copyright (C) 2019 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dmreitz@redhat.com + +seq=3D$(basename $0) +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.base_new" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +# Currently only qcow2 and qed support rebasing, and only qcow2 v3 has +# zero cluster support +_supported_fmt qcow2 +_unsupported_imgopts 'compat=3D0.10' +_supported_proto file +_supported_os Linux + +CLUSTER_SIZE=3D65536 + +echo +echo "=3D=3D=3D Test rebase without input base =3D=3D=3D" +echo + +# Cluster allocations to be tested: +# +# Backing (new) 11 -- 11 -- 11 -- +# COW image 22 22 11 11 -- -- +# +# Expected result: +# +# COW image 22 22 11 11 00 -- +# +# (Cluster 2 might be "--" after the rebase, too, but rebase just +# compares the new backing file to the old one and disregards the +# overlay. Therefore, it will never discard overlay clusters.) + +_make_test_img $((6 * CLUSTER_SIZE)) +TEST_IMG=3D"$TEST_IMG.base_new" _make_test_img $((6 * CLUSTER_SIZE)) + +echo + +$QEMU_IO "$TEST_IMG" \ + -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + | _filter_qemu_io + +$QEMU_IO "$TEST_IMG.base_new" \ + -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + | _filter_qemu_io + +echo + +# This should be a no-op +$QEMU_IMG rebase -b "" "$TEST_IMG" + +# Verify the data is correct +$QEMU_IO "$TEST_IMG" \ + -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + | _filter_qemu_io + +echo + +# Verify the allocation status (first four cluster should be allocated +# in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero +# clusters here because there is no backing file)) +$QEMU_IMG map --output=3Djson "$TEST_IMG" | _filter_qemu_img_map + +echo + +$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG" + +# Verify the data is correct +$QEMU_IO "$TEST_IMG" \ + -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + | _filter_qemu_io + +echo + +# Verify the allocation status (first four cluster should be allocated +# in TEST_IMG, cluster 4 should be zero, and cluster 5 should be +# unallocated (signified by '"depth": 1')) +$QEMU_IMG map --output=3Djson "$TEST_IMG" | _filter_qemu_img_map + + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/252.out b/tests/qemu-iotests/252.out new file mode 100644 index 0000000000..12dce889f8 --- /dev/null +++ b/tests/qemu-iotests/252.out @@ -0,0 +1,39 @@ +QA output created by 252 + +=3D=3D=3D Test rebase without input base =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D393216 +Formatting 'TEST_DIR/t.IMGFMT.base_new', fmt=3DIMGFMT size=3D393216 + +wrote 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 131072/131072 bytes at offset 131072 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 131072 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 262144 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +read 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 131072/131072 bytes at offset 131072 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 131072/131072 bytes at offset 262144 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +[{ "start": 0, "length": 262144, "depth": 0, "zero": false, "data": true, = "offset": OFFSET}, +{ "start": 262144, "length": 131072, "depth": 0, "zero": true, "data": fal= se}] + +read 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 131072/131072 bytes at offset 131072 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 131072/131072 bytes at offset 262144 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +[{ "start": 0, "length": 262144, "depth": 0, "zero": false, "data": true, = "offset": OFFSET}, +{ "start": 262144, "length": 65536, "depth": 0, "zero": true, "data": fals= e}, +{ "start": 327680, "length": 65536, "depth": 1, "zero": true, "data": fals= e}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 7ac9a5ea4a..00e474ab0a 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -249,3 +249,4 @@ 247 rw auto quick 248 rw auto quick 249 rw auto quick +252 rw auto backing quick --=20 2.21.0