Received: from eggs.gnu.org ([2001:4830:134:3::10]:48730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aienp-0007Uv-1A for qemu-devel@nongnu.org; Wed, 23 Mar 2016 05:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aienj-0005bY-0Q for qemu-devel@nongnu.org; Wed, 23 Mar 2016 05:10:08 -0400 Date: Wed, 23 Mar 2016 10:09:44 +0100 From: Kevin Wolf Message-ID: <20160323090944.GB4126@noname.redhat.com> References: <1458660792-3035-1-git-send-email-kwolf@redhat.com> <1458660792-3035-4-git-send-email-kwolf@redhat.com> <56F1BEEE.5010307@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline In-Reply-To: <56F1BEEE.5010307@redhat.com> Subject: Re: [Qemu-devel] [PATCH 03/12] block: Introduce BlockBackendPublic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: berto@igalia.com, qemu-devel@nongnu.org, qemu-block@nongnu.org --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 22.03.2016 um 22:53 hat Eric Blake geschrieben: > On 03/22/2016 09:33 AM, Kevin Wolf wrote: > > Some features, like I/O throttling, are implemented outside > > block-backend.c, but still want to keep BlockBackends in a list. In > > order to avoid exposing the whole struct layout in the public header > > file, this patch introduces an embedded public struct where list entry > > structs can be added and a pair of functions to convert between > > BlockBackend and BlockBackendPublic. > >=20 > > Signed-off-by: Kevin Wolf > > --- > > block/block-backend.c | 17 +++++++++++++++++ > > include/sysemu/block-backend.h | 9 +++++++++ > > 2 files changed, 26 insertions(+) > >=20 > > diff --git a/block/block-backend.c b/block/block-backend.c > > index df8f717..4394950 100644 > > --- a/block/block-backend.c > > +++ b/block/block-backend.c > > @@ -33,6 +33,7 @@ struct BlockBackend { > > DriveInfo *legacy_dinfo; /* null unless created by drive_new() = */ > > QTAILQ_ENTRY(BlockBackend) link; /* for block_backends */ > > QTAILQ_ENTRY(BlockBackend) monitor_link; /* for monitor_block_back= ends */ > > + BlockBackendPublic public; >=20 > Any reason to not put the public struct at offset 0? No, but also no reason to put it there. :-) > > + > > +/* > > + * Returns a BlockBackend given the associated @public fields. > > + */ > > +BlockBackend *blk_by_public(BlockBackendPublic *public) > > +{ > > + return container_of(public, BlockBackend, public); > > +} >=20 > At least container_of() doesn't care, so I guess it doesn't matter. >=20 > > +/* This struct is embedded in (the private) BlockBackend struct and co= ntains > > + * fields that must be public. This is in particular for QLIST_ENTRY()= and > > + * friends so that BlockBackends can be kept in lists outside block-ba= ckend.c */ > > +typedef struct BlockBackendPublic { > > +} BlockBackendPublic; >=20 > No fields? So really all we need this for is so that we can have an > address of a member of the larger struct, so that we can do list > operations based on that address? Well, a list still needs a QLIST_ENTRY, otherwise I could have directly used BlockBackend. I just tried to keep the introduction of .public separate from the addition of a specific list. I think it's strictly speaking invalid C to have an empty struct, but gcc compiles it and so I thought it should be acceptable to have one for a single commit until something is added there. Kevin --BXVAT5kNtrzKuDFl Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJW8l1YAAoJEH8JsnLIjy/WoIoP/jTtxqvybvCf0M4BI+dfJ6+L DN/ANOmMhtNbydMxPHKjyQ3MI2CX2TUPn5rQCgf7IWPbMBx93Xq/4MkzxRCC3rmP GdYP93nsdSMtV+tvF/qXsL15z1qPMOpJod/cK6blaauhoepBDy5ZwAjm/NDRksaS nbya9nJ8uAnltFftkHic6kqOFL1BJ/xCZJiX3O7E4s9Fep/eblzt5m+9ZooCX9C6 2j2B5Pa9EED9coALrTfZUk9z5y/0hjdqWfa/zvd9GGn+/to/ec95+DGPs/f6PYWs tstLqxXMz/5+6XexrS0eEJjyrOeFKI6iqMr21No/IdRDesCwpI8i+sHi/PA8kHct zhB2SP8FAAX+OfCIhWpRZ6Twl8Fxw+3x+wCk9GfIicBZIjU9F7SNnAMlFOw0mK/v G32vskibeDIIH0piJh7HZM1mQUPZz/pR7Zu5G04BST+MKIOCTnp/pDvkE9TfAdX6 i6971NKPv1jIsXzFJDOcF99AxvfXi5Vvhj3w+zbR+7n+c8ZBRlrr46u5/cEFhB+j 4loH1ZgQHOSXSB/BvTU4V27VfLJHW3CssZdtQhwASl+a41bwngGoQUiEvGSu3sT7 6+JllYqCziQTVVR9X036lhsb/P1l0Gn6giWJqYcfeDVCcoNry9Fngfler3fbUdpr +bRswoIg7Pu/q/6wLkuw =d8AQ -----END PGP SIGNATURE----- --BXVAT5kNtrzKuDFl--