From: Paolo Bonzini <pbonzini@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com, Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/2] nbd: Convert to byte-based interface
Date: Mon, 27 Jun 2016 14:19:25 +0200 [thread overview]
Message-ID: <c8826ebf-8a80-ff1e-94f6-cb4280e29102@redhat.com> (raw)
In-Reply-To: <1466740739-7240-2-git-send-email-eblake@redhat.com>
On 24/06/2016 05:58, Eric Blake wrote:
> The NBD protocol doesn't have any notion of sectors, so it is
> a fairly easy convertion to use byte-based read and write.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
> block/nbd-client.h | 8 ++++----
> include/block/nbd.h | 1 -
> block/nbd-client.c | 30 +++++++++++++++++-------------
> block/nbd.c | 12 ++++++------
> 4 files changed, 27 insertions(+), 24 deletions(-)
>
> diff --git a/block/nbd-client.h b/block/nbd-client.h
> index 62dec33..fa9817b 100644
> --- a/block/nbd-client.h
> +++ b/block/nbd-client.h
> @@ -46,10 +46,10 @@ void nbd_client_close(BlockDriverState *bs);
>
> int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int count);
> int nbd_client_co_flush(BlockDriverState *bs);
> -int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
> - int nb_sectors, QEMUIOVector *qiov, int flags);
> -int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num,
> - int nb_sectors, QEMUIOVector *qiov);
> +int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
> + uint64_t bytes, QEMUIOVector *qiov, int flags);
> +int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
> + uint64_t bytes, QEMUIOVector *qiov, int flags);
>
> void nbd_client_detach_aio_context(BlockDriverState *bs);
> void nbd_client_attach_aio_context(BlockDriverState *bs,
> diff --git a/include/block/nbd.h b/include/block/nbd.h
> index 503f514..cb91820 100644
> --- a/include/block/nbd.h
> +++ b/include/block/nbd.h
> @@ -77,7 +77,6 @@ enum {
>
> /* Maximum size of a single READ/WRITE data buffer */
> #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024)
> -#define NBD_MAX_SECTORS (NBD_MAX_BUFFER_SIZE / BDRV_SECTOR_SIZE)
>
> /* Maximum size of an export name. The NBD spec requires 256 and
> * suggests that servers support up to 4096, but we stick to only the
> diff --git a/block/nbd-client.c b/block/nbd-client.c
> index 070bb9d..647dedd 100644
> --- a/block/nbd-client.c
> +++ b/block/nbd-client.c
> @@ -218,17 +218,20 @@ static void nbd_coroutine_end(NbdClientSession *s,
> }
> }
>
> -int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num,
> - int nb_sectors, QEMUIOVector *qiov)
> +int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
> + uint64_t bytes, QEMUIOVector *qiov, int flags)
> {
> NbdClientSession *client = nbd_get_client_session(bs);
> - struct nbd_request request = { .type = NBD_CMD_READ };
> + struct nbd_request request = {
> + .type = NBD_CMD_READ,
> + .from = offset,
> + .len = bytes,
> + };
> struct nbd_reply reply;
> ssize_t ret;
>
> - assert(nb_sectors <= NBD_MAX_SECTORS);
> - request.from = sector_num * 512;
> - request.len = nb_sectors * 512;
> + assert(bytes <= NBD_MAX_BUFFER_SIZE);
> + assert(!flags);
>
> nbd_coroutine_start(client, &request);
> ret = nbd_co_send_request(bs, &request, NULL);
> @@ -239,14 +242,17 @@ int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num,
> }
> nbd_coroutine_end(client, &request);
> return -reply.error;
> -
> }
>
> -int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
> - int nb_sectors, QEMUIOVector *qiov, int flags)
> +int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
> + uint64_t bytes, QEMUIOVector *qiov, int flags)
> {
> NbdClientSession *client = nbd_get_client_session(bs);
> - struct nbd_request request = { .type = NBD_CMD_WRITE };
> + struct nbd_request request = {
> + .type = NBD_CMD_WRITE,
> + .from = offset,
> + .len = bytes,
> + };
> struct nbd_reply reply;
> ssize_t ret;
>
> @@ -255,9 +261,7 @@ int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
> request.type |= NBD_CMD_FLAG_FUA;
> }
>
> - assert(nb_sectors <= NBD_MAX_SECTORS);
> - request.from = sector_num * 512;
> - request.len = nb_sectors * 512;
> + assert(bytes <= NBD_MAX_BUFFER_SIZE);
>
> nbd_coroutine_start(client, &request);
> ret = nbd_co_send_request(bs, &request, qiov);
> diff --git a/block/nbd.c b/block/nbd.c
> index 42cae0e..8d57220 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -438,8 +438,8 @@ static BlockDriver bdrv_nbd = {
> .instance_size = sizeof(BDRVNBDState),
> .bdrv_parse_filename = nbd_parse_filename,
> .bdrv_file_open = nbd_open,
> - .bdrv_co_readv = nbd_client_co_readv,
> - .bdrv_co_writev_flags = nbd_client_co_writev,
> + .bdrv_co_preadv = nbd_client_co_preadv,
> + .bdrv_co_pwritev = nbd_client_co_pwritev,
> .bdrv_close = nbd_close,
> .bdrv_co_flush_to_os = nbd_co_flush,
> .bdrv_co_pdiscard = nbd_client_co_pdiscard,
> @@ -456,8 +456,8 @@ static BlockDriver bdrv_nbd_tcp = {
> .instance_size = sizeof(BDRVNBDState),
> .bdrv_parse_filename = nbd_parse_filename,
> .bdrv_file_open = nbd_open,
> - .bdrv_co_readv = nbd_client_co_readv,
> - .bdrv_co_writev_flags = nbd_client_co_writev,
> + .bdrv_co_preadv = nbd_client_co_preadv,
> + .bdrv_co_pwritev = nbd_client_co_pwritev,
> .bdrv_close = nbd_close,
> .bdrv_co_flush_to_os = nbd_co_flush,
> .bdrv_co_pdiscard = nbd_client_co_pdiscard,
> @@ -474,8 +474,8 @@ static BlockDriver bdrv_nbd_unix = {
> .instance_size = sizeof(BDRVNBDState),
> .bdrv_parse_filename = nbd_parse_filename,
> .bdrv_file_open = nbd_open,
> - .bdrv_co_readv = nbd_client_co_readv,
> - .bdrv_co_writev_flags = nbd_client_co_writev,
> + .bdrv_co_preadv = nbd_client_co_preadv,
> + .bdrv_co_pwritev = nbd_client_co_pwritev,
> .bdrv_close = nbd_close,
> .bdrv_co_flush_to_os = nbd_co_flush,
> .bdrv_co_pdiscard = nbd_client_co_pdiscard,
>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2016-06-27 12:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 3:58 [Qemu-devel] [PATCH 0/2] Switch raw NBD to byte-based Eric Blake
2016-06-24 3:58 ` [Qemu-devel] [PATCH 1/2] nbd: Convert to byte-based interface Eric Blake
2016-06-27 12:19 ` Paolo Bonzini [this message]
2016-06-24 3:58 ` [Qemu-devel] [PATCH 2/2] raw_bsd: " Eric Blake
2016-06-27 12:19 ` Paolo Bonzini
2016-06-27 12:51 ` Eric Blake
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=c8826ebf-8a80-ff1e-94f6-cb4280e29102@redhat.com \
--to=pbonzini@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).