[Libguestfs] [PATCH 2/2] launch: libvirt: Use qemu-bridge-helper to implement a full network (RHBZ#1148012).

Richard W.M. Jones rjones at redhat.com
Tue Sep 30 15:44:05 UTC 2014


When using the libvirt backend, don't use the SLIRP.  Use
qemu-bridge-helper via libvirt to give us a full network connection.
One consequence of this is that 'ping' works in virt-builder
--run-command.

Note unfortunately this does not fix virt-rescue (since it overrides
the default backend and uses 'direct' for various reasons).
---
 src/launch-libvirt.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 706ae38..50c3f9d 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -1236,6 +1236,19 @@ construct_libvirt_xml_devices (guestfs_h *g,
       } end_element ();
     } end_element ();
 
+    /* Connect to libvirt bridge virbr0 (see: RHBZ#1148012). */
+    if (g->enable_network) {
+      start_element ("interface") {
+        attribute ("type", "bridge");
+        start_element ("source") {
+          attribute ("bridge", "virbr0");
+        } end_element ();
+        start_element ("model") {
+          attribute ("type", "virtio");
+        } end_element ();
+      } end_element ();
+    }
+
   } end_element (); /* </devices> */
 
   return 0;
@@ -1617,27 +1630,6 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
       attribute ("value", tmpdir);
     } end_element ();
 
-    /* Workaround because libvirt user networking cannot specify "net="
-     * parameter.
-     */
-    if (g->enable_network) {
-      start_element ("qemu:arg") {
-        attribute ("value", "-netdev");
-      } end_element ();
-
-      start_element ("qemu:arg") {
-        attribute ("value", "user,id=usernet,net=169.254.0.0/16");
-      } end_element ();
-
-      start_element ("qemu:arg") {
-        attribute ("value", "-device");
-      } end_element ();
-
-      start_element ("qemu:arg") {
-        attribute ("value", VIRTIO_NET ",netdev=usernet");
-      } end_element ();
-    }
-
     /* The qemu command line arguments requested by the caller. */
     for (hp = g->hv_params; hp; hp = hp->next) {
       start_element ("qemu:arg") {
-- 
2.0.4




More information about the Libguestfs mailing list