Skip to contentSkip to conversation

qemu-img: Saner printing of large file sizes

PATCH Applied Vladimir Sementsov-Ogievskiy 4 participants 6 messages Apr 1, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Vladimir Sementsov-Ogievskiy

author Reviewed-by
#1 lore raw
Quoted 18 lines · Eric Blake

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

   $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
   image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
   file format: raw
   virtual size: -8388607T (9223372036854775296 bytes)
   disk size: unavailable

But there's no reason to have two separate implementations of integer to human-readable abbreviation, where one has overflow and stops at 'T', while the other avoids overflow and goes all the way to 'E'. With this patch, the output now claims 8EiB instead of -8388607T, which really is the correct rounding of largest file size supported by qemu (we could go 511 bytes larger if we used byte-accurate sizing instead of rounding up to the next sector boundary, but that wouldn't change the human-readable result).

Quoted 2 lines
Signature · 2 lines
Best regards,
Vladimir
#2 lore raw
In reply to a message not in the archive

Am 30.03.2019 um 16:07 hat Eric Blake geschrieben:

Quoted 18 lines

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

  $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
  image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
  file format: raw
  virtual size: -8388607T (9223372036854775296 bytes)
  disk size: unavailable

But there's no reason to have two separate implementations of integer to human-readable abbreviation, where one has overflow and stops at 'T', while the other avoids overflow and goes all the way to 'E'. With this patch, the output now claims 8EiB instead of -8388607T, which really is the correct rounding of largest file size supported by qemu (we could go 511 bytes larger if we used byte-accurate sizing instead of rounding up to the next sector boundary, but that wouldn't change the human-readable result).

Quoted 2 lines

This is quite obviously a bug fix for some cases. This suggests that we want it in 4.0.

It is also an output change for other cases, like going from "8M" to "8 MiB". We probably can't tell for sure whether some tools expect the spelling "8M" (even if this is supposed to be the human interface and tools should be using JSON) or feed the change back to qemu-img or qemu-io (which accept "8M", but not "8 MiB" as sizes in most places). This suggests that we shouldn't make this change as late as -rc2.

So what is the conclusion?

Kevin

#3 lore raw
Quoted 25 lines · Kevin Wolf

Am 30.03.2019 um 16:07 hat Eric Blake geschrieben:

Quoted 18 lines

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

  $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
  image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
  file format: raw
  virtual size: -8388607T (9223372036854775296 bytes)
  disk size: unavailable

But there's no reason to have two separate implementations of integer to human-readable abbreviation, where one has overflow and stops at 'T', while the other avoids overflow and goes all the way to 'E'. With this patch, the output now claims 8EiB instead of -8388607T, which really is the correct rounding of largest file size supported by qemu (we could go 511 bytes larger if we used byte-accurate sizing instead of rounding up to the next sector boundary, but that wouldn't change the human-readable result).

Quoted 2 lines

This is quite obviously a bug fix for some cases. This suggests that we want it in 4.0.

Quoted 6 lines

It is also an output change for other cases, like going from "8M" to "8 MiB". We probably can't tell for sure whether some tools expect the spelling "8M" (even if this is supposed to be the human interface and tools should be using JSON) or feed the change back to qemu-img or qemu-io (which accept "8M", but not "8 MiB" as sizes in most places). This suggests that we shouldn't make this change as late as -rc2.

If it breaks our own tests, then it is possible to break other tools too.

Quoted 1 line

So what is the conclusion?

The safe option is to do the minimal fix for the existing code and look at the refactoring in the next dev cycle.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw
Quoted 22 lines · Daniel P. Berrangé
Quoted 14 lines · Kevin Wolf

Am 30.03.2019 um 16:07 hat Eric Blake geschrieben:

Quoted 9 lines

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

  $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
  image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
  file format: raw
  virtual size: -8388607T (9223372036854775296 bytes)
  disk size: unavailable

This is quite obviously a bug fix for some cases. This suggests that we want it in 4.0.

Quoted 6 lines

It is also an output change for other cases, like going from "8M" to "8 MiB". We probably can't tell for sure whether some tools expect the spelling "8M" (even if this is supposed to be the human interface and tools should be using JSON) or feed the change back to qemu-img or qemu-io (which accept "8M", but not "8 MiB" as sizes in most places). This suggests that we shouldn't make this change as late as -rc2.

Quoted 7 lines

If it breaks our own tests, then it is possible to break other tools too.

Quoted 1 line

So what is the conclusion?

The safe option is to do the minimal fix for the existing code and look at the refactoring in the next dev cycle.

It's not worth fixing the second implementation to match the first in terms of support for sizes > T with no overflow, but with the existing format of 8.0M vs. 8 MiB. I'm happy to defer this patch to 4.1; the bug is not new to 4.0, so living with it for one more release doesn't hurt.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Applied
#5 lore raw
In reply to a message not in the archive

Am 30.03.2019 um 16:07 hat Eric Blake geschrieben:

Quoted 18 lines

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

  $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
  image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
  file format: raw
  virtual size: -8388607T (9223372036854775296 bytes)
  disk size: unavailable

But there's no reason to have two separate implementations of integer to human-readable abbreviation, where one has overflow and stops at 'T', while the other avoids overflow and goes all the way to 'E'. With this patch, the output now claims 8EiB instead of -8388607T, which really is the correct rounding of largest file size supported by qemu (we could go 511 bytes larger if we used byte-accurate sizing instead of rounding up to the next sector boundary, but that wouldn't change the human-readable result).

Quoted 2 lines

Thanks, applied to the block-next branch for 4.1.

Kevin

#6 lore raw
Quoted 19 lines · Kevin Wolf

Am 30.03.2019 um 16:07 hat Eric Blake geschrieben:

Quoted 18 lines

Disk sizes close to INT64_MAX cause overflow, for some pretty ridiculous output:

  $ ./nbdkit -U - memory size=$((2**63 - 512)) --run 'qemu-img info $nbd'
  image: nbd+unix://?socket=/tmp/nbdkitHSAzNz/socket
  file format: raw
  virtual size: -8388607T (9223372036854775296 bytes)
  disk size: unavailable

But there's no reason to have two separate implementations of integer to human-readable abbreviation, where one has overflow and stops at 'T', while the other avoids overflow and goes all the way to 'E'. With this patch, the output now claims 8EiB instead of -8388607T, which really is the correct rounding of largest file size supported by qemu (we could go 511 bytes larger if we used byte-accurate sizing instead of rounding up to the next sector boundary, but that wouldn't change the human-readable result).

Quoted 4 lines
Quoted 2 lines

Thanks, applied to the block-next branch for 4.1.

You'll need v2. Coming up shortly.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org