From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@gmail.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/4] block: convert crypto driver to bdrv_co_preadv|pwritev
Date: Thu, 31 Aug 2017 10:08:00 -0500 [thread overview]
Message-ID: <3867f025-5d0b-5bed-d47f-a91c706cd3aa@redhat.com> (raw)
In-Reply-To: <20170831110518.10741-4-berrange@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4070 bytes --]
On 08/31/2017 06:05 AM, Daniel P. Berrange wrote:
> Make the crypto driver implement the bdrv_co_preadv|pwritev
> callbacks, and also use bdrv_co_preadv|pwritev for I/O
> with the protocol driver beneath.
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
> block/crypto.c | 103 +++++++++++++++++++++++++++++----------------------------
> 1 file changed, 53 insertions(+), 50 deletions(-)
>
> static coroutine_fn int
> -block_crypto_co_readv(BlockDriverState *bs, int64_t sector_num,
> - int remaining_sectors, QEMUIOVector *qiov)
> +block_crypto_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
> + QEMUIOVector *qiov, int flags)
> {
> BlockCrypto *crypto = bs->opaque;
> - int cur_nr_sectors; /* number of sectors in current iteration */
> + uint64_t cur_bytes; /* number of bytes in current iteration */
> uint64_t bytes_done = 0;
> uint8_t *cipher_data = NULL;
> QEMUIOVector hd_qiov;
> int ret = 0;
> - size_t payload_offset =
> - qcrypto_block_get_payload_offset(crypto->block) / BDRV_SECTOR_SIZE;
> + size_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
Pre-existing: is size_t the right type, or can we overflow a 64-bit
offset on a 32-bit host?
> + uint64_t sector_num = offset / BDRV_SECTOR_SIZE;
> +
> + assert((offset % BDRV_SECTOR_SIZE) == 0);
> + assert((bytes % BDRV_SECTOR_SIZE) == 0);
The osdep.h macros might be nicer than open-coding; furthermore, if
desired, you could shorten to:
assert(QEMU_IS_ALIGNED(offset | bytes, BDRV_SECTOR_SIZE));
>
> static coroutine_fn int
> -block_crypto_co_writev(BlockDriverState *bs, int64_t sector_num,
> - int remaining_sectors, QEMUIOVector *qiov)
> +block_crypto_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
> + QEMUIOVector *qiov, int flags)
> {
Hmm - you don't set supported_write_flags. But presumably, if the
underlying BDS supports BDRV_REQUEST_FUA, then crypto can likewise
support that flag by passing it through to the underlying device after
encryption.
> BlockCrypto *crypto = bs->opaque;
> - int cur_nr_sectors; /* number of sectors in current iteration */
> + uint64_t cur_bytes; /* number of bytes in current iteration */
> uint64_t bytes_done = 0;
> uint8_t *cipher_data = NULL;
> QEMUIOVector hd_qiov;
> int ret = 0;
> - size_t payload_offset =
> - qcrypto_block_get_payload_offset(crypto->block) / BDRV_SECTOR_SIZE;
> + size_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
> + uint64_t sector_num = offset / BDRV_SECTOR_SIZE;
> +
> + assert((offset % BDRV_SECTOR_SIZE) == 0);
> + assert((bytes % BDRV_SECTOR_SIZE) == 0);
Same comment as for read.
> @@ -611,8 +613,9 @@ BlockDriver bdrv_crypto_luks = {
> .bdrv_truncate = block_crypto_truncate,
> .create_opts = &block_crypto_create_opts_luks,
>
> - .bdrv_co_readv = block_crypto_co_readv,
> - .bdrv_co_writev = block_crypto_co_writev,
> + .bdrv_refresh_limits = block_crypto_refresh_limits,
> + .bdrv_co_preadv = block_crypto_co_preadv,
> + .bdrv_co_pwritev = block_crypto_co_pwritev,
> .bdrv_getlength = block_crypto_getlength,
> .bdrv_get_info = block_crypto_get_info_luks,
> .bdrv_get_specific_info = block_crypto_get_specific_info_luks,
Looks weird when = isn't consistently aligned, but we use more than one
space. My preference is to just use one space everywhere, as adding a
longer name to the list doesn't require a mass re-format of all other
entries; but I'm not opposed when people like the aligned = for
legibility. So up to you if you do anything in response to my nit.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
next prev parent reply other threads:[~2017-08-31 15:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 11:05 [Qemu-devel] [PATCH v2 0/4] block: improve luks driver perf & switch to byte APIs Daniel P. Berrange
2017-08-31 11:05 ` [Qemu-devel] [PATCH v2 1/4] block: use 1 MB bounce buffers for crypto instead of 16KB Daniel P. Berrange
2017-08-31 11:05 ` [Qemu-devel] [PATCH v2 2/4] block: use BDRV_SECTOR_SIZE in crypto driver Daniel P. Berrange
2017-08-31 14:54 ` Eric Blake
2017-09-05 9:52 ` Kevin Wolf
2017-09-05 10:05 ` Daniel P. Berrange
2017-09-05 10:23 ` Kevin Wolf
2017-08-31 11:05 ` [Qemu-devel] [PATCH v2 3/4] block: convert crypto driver to bdrv_co_preadv|pwritev Daniel P. Berrange
2017-08-31 15:08 ` Eric Blake [this message]
2017-09-12 10:14 ` Daniel P. Berrange
2017-08-31 11:05 ` [Qemu-devel] [PATCH v2 4/4] block: convert qcrypto_block_encrypt|decrypt to take bytes offset Daniel P. Berrange
2017-08-31 15:17 ` Eric Blake
2017-08-31 15:22 ` Daniel P. Berrange
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3867f025-5d0b-5bed-d47f-a91c706cd3aa@redhat.com \
--to=eblake@redhat.com \
--cc=berrange@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).