From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFZq-00023W-EH for qemu-devel@nongnu.org; Fri, 16 May 2014 06:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WlFZl-0005vI-Qn for qemu-devel@nongnu.org; Fri, 16 May 2014 06:41:22 -0400 Date: Fri, 16 May 2014 12:41:11 +0200 From: Kevin Wolf Message-ID: <20140516104111.GD4508@noname.redhat.com> References: <1400163717-1898-1-git-send-email-kwolf@redhat.com> <1400163717-1898-2-git-send-email-kwolf@redhat.com> <5374E217.7090607@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <5374E217.7090607@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 1/5] qcow1: Make padding in the header explicit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: benoit.canet@irqsave.net, ppandit@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, qemu-stable@nongnu.org --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 15.05.2014 um 17:49 hat Eric Blake geschrieben: > On 05/15/2014 08:21 AM, Kevin Wolf wrote: > > We were relying on all compilers inserting the same padding in the > > header struct that is used for the on-disk format. Let's not do that. > > Mark the struct as packed and insert an explicit padding field for > > compatibility. > >=20 > > Cc: qemu-stable@nongnu.org > > Signed-off-by: Kevin Wolf > > Reviewed-by: Benoit Canet > > --- > > block/qcow.c | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > >=20 > > diff --git a/block/qcow.c b/block/qcow.c > > index 937dd6d..3684794 100644 > > --- a/block/qcow.c > > +++ b/block/qcow.c > > @@ -48,9 +48,10 @@ typedef struct QCowHeader { > > uint64_t size; /* in bytes */ > > uint8_t cluster_bits; > > uint8_t l2_bits; > > + uint16_t padding; > > uint32_t crypt_method; > > uint64_t l1_table_offset; > > -} QCowHeader; > > +} QEMU_PACKED QCowHeader; >=20 > Is it worth a compile-time assertion that the correct size is achieved? >=20 > [I don't know if glib provides such a macro, but gnulib has a verify() > macro that could be used as: >=20 > verify(sizeof(QCowHeader) =3D=3D NNN) >=20 > which expands to _Static_assert(sizeof(QCowHeader) =3D=3D NNN) in new eno= ugh > C compilers, and to something like >=20 > extern int (*dummy1(void)) [sizeof (struct dummy2 { > int dummy3: (sizeof(QCowHeader) =3D=3D NNN) ? 1 : -1; })] >=20 > on older compilers for reliable compile-time detection] >=20 > But not a show-stopper to this patch as-is. QEMU_BUILD_BUG_ON() is what you're looking for. Do you think that would be a useful addition? With packed structs there should be little that could make it go wrong. But if we want to add this, I'd do it in a separate patch and for all image formats. Kevin --pf9I7BMVVzbSWLtt Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJTdetHAAoJEH8JsnLIjy/WT0UP/jtma1E/Ho+UkEfgZGG4e7kO PCyZhHg/0E4PsflqSnAdJexrm4lKWInX+5n6lX5fGUF7dVahxfQvpnUdlLcjWYbW ywYr3e/eiZmPW7/0VeWqxfm8jfANQPPZ2Fp0Eyu29SGWSxn4RHbLwi0pewTGJqi8 eFdJKcEAKYgnL5h9ZM4FrPSZ0ley+VmN3co2D2oKyVHykc4FaPOBlEYevJygoNEc cfgb9wqJrXKfXxS3/bMrIE5aZEpHLFv338mrLwusrKODsQN5TC3FK1Rj3oVYP8eZ n2FajJO/45Qklwe2ckJn/d9ZvNJa2POEqevXiyFTl3DafhUhMp4zgb0ZWuc9u8n6 y8gnSFB3b0d3c+SBbA62UCZlo2FhV+EXnqglZM0F0594haaOquSJyQTRSbmJmOcR qw46aG/6/taV5BR6Ufd2KxAdgPISYFbIO5pHw6vLEgZf8c2nXrXFz9TPPqx7zbgH CvelYDhUF1IgKv1MaJwd8Cd+i7C1dyzt+UnsSI+UOiTMnlRP8E2vJ8RjBpuAX3lB C1HMzpRZl7g1pj23l2bBmfwDXxSrGKVDWwcM6H4hEly1raMueudtlDaVYlFGzpWw jbWFWxOtddYfER8yOXoZtr2+5TXZg4xUGf0XRCRkXNDIG/ICly3a6YMMudxvFG4y wwKOXeHnG5Dj/KjJ+C6j =vHHD -----END PGP SIGNATURE----- --pf9I7BMVVzbSWLtt--