From nobody Wed Nov 12 01:53:56 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=1567199344; cv=none; d=zoho.com; s=zohoarc; b=T6XUPag0rPV/JvlLxaYP40/ojO4ppDel62fgN8SkMzNY9mNrueYyKHxzf9SPdIH37mxFin2DPBZQ9qWE/x41+uHLY1rkNNopEYAnGOxh7lUfl7pCXd6W8jixA0SMcJo1HkGLgx2Gv/5nsHvdTZiEP54Cluo1K1Bkzxt2B2djhRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567199344; 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=LcG8wT49NXp7cYLmilGySxxV9xa7jJoYMtP0W579EqA=; b=RHTZBhhNolKyEqXMpPJ/uvOu3pkxK/XzOyUUCl6pVuRCR3leFjV51TkooiG7YuPHv3dcjNyoDpEZ2ew9D5RUT7uM6QhN4D9hZ6XABiKgewlyE7Wn63IJUVxUWNG52OS3UTUdaemogamh4nMv5FyB7CZ4mM3IqDdltH0DGEnGgYg= 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 1567199344671632.0717544070819; Fri, 30 Aug 2019 14:09:04 -0700 (PDT) Received: from localhost ([::1]:41170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3o8l-0004rD-4u for importer@patchew.org; Fri, 30 Aug 2019 17:09:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47702) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3nwz-0003RW-Bz for qemu-devel@nongnu.org; Fri, 30 Aug 2019 16:56:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3nww-0001fR-AG for qemu-devel@nongnu.org; Fri, 30 Aug 2019 16:56:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i3nwt-0001bp-MJ; Fri, 30 Aug 2019 16:56:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 029CD317528A; Fri, 30 Aug 2019 20:56:47 +0000 (UTC) Received: from maximlenovopc.usersys.redhat.com (unknown [10.35.206.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAEA55D9CA; Fri, 30 Aug 2019 20:56:44 +0000 (UTC) From: Maxim Levitsky To: qemu-devel@nongnu.org Date: Fri, 30 Aug 2019 23:56:07 +0300 Message-Id: <20190830205608.18192-10-mlevitsk@redhat.com> In-Reply-To: <20190830205608.18192-1-mlevitsk@redhat.com> References: <20190830205608.18192-1-mlevitsk@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 30 Aug 2019 20:56:47 +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 09/10] 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 | 4 +-- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 8dff4c6b5f..327d2afd9f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3082,6 +3082,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; @@ -5112,6 +5124,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. @@ -5304,6 +5374,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 02375fb59a..ba41744427 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4312,10 +4312,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