From nobody Wed Nov 12 02:09:40 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 ARC-Seal: i=1; a=rsa-sha256; t=1568328155; cv=none; d=zoho.com; s=zohoarc; b=K8KV72A0vpINrlaGDH5Ip/Ca9UFFc6jNmMsaQndmEh9q86oTkJFM1f7Hx+xvQE1BJxsya5WJXUFGI+/tXMhky3ovOpOI8n/m5f17kqwjL/eVWsT5Nm8EY0j6RRNS/lQtZNCN2E/Vp6UVDIFv0EUfAq5m0xrQT9vpZvlSGZBpduA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568328155; 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=8j8wQKjjqY8jpfXjwzvBdTujq0oxmCzs1NvXtHRkVpc=; b=eA+karf5YXTo8F2a7ZPQuLobVauHcsr3T9yELyhhDWanaqp8l2cGCI5g7OLJKz3A/zuP8CvG7X9j75VjGmohv6NLAj2aWC7Ae0pOuNTUSf7NJ8KIzyPSD7yabqe8Dp9R3wRr6gZCFGXQaCZN6+AfcrOhVcK1JhZuCR7ofn4JllE= 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 1568328155235508.10533969744677; Thu, 12 Sep 2019 15:42:35 -0700 (PDT) Received: from localhost ([::1]:39326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8XnN-0003xJ-Vz for importer@patchew.org; Thu, 12 Sep 2019 18:42:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42073) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8XcW-0008Aw-6I for qemu-devel@nongnu.org; Thu, 12 Sep 2019 18:31:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8XcU-00060f-RH for qemu-devel@nongnu.org; Thu, 12 Sep 2019 18:31:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8XcS-0005y8-6l; Thu, 12 Sep 2019 18:31:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86EECC065121; Thu, 12 Sep 2019 22:31:15 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 492C65C1B2; Thu, 12 Sep 2019 22:31:13 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 01:30:26 +0300 Message-Id: <20190912223028.18496-10-mlevitsk@redhat.com> In-Reply-To: <20190912223028.18496-1-mlevitsk@redhat.com> References: <20190912223028.18496-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 12 Sep 2019 22:31:15 +0000 (UTC) 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 v2 09/11] block/qcow2: implement blockdev-amend 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Maxim Levitsky , John Snow 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" Currently only for changing crypto parameters Signed-off-by: Maxim Levitsky --- block/qcow2.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 6 ++-- 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 26f83aeb44..c8847ec6e2 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3079,6 +3079,18 @@ qcow2_co_create(BlockdevCreateOptions *create_option= s, Error **errp) assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_QCOW2); qcow2_opts =3D &create_options->u.qcow2; =20 + if (!qcow2_opts->has_size) { + error_setg(errp, "Size is manadatory for image creation"); + return -EINVAL; + + } + + if (!qcow2_opts->has_file) { + error_setg(errp, "'file' is manadatory for image creation"); + return -EINVAL; + + } + bs =3D bdrv_open_blockdev_ref(qcow2_opts->file, errp); if (bs =3D=3D NULL) { return -EIO; @@ -5111,6 +5123,64 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, return 0; } =20 + +static int coroutine_fn qcow2_co_amend(BlockDriverState *bs, + BlockdevCreateOptions *opts, + bool force, + Error **errp) +{ + BlockdevCreateOptionsQcow2 *qopts =3D &opts->u.qcow2; + BDRVQcow2State *s =3D bs->opaque; + int ret; + + /* + * This is ugly as hell, in later versions of this patch + * something has to be done about this + */ + if (qopts->has_file || qopts->has_size || qopts->has_data_file || + qopts->has_data_file_raw || qopts->has_version || + qopts->has_backing_file || qopts->has_backing_fmt || + qopts->has_cluster_size || qopts->has_preallocation || + qopts->has_lazy_refcounts || qopts->has_refcount_bits) { + + error_setg(errp, + "Only LUKS encryption options can be amended for qcow2 wit= h blockdev-amend"); + return -EOPNOTSUPP; + + } + + if (qopts->has_encrypt) { + if (!s->crypto) { + error_setg(errp, "QCOW2 image is not encrypted, can't amend"); + return -EOPNOTSUPP; + } + + if (qopts->encrypt->format !=3D Q_CRYPTO_BLOCK_FORMAT_LUKS) { + error_setg(errp, + "Amend can't be used to change the qcow2 encryption= format"); + return -EOPNOTSUPP; + } + + if (s->crypt_method_header !=3D QCOW_CRYPT_LUKS) { + error_setg(errp, + "Only LUKS encryption options can be amended for qc= ow2 with blockdev-amend"); + return -EOPNOTSUPP; + } + + ret =3D qcrypto_block_amend_options(s->crypto, + qcow2_crypto_hdr_read_func, + qcow2_crypto_hdr_write_func, + bs, + qopts->encrypt, + force, + errp); + if (ret) { + return ret; + } + } + return 0; +} + /* * If offset or size are negative, respectively, they will not be included= in * the BLOCK_IMAGE_CORRUPTED event emitted. @@ -5303,6 +5373,7 @@ BlockDriver bdrv_qcow2 =3D { .mutable_opts =3D mutable_opts, .bdrv_co_check =3D qcow2_co_check, .bdrv_amend_options =3D qcow2_amend_options, + .bdrv_co_amend =3D qcow2_co_amend, =20 .bdrv_detach_aio_context =3D qcow2_detach_aio_context, .bdrv_attach_aio_context =3D qcow2_attach_aio_context, diff --git a/qapi/block-core.json b/qapi/block-core.json index 4a6db98938..0eb4e45168 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4294,6 +4294,7 @@ # Driver specific image creation options for qcow2. # # @file Node to create the image format on +# Mandatory for create # @data-file Node to use as an external data file in which all guest # data is stored so that only metadata remains in the qc= ow2 # file (since: 4.0) @@ -4301,6 +4302,7 @@ # standalone (read-only) raw image without looking at qc= ow2 # metadata (default: false; since: 4.0) # @size Size of the virtual disk in bytes +# Mandatory for create # @version Compatibility level (default: v3) # @backing-file File name of the backing file if a backing file # should be used @@ -4315,10 +4317,10 @@ # Since: 2.12 ## { 'struct': 'BlockdevCreateOptionsQcow2', - 'data': { 'file': 'BlockdevRef', + 'data': { '*file': 'BlockdevRef', '*data-file': 'BlockdevRef', '*data-file-raw': 'bool', - 'size': 'size', + '*size': 'size', '*version': 'BlockdevQcow2Version', '*backing-file': 'str', '*backing-fmt': 'BlockdevDriver', --=20 2.17.2