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. > > Signed-off-by: Kevin Wolf <[email protected]> > --- > block/block-backend.c | 17 +++++++++++++++++ > include/sysemu/block-backend.h | 9 +++++++++ > 2 files changed, 26 insertions(+) > > 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_backends */ > + BlockBackendPublic public;
Any reason to not put the public struct at offset 0?
> +
> +/*
> + * Returns a BlockBackend given the associated @public fields.
> + */
> +BlockBackend *blk_by_public(BlockBackendPublic *public)
> +{
> + return container_of(public, BlockBackend, public);
> +}
At least container_of() doesn't care, so I guess it doesn't matter.
> +/* This struct is embedded in (the private) BlockBackend struct and contains
> + * fields that must be public. This is in particular for QLIST_ENTRY() and
> + * friends so that BlockBackends can be kept in lists outside
> block-backend.c */
> +typedef struct BlockBackendPublic {
> +} BlockBackendPublic;
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?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
