[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 02/10] block: New bdrv_nb_sectors()
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v2 02/10] block: New bdrv_nb_sectors() |
Date: |
Wed, 28 May 2014 09:02:24 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
On 05/28/2014 08:25 AM, Markus Armbruster wrote:
> A call to retrieve the image size converts between bytes and sectors
> several times:
>
> * BlockDriver method bdrv_getlength() returns bytes.
>
> * refresh_total_sectors() converts to sectors, rounding up, and stores
> in total_sectors.
>
> * bdrv_getlength() converts total_sectors back to bytes (now rounded
> up to a multiple of the sector size).
>
> * Callers wanting sectors rather bytes convert it right back.
> Example: bdrv_get_geometry().
>
> bdrv_nb_sectors() provides a way to omit the last two conversions.
> It's exactly bdrv_getlength() with the conversion to bytes omitted.
> It's functionally like bdrv_get_geometry() without its odd error
> handling.
>
> Reimplement bdrv_getlength() and bdrv_get_geometry() on top of
> bdrv_nb_sectors().
>
> The next patches will convert some users of bdrv_getlength() to
> bdrv_nb_sectors().
>
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
> block.c | 29 +++++++++++++++++++----------
> include/block/block.h | 1 +
> 2 files changed, 20 insertions(+), 10 deletions(-)
Reviewed-by: Eric Blake <address@hidden>
> +/**
> + * Return length in bytes on success, -errno on error.
> + * The length is always a multiple of BDRV_SECTOR_SIZE.
> + */
> +int64_t bdrv_getlength(BlockDriverState *bs)
The second sentence might not always be true in the future if we add
support for image length not a multiple of sector size; but we can
correct it at the point we make such a change. For now, it is worth
keeping.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v2 00/10] Clean up around bdrv_getlength(), Markus Armbruster, 2014/05/28
- [Qemu-devel] [PATCH v2 01/10] raw-posix: Fix raw_getlength() to always return -errno on error, Markus Armbruster, 2014/05/28
- [Qemu-devel] [PATCH v2 02/10] block: New bdrv_nb_sectors(), Markus Armbruster, 2014/05/28
- Re: [Qemu-devel] [PATCH v2 02/10] block: New bdrv_nb_sectors(),
Eric Blake <=
- [Qemu-devel] [PATCH v2 03/10] block: Use bdrv_nb_sectors() in bdrv_make_zero(), Markus Armbruster, 2014/05/28
- [Qemu-devel] [PATCH v2 08/10] block: Drop superfluous aligning of bdrv_getlength()'s value, Markus Armbruster, 2014/05/28
- [Qemu-devel] [PATCH v2 06/10] block: Use bdrv_nb_sectors() in img_convert(), Markus Armbruster, 2014/05/28
- [Qemu-devel] [PATCH v2 09/10] qemu-img: Make img_convert() get image size just once per image, Markus Armbruster, 2014/05/28