All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple
@ 2014-05-22  9:42 Stefan Hajnoczi
  2014-05-22 16:52 ` Eric Blake
  2014-05-23 11:18 ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-05-22  9:42 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Maria Kustova, Benoît Canet, Stefan Hajnoczi

Normally one would expect that qcow2 image file lengths are multiples of
the cluster size.  This is not true in all cases and the spec should
document this so implementers remember to accept such files.

$ qemu-img create -f qcow2 foo.qcow2 2G
Formatting 'foo.qcow2', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 lazy_refcounts=off
$ ls -l foo.qcow2
-rw-r--r-- 1 stefanha stefanha 197120 May 22 11:40 foo.qcow2
$ bc -q
3 * (64 * 1024) + 512
197120

The extra sector are the 4 L1 table entries that a 2 GB disk with 64 KB
cluster size needs.  The rest of the L1 table is omitted from the file
but allocation will continue at the next cluster boundary.

Reported-by: Maria Kustova <maxa@catit.be>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 docs/specs/qcow2.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt
index f19536a..a46ee57 100644
--- a/docs/specs/qcow2.txt
+++ b/docs/specs/qcow2.txt
@@ -4,6 +4,10 @@ A qcow2 image file is organized in units of constant size, which are called
 (host) clusters. A cluster is the unit in which all allocations are done,
 both for actual guest data and for image metadata.
 
+If the end of the image file is not on a cluster boundary, the missing data is
+treated as zeroes.  This layout can occur when an L1 table or refcount table is
+the last thing in the file and not all entries in the table are used.
+
 Likewise, the virtual disk as seen by the guest is divided into (guest)
 clusters of the same size.
 
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple
  2014-05-22  9:42 [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple Stefan Hajnoczi
@ 2014-05-22 16:52 ` Eric Blake
  2014-05-23 11:18 ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-05-22 16:52 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel; +Cc: Kevin Wolf, Maria Kustova, Benoît Canet

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

On 05/22/2014 03:42 AM, Stefan Hajnoczi wrote:
> Normally one would expect that qcow2 image file lengths are multiples of
> the cluster size.  This is not true in all cases and the spec should
> document this so implementers remember to accept such files.
> 
> $ qemu-img create -f qcow2 foo.qcow2 2G
> Formatting 'foo.qcow2', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 lazy_refcounts=off
> $ ls -l foo.qcow2
> -rw-r--r-- 1 stefanha stefanha 197120 May 22 11:40 foo.qcow2
> $ bc -q
> 3 * (64 * 1024) + 512
> 197120
> 
> The extra sector are the 4 L1 table entries that a 2 GB disk with 64 KB
> cluster size needs.  The rest of the L1 table is omitted from the file
> but allocation will continue at the next cluster boundary.
> 
> Reported-by: Maria Kustova <maxa@catit.be>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  docs/specs/qcow2.txt | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple
  2014-05-22  9:42 [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple Stefan Hajnoczi
  2014-05-22 16:52 ` Eric Blake
@ 2014-05-23 11:18 ` Kevin Wolf
  2014-05-26 11:57   ` Stefan Hajnoczi
  1 sibling, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2014-05-23 11:18 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Maria Kustova, qemu-devel, Benoît Canet

Am 22.05.2014 um 11:42 hat Stefan Hajnoczi geschrieben:
> Normally one would expect that qcow2 image file lengths are multiples of
> the cluster size.  This is not true in all cases and the spec should
> document this so implementers remember to accept such files.
> 
> $ qemu-img create -f qcow2 foo.qcow2 2G
> Formatting 'foo.qcow2', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 lazy_refcounts=off
> $ ls -l foo.qcow2
> -rw-r--r-- 1 stefanha stefanha 197120 May 22 11:40 foo.qcow2
> $ bc -q
> 3 * (64 * 1024) + 512
> 197120
> 
> The extra sector are the 4 L1 table entries that a 2 GB disk with 64 KB
> cluster size needs.  The rest of the L1 table is omitted from the file
> but allocation will continue at the next cluster boundary.
> 
> Reported-by: Maria Kustova <maxa@catit.be>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>  docs/specs/qcow2.txt | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt
> index f19536a..a46ee57 100644
> --- a/docs/specs/qcow2.txt
> +++ b/docs/specs/qcow2.txt
> @@ -4,6 +4,10 @@ A qcow2 image file is organized in units of constant size, which are called
>  (host) clusters. A cluster is the unit in which all allocations are done,
>  both for actual guest data and for image metadata.
>  
> +If the end of the image file is not on a cluster boundary, the missing data is
> +treated as zeroes.  This layout can occur when an L1 table or refcount table is
> +the last thing in the file and not all entries in the table are used.
> +
>  Likewise, the virtual disk as seen by the guest is divided into (guest)
>  clusters of the same size.

Why don't we specify this for _any_ data after EOF, as we discussed on
IRC, instead of just for a partial last cluster?

If we restrict it to the last cluster, specifying the data as zero
doesn't make a whole lot of sense because then the data there wouldn't
be supposed to be interpreted anyway.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple
  2014-05-23 11:18 ` Kevin Wolf
@ 2014-05-26 11:57   ` Stefan Hajnoczi
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-05-26 11:57 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Maria Kustova, qemu-devel, Benoît Canet

On Fri, May 23, 2014 at 01:18:50PM +0200, Kevin Wolf wrote:
> Am 22.05.2014 um 11:42 hat Stefan Hajnoczi geschrieben:
> > diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt
> > index f19536a..a46ee57 100644
> > --- a/docs/specs/qcow2.txt
> > +++ b/docs/specs/qcow2.txt
> > @@ -4,6 +4,10 @@ A qcow2 image file is organized in units of constant size, which are called
> >  (host) clusters. A cluster is the unit in which all allocations are done,
> >  both for actual guest data and for image metadata.
> >  
> > +If the end of the image file is not on a cluster boundary, the missing data is
> > +treated as zeroes.  This layout can occur when an L1 table or refcount table is
> > +the last thing in the file and not all entries in the table are used.
> > +
> >  Likewise, the virtual disk as seen by the guest is divided into (guest)
> >  clusters of the same size.
> 
> Why don't we specify this for _any_ data after EOF, as we discussed on
> IRC, instead of just for a partial last cluster?
> 
> If we restrict it to the last cluster, specifying the data as zero
> doesn't make a whole lot of sense because then the data there wouldn't
> be supposed to be interpreted anyway.

That's too general.  Specifying it that way means almost all offsets
become valid because you're just supposed to read zeroes!  That will
definitely cause trouble, let's be stricter here.

Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-26 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-22  9:42 [Qemu-devel] [PATCH] docs: clarify that qcow2 file size is not always a cluster multiple Stefan Hajnoczi
2014-05-22 16:52 ` Eric Blake
2014-05-23 11:18 ` Kevin Wolf
2014-05-26 11:57   ` Stefan Hajnoczi

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.