qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

block/qcow2: implement blockdev-amend

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>

authored by

Maxim Levitsky and committed by
Max Reitz
8ea1613d 30da9dd8

+54 -1
+39
block/qcow2.c
··· 5596 5596 return 0; 5597 5597 } 5598 5598 5599 + static int coroutine_fn qcow2_co_amend(BlockDriverState *bs, 5600 + BlockdevAmendOptions *opts, 5601 + bool force, 5602 + Error **errp) 5603 + { 5604 + BlockdevAmendOptionsQcow2 *qopts = &opts->u.qcow2; 5605 + BDRVQcow2State *s = bs->opaque; 5606 + int ret = 0; 5607 + 5608 + if (qopts->has_encrypt) { 5609 + if (!s->crypto) { 5610 + error_setg(errp, "image is not encrypted, can't amend"); 5611 + return -EOPNOTSUPP; 5612 + } 5613 + 5614 + if (qopts->encrypt->format != Q_CRYPTO_BLOCK_FORMAT_LUKS) { 5615 + error_setg(errp, 5616 + "Amend can't be used to change the qcow2 encryption format"); 5617 + return -EOPNOTSUPP; 5618 + } 5619 + 5620 + if (s->crypt_method_header != QCOW_CRYPT_LUKS) { 5621 + error_setg(errp, 5622 + "Only LUKS encryption options can be amended for qcow2 with blockdev-amend"); 5623 + return -EOPNOTSUPP; 5624 + } 5625 + 5626 + ret = qcrypto_block_amend_options(s->crypto, 5627 + qcow2_crypto_hdr_read_func, 5628 + qcow2_crypto_hdr_write_func, 5629 + bs, 5630 + qopts->encrypt, 5631 + force, 5632 + errp); 5633 + } 5634 + return ret; 5635 + } 5636 + 5599 5637 /* 5600 5638 * If offset or size are negative, respectively, they will not be included in 5601 5639 * the BLOCK_IMAGE_CORRUPTED event emitted. ··· 5813 5851 .mutable_opts = mutable_opts, 5814 5852 .bdrv_co_check = qcow2_co_check, 5815 5853 .bdrv_amend_options = qcow2_amend_options, 5854 + .bdrv_co_amend = qcow2_co_amend, 5816 5855 5817 5856 .bdrv_detach_aio_context = qcow2_detach_aio_context, 5818 5857 .bdrv_attach_aio_context = qcow2_attach_aio_context,
+15 -1
qapi/block-core.json
··· 4687 4687 } 4688 4688 4689 4689 ## 4690 + # @BlockdevAmendOptionsQcow2: 4691 + # 4692 + # Driver specific image amend options for qcow2. 4693 + # For now, only encryption options can be amended 4694 + # 4695 + # @encrypt Encryption options to be amended 4696 + # 4697 + # Since: 5.1 4698 + ## 4699 + { 'struct': 'BlockdevAmendOptionsQcow2', 4700 + 'data': { '*encrypt': 'QCryptoBlockAmendOptions' } } 4701 + 4702 + ## 4690 4703 # @BlockdevAmendOptions: 4691 4704 # 4692 4705 # Options for amending an image format ··· 4700 4713 'driver': 'BlockdevDriver' }, 4701 4714 'discriminator': 'driver', 4702 4715 'data': { 4703 - 'luks': 'BlockdevAmendOptionsLUKS' } } 4716 + 'luks': 'BlockdevAmendOptionsLUKS', 4717 + 'qcow2': 'BlockdevAmendOptionsQcow2' } } 4704 4718 4705 4719 ## 4706 4720 # @x-blockdev-amend: