[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 12/13] block/qcow2: implement blockdev-amend
From: |
Maxim Levitsky |
Subject: |
[PATCH 12/13] block/qcow2: implement blockdev-amend |
Date: |
Tue, 14 Jan 2020 21:33:49 +0200 |
Currently the implementation only supports amending the encryption
options, unlike the qemu-img version
Signed-off-by: Maxim Levitsky <address@hidden>
---
block/qcow2.c | 39 +++++++++++++++++++++++++++++++++++++++
qapi/block-core.json | 16 +++++++++++++++-
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 1b01174aed..8b74471bc6 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -5444,6 +5444,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.
@@ -5656,6 +5694,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,
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 790aa40991..2cf1f443e5 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4755,6 +4755,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.0
+##
+{ 'struct': 'BlockdevAmendOptionsQcow2',
+ 'data': { '*encrypt': 'QCryptoBlockAmendOptions' } }
+
##
# @BlockdevAmendOptions:
#
@@ -4769,7 +4782,8 @@
'driver': 'BlockdevDriver' },
'discriminator': 'driver',
'data': {
- 'luks': 'BlockdevAmendOptionsLUKS' } }
+ 'luks': 'BlockdevAmendOptionsLUKS',
+ 'qcow2': 'BlockdevAmendOptionsQcow2' } }
##
# @x-blockdev-amend:
--
2.17.2
- [PATCH 07/13] qcow2: extend qemu-img amend interface with crypto options, (continued)
- [PATCH 07/13] qcow2: extend qemu-img amend interface with crypto options, Maxim Levitsky, 2020/01/14
- [PATCH 09/13] qemu-iotests: qemu-img tests for luks key management, Maxim Levitsky, 2020/01/14
- [PATCH 08/13] iotests: filter few more luks specific create options, Maxim Levitsky, 2020/01/14
- [PATCH 10/13] block: add generic infrastructure for x-blockdev-amend qmp command, Maxim Levitsky, 2020/01/14
- [PATCH 12/13] block/qcow2: implement blockdev-amend,
Maxim Levitsky <=
- [PATCH 13/13] iotests: add tests for blockdev-amend, Maxim Levitsky, 2020/01/14
- [PATCH 11/13] block/crypto: implement blockdev-amend, Maxim Levitsky, 2020/01/14
- Re: [PATCH 00/13] LUKS: encryption slot management using amend interface, no-reply, 2020/01/14
- Re: [PATCH 00/13] LUKS: encryption slot management using amend interface, no-reply, 2020/01/14