Received: from eggs.gnu.org ([2001:4830:134:3::10]:52524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VleTl-0005NR-0o for qemu-devel@nongnu.org; Wed, 27 Nov 2013 07:44:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VleTd-00026Q-N9 for qemu-devel@nongnu.org; Wed, 27 Nov 2013 07:44:28 -0500 Date: Wed, 27 Nov 2013 13:44:23 +0100 From: Kevin Wolf Message-ID: <20131127124423.GC2884@dhcp-200-207.str.redhat.com> References: <1385462881-12290-1-git-send-email-kwolf@redhat.com> <52949198.8080907@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <52949198.8080907@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [Qemu-stable] [PATCH] qcow2: Zero-initialise first cluster for new images List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: qemu-devel@nongnu.org, stefanha@redhat.com, qemu-stable@nongnu.org Am 26.11.2013 um 13:18 hat Fam Zheng geschrieben: > On 2013=E5=B9=B411=E6=9C=8826=E6=97=A5 18:48, Kevin Wolf wrote: > >Strictly speaking, this is only required for has_zero_init() =3D=3D fa= lse, > >but it's easy enough to just do a cluster-aligned write that is padded > >with zeros after the header. > > > >This fixes that after 'qemu-img create' header extensions are attempte= d > >to be parsed that are really just random leftover data. > > > >Cc: qemu-stable@nongnu.org > >Signed-off-by: Kevin Wolf > >--- > > block/qcow2.c | 37 +++++++++++++++++++++---------------- > > 1 file changed, 21 insertions(+), 16 deletions(-) > > > >diff --git a/block/qcow2.c b/block/qcow2.c > >index 6e5d98d..7c18587 100644 > >--- a/block/qcow2.c > >+++ b/block/qcow2.c > >@@ -1471,7 +1471,7 @@ static int qcow2_create2(const char *filename, i= nt64_t total_size, > > * size for any qcow2 image. > > */ > > BlockDriverState* bs; > >- QCowHeader header; > >+ QCowHeader *header; > > uint8_t* refcount_table; > > Error *local_err =3D NULL; > > int ret; > >@@ -1489,30 +1489,35 @@ static int qcow2_create2(const char *filename,= int64_t total_size, > > } > > > > /* Write the header */ > >- memset(&header, 0, sizeof(header)); > >- header.magic =3D cpu_to_be32(QCOW_MAGIC); > >- header.version =3D cpu_to_be32(version); > >- header.cluster_bits =3D cpu_to_be32(cluster_bits); > >- header.size =3D cpu_to_be64(0); > >- header.l1_table_offset =3D cpu_to_be64(0); > >- header.l1_size =3D cpu_to_be32(0); > >- header.refcount_table_offset =3D cpu_to_be64(cluster_size); > >- header.refcount_table_clusters =3D cpu_to_be32(1); > >- header.refcount_order =3D cpu_to_be32(3 + REFCOUNT_SHIFT); > >- header.header_length =3D cpu_to_be32(sizeof(header)); > >+ QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header)); > >+ header =3D g_malloc(cluster_size); > >+ memset(header, 0, cluster_size); >=20 > Could just be: >=20 > header =3D g_malloc0(cluster_size); >=20 > But either way, Yes, that's better. I'll change it. > Reviewed-by: Fam Zheng Thanks. Kevin