[Libguestfs] [PATCH 5/7] New APIs: add-domain and add-libvirt-dom.
Richard W.M. Jones
rjones at redhat.com
Wed Nov 10 12:47:55 UTC 2010
On Wed, Nov 10, 2010 at 12:26:03PM +0000, Daniel P. Berrange wrote:
> On Wed, Nov 10, 2010 at 12:11:22PM +0000, Richard W.M. Jones wrote:
> > On Wed, Nov 10, 2010 at 11:58:40AM +0000, Daniel P. Berrange wrote:
> > > On Wed, Nov 10, 2010 at 11:46:31AM +0000, Richard W.M. Jones wrote:
> > > > diff --git a/src/guestfs.h b/src/guestfs.h
> > > > index 0f4f9fd..be7398a 100644
> > > > --- a/src/guestfs.h
> > > > +++ b/src/guestfs.h
> > > > @@ -79,6 +79,11 @@ extern void guestfs_set_private (guestfs_h *g, const char *key, void *data);
> > > > extern void *guestfs_get_private (guestfs_h *g, const char *key);
> > > >
> > > > /*--- Structures and actions ---*/
> > > > +
> > > > +/* Hack to avoid needing to include <libvirt.h> */
> > > > +typedef struct _virDomain virDomain;
> > > > +typedef virDomain *virDomainPtr;
> > > > +
> > > > #include <rpc/types.h>
> > > > #include <rpc/xdr.h>
> > > > #include <guestfs-structs.h>
> > >
> > > Surely this will break any application whose code does
> > >
> > > #include <libvirt/libvirt.h>
> > > #include <guestfs.h>
> > >
> > > because they'll get a duplicated definition of virDomain from
> > > both headers.
> >
> > I checked and it works fine both ways round. It would break if
> > libvirt changed the definition, but you've boxed yourself into a
> > corner there by documenting the current definition:
>
> Surely the compiler should complain about duplicated typedefs, even
> if they are identical, because C doesn't allow duplicate typedefs
> within the same scope.
>
> http://david.tribble.com/text/cdiffs.htm#C99-typedefs
>
> eg
>
> $ cat st.c
> typedef struct foo foo;
> typedef struct foo foo;
> $ gcc -Wall -o st st.c
> st.c:3:20: error: redefinition of typedef ‘foo’
> st.c:2:20: note: previous declaration of ‘foo’ was here
Apparently "scope" there means something a bit different. Try this
program to see it definitely works (and also swap the order of the
include and the typedef):
----------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>
typedef struct _virDomain virDomain;
typedef virDomain *virDomainPtr;
int main () { printf ("hello\n"); exit (0); }
----------------------------------------------------------------------
gcc -Wall -o test test.c
It doesn't need the #ifndef as suggested by that link.
> Then perhaps the integration glue should be a separate library,
> so libguestfs.so provides the core infrastructure, and then a
> libguest-libvirt.so provides higher level libvirt integration.
> This way people who don't want it can avoid any dep, but apps
> that do want libvirt can use the extra library and guarentee
> they'll have the functionality there, avoiding any nasty runtime
> surprises from libvirt being missing.
For a single function using virDomainPtr, this is all quite a lot more
complicated ...
It should be possible to check availability through the
guestfs_available API, although I didn't implement that yet (see XXX
comments in the patches).
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
More information about the Libguestfs
mailing list