On 04/09/2014 01:12 AM, Hu Tao wrote:
> and avoid converting it back later.
> 
> Signed-off-by: Hu Tao <hu...@cn.fujitsu.com>
> ---
>  block/qcow2.c     | 8 ++++----
>  block/raw-posix.c | 4 ++--
>  block/raw-win32.c | 4 ++--
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 

> @@ -1777,7 +1777,7 @@ static int qcow2_create(const char *filename, 
> QEMUOptionParameter *options,
>      /* Read out options */
>      while (options && options->name) {
>          if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            sectors = options->value.n / 512;
> +            size = options->value.n & BDRV_SECTOR_MASK;

The old code rounds down, which in my opinion is a bug.  The qcow2 file
format has a size parameter that is recorded in bytes, not sectors, so I
see no technical reason why we can't support a file where the last
sector is partial.  If I request a size 1025 bytes, I should get a file
with 3 sectors (where the last sector is partial), and not a file with 2
sectors (where the last byte that I requested cannot be accessed).  Your
patch preserves the pre-existing behavior, but I think this series
should consider fixing the bug and allowing for the creation of a qcow2
file whose size exposed to the guest is NOT a multiple of sector size,
or at least, at a bare minimum, round my request UP to the nearest
sector size rather than giving me something smaller than what I asked for.


> +++ b/block/raw-posix.c
> @@ -1246,7 +1246,7 @@ static int raw_create(const char *filename, 
> QEMUOptionParameter *options,
>      /* Read out options */
>      while (options && options->name) {
>          if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            total_size = options->value.n / BDRV_SECTOR_SIZE;
> +            total_size = options->value.n & BDRV_SECTOR_MASK;

Another case of incorrectly rounding down.

> +++ b/block/raw-win32.c
> @@ -486,7 +486,7 @@ static int raw_create(const char *filename, 
> QEMUOptionParameter *options,
>      /* Read out options */
>      while (options && options->name) {
>          if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> -            total_size = options->value.n / 512;
> +            total_size = options->value.n & BDRV_SECTOR_MASK;

and another

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to