All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Max Reitz <mreitz@redhat.com>, Eric Blake <eblake@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/5] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
Date: Tue, 30 Apr 2019 12:03:22 +0200	[thread overview]
Message-ID: <20190430100322.GB5607@linux.fritz.box> (raw)
In-Reply-To: <e5e1571c583874454760dc738ef3ea3470ea96e7.1556562150.git.berto@igalia.com>

Am 29.04.2019 um 20:42 hat Alberto Garcia geschrieben:
> There's only a couple of bdrv_read() and bdrv_write() calls left in
> the vdi code, and they can be trivially replaced with the byte-based
> bdrv_pread() and bdrv_pwrite().
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/vdi.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/block/vdi.c b/block/vdi.c
> index e1c42ad732..8d849b2754 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -384,7 +384,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
>  
>      logout("\n");
>  
> -    ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1);
> +    ret = bdrv_pread(bs->file, 0, (uint8_t *)&header, sizeof(header));

Maybe worth adding this after the VdiHeader declaration?

QEMU_BUILD_BUG_ON(sizeof(VdiHeader) != 512);

>      if (ret < 0) {
>          goto fail;
>      }
> @@ -484,8 +484,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
>          goto fail;
>      }
>  
> -    ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap,
> -                    bmap_size);
> +    ret = bdrv_pread(bs->file, header.offset_bmap, (uint8_t *)s->bmap,
> +                     bmap_size * SECTOR_SIZE);
>      if (ret < 0) {
>          goto fail_free_bmap;
>      }
> @@ -704,7 +704,7 @@ nonallocating_write:
>          assert(VDI_IS_ALLOCATED(bmap_first));
>          *header = s->header;
>          vdi_header_to_le(header);
> -        ret = bdrv_write(bs->file, 0, block, 1);
> +        ret = bdrv_pwrite(bs->file, 0, block, sizeof(*block));

block is uint8_t*, so sizeof(*block) == 1. This is not what you want.
(qemu-iotests catches this pretty early.)

>          g_free(block);
>          block = NULL;
>  
> @@ -722,7 +722,8 @@ nonallocating_write:
>          base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
>          logout("will write %u block map sectors starting from entry %u\n",
>                 n_sectors, bmap_first);
> -        ret = bdrv_write(bs->file, offset, base, n_sectors);
> +        ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base,
> +                          n_sectors * SECTOR_SIZE);
>      }
>  
>      return ret;

Let's avoid returning a non-zero positive number in the success case
here. bdrv_driver_pwritev() checks ret == 0 for BDRV_REQ_FUA emulation,
and its callers don't expect positive results either.

Maybe we should actually assert() in bdrv_driver_preadv/pwritev() that
the result is <= 0.

Kevin

WARNING: multiple messages have this Message-ID (diff)
From: Kevin Wolf <kwolf@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 2/5] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
Date: Tue, 30 Apr 2019 12:03:22 +0200	[thread overview]
Message-ID: <20190430100322.GB5607@linux.fritz.box> (raw)
Message-ID: <20190430100322.KJO0XpiJWvIbJNIUk9i3GloVJjrrvToEVFT6exmGYOY@z> (raw)
In-Reply-To: <e5e1571c583874454760dc738ef3ea3470ea96e7.1556562150.git.berto@igalia.com>

Am 29.04.2019 um 20:42 hat Alberto Garcia geschrieben:
> There's only a couple of bdrv_read() and bdrv_write() calls left in
> the vdi code, and they can be trivially replaced with the byte-based
> bdrv_pread() and bdrv_pwrite().
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  block/vdi.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/block/vdi.c b/block/vdi.c
> index e1c42ad732..8d849b2754 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -384,7 +384,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
>  
>      logout("\n");
>  
> -    ret = bdrv_read(bs->file, 0, (uint8_t *)&header, 1);
> +    ret = bdrv_pread(bs->file, 0, (uint8_t *)&header, sizeof(header));

Maybe worth adding this after the VdiHeader declaration?

QEMU_BUILD_BUG_ON(sizeof(VdiHeader) != 512);

>      if (ret < 0) {
>          goto fail;
>      }
> @@ -484,8 +484,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
>          goto fail;
>      }
>  
> -    ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap,
> -                    bmap_size);
> +    ret = bdrv_pread(bs->file, header.offset_bmap, (uint8_t *)s->bmap,
> +                     bmap_size * SECTOR_SIZE);
>      if (ret < 0) {
>          goto fail_free_bmap;
>      }
> @@ -704,7 +704,7 @@ nonallocating_write:
>          assert(VDI_IS_ALLOCATED(bmap_first));
>          *header = s->header;
>          vdi_header_to_le(header);
> -        ret = bdrv_write(bs->file, 0, block, 1);
> +        ret = bdrv_pwrite(bs->file, 0, block, sizeof(*block));

block is uint8_t*, so sizeof(*block) == 1. This is not what you want.
(qemu-iotests catches this pretty early.)

>          g_free(block);
>          block = NULL;
>  
> @@ -722,7 +722,8 @@ nonallocating_write:
>          base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
>          logout("will write %u block map sectors starting from entry %u\n",
>                 n_sectors, bmap_first);
> -        ret = bdrv_write(bs->file, offset, base, n_sectors);
> +        ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base,
> +                          n_sectors * SECTOR_SIZE);
>      }
>  
>      return ret;

Let's avoid returning a non-zero positive number in the success case
here. bdrv_driver_pwritev() checks ret == 0 for BDRV_REQ_FUA emulation,
and its callers don't expect positive results either.

Maybe we should actually assert() in bdrv_driver_preadv/pwritev() that
the result is <= 0.

Kevin


  reply	other threads:[~2019-04-30 10:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-29 18:42 [Qemu-devel] [PATCH 0/5] Remove bdrv_read() and bdrv_write() Alberto Garcia
2019-04-29 18:42 ` Alberto Garcia
2019-04-29 18:42 ` [Qemu-devel] [PATCH 1/5] qcow2: Replace bdrv_write() with bdrv_pwrite() Alberto Garcia
2019-04-29 18:42   ` Alberto Garcia
2019-04-29 18:42 ` [Qemu-devel] [PATCH 2/5] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}() Alberto Garcia
2019-04-29 18:42   ` Alberto Garcia
2019-04-30 10:03   ` Kevin Wolf [this message]
2019-04-30 10:03     ` Kevin Wolf
2019-04-29 18:42 ` [Qemu-devel] [PATCH 3/5] vvfat: " Alberto Garcia
2019-04-29 18:42   ` Alberto Garcia
2019-04-30  9:52   ` Kevin Wolf
2019-04-30  9:52     ` Kevin Wolf
2019-04-29 18:42 ` [Qemu-devel] [PATCH 4/5] block: Remove bdrv_read() and bdrv_write() Alberto Garcia
2019-04-29 18:42   ` Alberto Garcia
2019-04-29 18:42 ` [Qemu-devel] [PATCH 5/5] qcow2: Remove BDRVQcow2State.cluster_sectors Alberto Garcia
2019-04-29 18:42   ` Alberto Garcia
2019-04-29 19:46 ` [Qemu-devel] [PATCH 0/5] Remove bdrv_read() and bdrv_write() Eric Blake
2019-04-29 19:46   ` Eric Blake
2019-05-01  7:33 ` no-reply
2019-05-01  7:33   ` no-reply
2019-05-01  8:54 ` no-reply
2019-05-01  8:54   ` no-reply

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=20190430100322.GB5607@linux.fritz.box \
    --to=kwolf@redhat.com \
    --cc=berto@igalia.com \
    --cc=eblake@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.