Richard W.M. Jones
2014-Mar-27 18:47 UTC
[Libguestfs] [PATCH 0/2] launch: libvirt: Use libvirt to set up the user network.
Use libvirt to set up the user network instead of a custom qemu argument. Note this requires a non-upstream patch being discussed on the libvirt mailing list at the moment. https://bugzilla.redhat.com/show_bug.cgi?id=1075520#c6 Rich.
Richard W.M. Jones
2014-Mar-27 18:47 UTC
[Libguestfs] [PATCH 1/2] launch: libvirt: Store libvirt version number in the backend data.
This lets us generate XML conditionally based on libvirt version. --- src/launch-libvirt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index e4563f8..7653bf9 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -100,6 +100,7 @@ xmlBufferDetach (xmlBufferPtr buf) /* Per-handle data. */ struct backend_libvirt_data { + unsigned long version; /* libvirt version */ virConnectPtr conn; /* libvirt connection */ virDomainPtr dom; /* libvirt domain */ char *selinux_label; @@ -208,7 +209,6 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) { struct backend_libvirt_data *data = datav; int daemon_accept_sock = -1, console_sock = -1; - unsigned long version; virConnectPtr conn = NULL; virDomainPtr dom = NULL; CLEANUP_FREE char *capabilities_xml = NULL; @@ -234,11 +234,13 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) return -1; } - virGetVersion (&version, NULL, NULL); + virGetVersion (&data->version, NULL, NULL); debug (g, "libvirt version = %lu (%lu.%lu.%lu)", - version, - version / 1000000UL, version / 1000UL % 1000UL, version % 1000UL); - if (version < MIN_LIBVIRT_VERSION) { + data->version, + data->version / 1000000UL, + data->version / 1000UL % 1000UL, + data->version % 1000UL); + if (data->version < MIN_LIBVIRT_VERSION) { error (g, _("you must have libvirt >= %d.%d.%d " "to use the 'libvirt' backend"), MIN_LIBVIRT_MAJOR, MIN_LIBVIRT_MINOR, MIN_LIBVIRT_MICRO); -- 1.8.5.3
Richard W.M. Jones
2014-Mar-27 18:47 UTC
[Libguestfs] [PATCH 2/2] launch: libvirt: Use libvirt to set up the user network.
This only works in libvirt >= 1.3.0. See: https://bugzilla.redhat.com/show_bug.cgi?id=1075520 Thanks: Michal Privoznik --- src/launch-libvirt.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index 7653bf9..87ad21a 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -1210,6 +1210,20 @@ construct_libvirt_xml_devices (guestfs_h *g, } end_element (); } end_element (); + /* User network using libvirt >= 1.3.0. */ + if (params->data->version >= 1003000 && g->enable_network) { + start_element ("interface") { + attribute ("type", "user"); + start_element ("ip") { + attribute ("address", "169.254.0.0"); + attribute ("prefix", "16"); + } end_element (); + start_element ("model") { + attribute ("type", VIRTIO_NET); + } end_element (); + } end_element (); + } + } end_element (); /* </devices> */ return 0; @@ -1588,10 +1602,11 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g, attribute ("value", tmpdir); } end_element (); - /* Workaround because libvirt user networking cannot specify "net=" - * parameter. + /* Workaround because libvirt user networking cannot specify + * "net=" parameter. We can remove this when the min required + * libvirt version is >= 1.3.0. */ - if (g->enable_network) { + if (params->data->version < 1003000 && g->enable_network) { start_element ("qemu:arg") { attribute ("value", "-netdev"); } end_element (); -- 1.8.5.3
Daniel P. Berrange
2014-Mar-28 11:04 UTC
Re: [Libguestfs] [PATCH 2/2] launch: libvirt: Use libvirt to set up the user network.
On Thu, Mar 27, 2014 at 06:47:55PM +0000, Richard W.M. Jones wrote:> This only works in libvirt >= 1.3.0. See:The release we're about todo is 1.2.3, and it isn't clear if we'll go to 1.2.4 or 1.3.0 yet - probably the former at this point. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Apparently Analagous Threads
- [PATCH] Revert "launch: libvirt: Use qemu-bridge-helper to implement
- [PATCH 1/2] appliance: Use dhclient instead of hard-coding IP address of appliance.
- [PATCH v2] Revert "launch: libvirt: Use qemu-bridge-helper to implement a full network (RHBZ#1148012)."
- [PATCH v3 0/4] launch: libvirt: Use qemu-bridge-helper to implement a
- [PATCH v2 0/4] launch: libvirt: Use qemu-bridge-helper to implement a full network (RHBZ#1148012).