[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/10] block/qcow2: implement blockdev-amend
From: |
Maxim Levitsky |
Subject: |
[Qemu-devel] [PATCH 09/10] block/qcow2: implement blockdev-amend |
Date: |
Fri, 30 Aug 2019 23:56:07 +0300 |
Currently only for changing crypto parameters
Signed-off-by: Maxim Levitsky <address@hidden>
---
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_options,
Error **errp)
assert(create_options->driver == BLOCKDEV_DRIVER_QCOW2);
qcow2_opts = &create_options->u.qcow2;
+ 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 = bdrv_open_blockdev_ref(qcow2_opts->file, errp);
if (bs == NULL) {
return -EIO;
@@ -5112,6 +5124,64 @@ static int qcow2_amend_options(BlockDriverState *bs,
QemuOpts *opts,
return 0;
}
+
+static int coroutine_fn qcow2_co_amend(BlockDriverState *bs,
+ BlockdevCreateOptions *opts,
+ bool force,
+ Error **errp)
+{
+ BlockdevCreateOptionsQcow2 *qopts = &opts->u.qcow2;
+ BDRVQcow2State *s = 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 with
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 != 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);
+ 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 = {
.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 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',
--
2.17.2
- [Qemu-devel] [PATCH 00/10] RFC crypto/luks: encryption key managment using amend interface, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 01/10] qcrypto: add suport for amend options, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 03/10] qcrypto-luks: implement the encryption key management, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 04/10] block: amend: add 'force' option, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 05/10] block/crypto: implement the encryption key management, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 02/10] qcrypto-luks: extend the create options for upcoming encryption key management, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 06/10] qcow2: implement crypto amend options, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 08/10] block/crypto: implement blockdev-amend, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 09/10] block/qcow2: implement blockdev-amend,
Maxim Levitsky <=
- [Qemu-devel] [PATCH 07/10] block: add x-blockdev-amend qmp command, Maxim Levitsky, 2019/08/30
- [Qemu-devel] [PATCH 10/10] iotests : add tests for encryption key management, Maxim Levitsky, 2019/08/30