[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/31] block/qcow2: implement blockdev-amend
From: |
Max Reitz |
Subject: |
[PULL 20/31] block/qcow2: implement blockdev-amend |
Date: |
Mon, 6 Jul 2020 12:04:21 +0200 |
From: Maxim Levitsky <mlevitsk@redhat.com>
Currently the implementation only supports amending the encryption
options, unlike the qemu-img version
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200608094030.670121-14-mlevitsk@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
qapi/block-core.json | 16 +++++++++++++++-
block/qcow2.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index cd679ad435..b20332e592 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4686,6 +4686,19 @@
'data': { }
}
+##
+# @BlockdevAmendOptionsQcow2:
+#
+# Driver specific image amend options for qcow2.
+# For now, only encryption options can be amended
+#
+# @encrypt Encryption options to be amended
+#
+# Since: 5.1
+##
+{ 'struct': 'BlockdevAmendOptionsQcow2',
+ 'data': { '*encrypt': 'QCryptoBlockAmendOptions' } }
+
##
# @BlockdevAmendOptions:
#
@@ -4700,7 +4713,8 @@
'driver': 'BlockdevDriver' },
'discriminator': 'driver',
'data': {
- 'luks': 'BlockdevAmendOptionsLUKS' } }
+ 'luks': 'BlockdevAmendOptionsLUKS',
+ 'qcow2': 'BlockdevAmendOptionsQcow2' } }
##
# @x-blockdev-amend:
diff --git a/block/qcow2.c b/block/qcow2.c
index 750e9c4842..30f073cf2a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -5596,6 +5596,44 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
return 0;
}
+static int coroutine_fn qcow2_co_amend(BlockDriverState *bs,
+ BlockdevAmendOptions *opts,
+ bool force,
+ Error **errp)
+{
+ BlockdevAmendOptionsQcow2 *qopts = &opts->u.qcow2;
+ BDRVQcow2State *s = bs->opaque;
+ int ret = 0;
+
+ if (qopts->has_encrypt) {
+ if (!s->crypto) {
+ error_setg(errp, "image is not encrypted, can't amend");
+ return -EOPNOTSUPP;
+ }
+
+ if (qopts->encrypt->format != 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 != QCOW_CRYPT_LUKS) {
+ error_setg(errp,
+ "Only LUKS encryption options can be amended for qcow2
with blockdev-amend");
+ return -EOPNOTSUPP;
+ }
+
+ ret = qcrypto_block_amend_options(s->crypto,
+ qcow2_crypto_hdr_read_func,
+ qcow2_crypto_hdr_write_func,
+ bs,
+ qopts->encrypt,
+ force,
+ errp);
+ }
+ return ret;
+}
+
/*
* If offset or size are negative, respectively, they will not be included in
* the BLOCK_IMAGE_CORRUPTED event emitted.
@@ -5813,6 +5851,7 @@ BlockDriver bdrv_qcow2 = {
.mutable_opts = mutable_opts,
.bdrv_co_check = qcow2_co_check,
.bdrv_amend_options = qcow2_amend_options,
+ .bdrv_co_amend = qcow2_co_amend,
.bdrv_detach_aio_context = qcow2_detach_aio_context,
.bdrv_attach_aio_context = qcow2_attach_aio_context,
--
2.26.2
- [PULL 12/31] block/amend: separate amend and create options for qemu-img, (continued)
- [PULL 12/31] block/amend: separate amend and create options for qemu-img, Max Reitz, 2020/07/06
- [PULL 14/31] block/crypto: rename two functions, Max Reitz, 2020/07/06
- [PULL 13/31] block/amend: refactor qcow2 amend options, Max Reitz, 2020/07/06
- [PULL 15/31] block/crypto: implement the encryption key management, Max Reitz, 2020/07/06
- [PULL 16/31] block/qcow2: extend qemu-img amend interface with crypto options, Max Reitz, 2020/07/06
- [PULL 17/31] iotests: qemu-img tests for luks key management, Max Reitz, 2020/07/06
- [PULL 19/31] block/crypto: implement blockdev-amend, Max Reitz, 2020/07/06
- [PULL 18/31] block/core: add generic infrastructure for x-blockdev-amend qmp command, Max Reitz, 2020/07/06
- [PULL 20/31] block/qcow2: implement blockdev-amend,
Max Reitz <=
- [PULL 22/31] qemu-img: convert: don't use unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 23/31] block: inline bdrv_unallocated_blocks_are_zero(), Max Reitz, 2020/07/06
- [PULL 21/31] iotests: add tests for blockdev-amend, Max Reitz, 2020/07/06
- [PULL 24/31] block/vdi: return ZERO block-status when appropriate, Max Reitz, 2020/07/06
- [PULL 26/31] block/crypto: drop unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 27/31] block/iscsi: drop unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 28/31] block/file-posix: drop unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 29/31] block/vhdx: drop unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 30/31] block: drop unallocated_blocks_are_zero, Max Reitz, 2020/07/06
- [PULL 25/31] block/vpc: return ZERO block-status when appropriate, Max Reitz, 2020/07/06