From nobody Tue Apr 15 11:38:42 2025 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552050901037675.5646138209244; Fri, 8 Mar 2019 05:15:01 -0800 (PST) Received: from localhost ([127.0.0.1]:42856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2FKu-0004A5-TT for importer@patchew.org; Fri, 08 Mar 2019 08:14:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2F5x-0000C1-3s for qemu-devel@nongnu.org; Fri, 08 Mar 2019 07:59:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2F5v-0008KG-1G for qemu-devel@nongnu.org; Fri, 08 Mar 2019 07:59:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2F5p-0007fP-4u; Fri, 08 Mar 2019 07:59:17 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6379D307D8E3; Fri, 8 Mar 2019 12:59:15 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 520175D787; Fri, 8 Mar 2019 12:59:14 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 8 Mar 2019 13:58:14 +0100 Message-Id: <20190308125823.32535-25-kwolf@redhat.com> In-Reply-To: <20190308125823.32535-1-kwolf@redhat.com> References: <20190308125823.32535-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 08 Mar 2019 12:59:15 +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] [PULL 24/33] qcow2: Add basic data-file infrastructure 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This adds a .bdrv_open option to specify the external data file node. Signed-off-by: Kevin Wolf --- qapi/block-core.json | 7 ++++++- block/qcow2.h | 4 +++- block/qcow2.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 2b8afbb924..de4d4fd0e4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3080,6 +3080,10 @@ # encrypted images, except when doing a metadata-o= nly # probe of the image. (since 2.10) # +# @data-file: reference to or definition of the external data = file. +# This may only be specified for images that requi= re an +# external data file. (since 4.0) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsQcow2', @@ -3094,7 +3098,8 @@ '*l2-cache-entry-size': 'int', '*refcount-cache-size': 'int', '*cache-clean-interval': 'int', - '*encrypt': 'BlockdevQcow2Encryption' } } + '*encrypt': 'BlockdevQcow2Encryption', + '*data-file': 'BlockdevRef' } } =20 ## # @SshHostKeyCheckMode: diff --git a/block/qcow2.h b/block/qcow2.h index aac7fc4348..f23c003a46 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -91,6 +91,7 @@ =20 #define DEFAULT_CLUSTER_SIZE 65536 =20 +#define QCOW2_OPT_DATA_FILE "data-file" #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts" #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request" #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot" @@ -205,7 +206,8 @@ enum { QCOW2_INCOMPAT_DATA_FILE =3D 1 << QCOW2_INCOMPAT_DATA_FILE_BITN= R, =20 QCOW2_INCOMPAT_MASK =3D QCOW2_INCOMPAT_DIRTY - | QCOW2_INCOMPAT_CORRUPT, + | QCOW2_INCOMPAT_CORRUPT + | QCOW2_INCOMPAT_DATA_FILE, }; =20 /* Compatible feature bits */ diff --git a/block/qcow2.c b/block/qcow2.c index f048763e10..ddbf8731bd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1453,8 +1453,31 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, goto fail; } =20 - /* TODO Open external data file */ - s->data_file =3D bs->file; + /* Open external data file */ + s->data_file =3D bdrv_open_child(NULL, options, "data-file", bs, &chil= d_file, + true, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fail; + } + + if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) { + if (!s->data_file) { + error_setg(errp, "'data-file' is required for this image"); + ret =3D -EINVAL; + goto fail; + } + } else { + if (s->data_file) { + error_setg(errp, "'data-file' can only be set for images with = an " + "external data file"); + ret =3D -EINVAL; + goto fail; + } else { + s->data_file =3D bs->file; + } + } =20 /* qcow2_read_extension may have set up the crypto context * if the crypt method needs a header region, some methods @@ -1627,6 +1650,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, return ret; =20 fail: + if (has_data_file(bs)) { + bdrv_unref_child(bs, s->data_file); + } g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); qcow2_free_snapshots(bs); @@ -2246,6 +2272,10 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); =20 + if (has_data_file(bs)) { + bdrv_unref_child(bs, s->data_file); + } + qcow2_refcount_close(bs); qcow2_free_snapshots(bs); } --=20 2.20.1