mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0059-Revert-launch-libvirt-Use-qemu-bridge-helper-to-impl.patch

d0ea73
From 66a40516a2696b7528803d7637c022659fa8c46e Mon Sep 17 00:00:00 2001
d0ea73
From: "Richard W.M. Jones" <rjones@redhat.com>
d0ea73
Date: Thu, 2 Oct 2014 16:44:07 +0100
d0ea73
Subject: [PATCH] Revert "launch: libvirt: Use qemu-bridge-helper to implement
d0ea73
 a full network (RHBZ#1148012)."
d0ea73
d0ea73
We've been carrying this exact patch in RHEL 7 for several years.  It
d0ea73
reverts the change made in 2014 where we switched to using the virbr0
d0ea73
bridge for libguestfs networking instead of SLIRP.  We thought SLIRP
d0ea73
was going to become unsupported in qemu, but recently there have been
d0ea73
more encouraging signs since it looks like SLIRP will be spun off as a
d0ea73
separate project, running as a modular process and properly secured
d0ea73
and supported.
d0ea73
d0ea73
This reverts commit 224de20b9a8d5ea56f6337f19b4ca237bb88eca0.
d0ea73
d0ea73
(cherry picked from commit 492a945791b43f80a769a53e60d0899b3d7c60ab)
d0ea73
---
d0ea73
 lib/guestfs-internal.h | 11 +++++
d0ea73
 lib/guestfs.pod        | 10 -----
d0ea73
 lib/launch-direct.c    | 11 -----
d0ea73
 lib/launch-libvirt.c   | 91 ++++++++++--------------------------------
d0ea73
 4 files changed, 32 insertions(+), 91 deletions(-)
d0ea73
d0ea73
diff --git a/lib/guestfs-internal.h b/lib/guestfs-internal.h
d0ea73
index adeb9478a..fe3a0e3b9 100644
d0ea73
--- a/lib/guestfs-internal.h
d0ea73
+++ b/lib/guestfs-internal.h
d0ea73
@@ -147,6 +147,17 @@
d0ea73
 #define MACHINE_TYPE "pseries"
d0ea73
 #endif
d0ea73
 
d0ea73
+/* Differences in qemu device names on ARMv7 (virtio-mmio), s/390x
d0ea73
+ * (CCW) vs normal hardware with PCI.
d0ea73
+ */
d0ea73
+#if defined(__arm__)
d0ea73
+#define VIRTIO_DEVICE_NAME(type) type "-device"
d0ea73
+#elif defined(__s390x__)
d0ea73
+#define VIRTIO_DEVICE_NAME(type) type "-ccw"
d0ea73
+#else
d0ea73
+#define VIRTIO_DEVICE_NAME(type) type "-pci"
d0ea73
+#endif
d0ea73
+
d0ea73
 /* Guestfs handle and associated structures. */
d0ea73
 
d0ea73
 /* State. */
d0ea73
diff --git a/lib/guestfs.pod b/lib/guestfs.pod
d0ea73
index 4b24006df..c7fbeef03 100644
d0ea73
--- a/lib/guestfs.pod
d0ea73
+++ b/lib/guestfs.pod
d0ea73
@@ -1551,16 +1551,6 @@ On Fedora, install C<kernel-debuginfo> for the C<vmlinux> file
d0ea73
 (containing symbols).  Make sure the symbols precisely match the
d0ea73
 kernel being used.
d0ea73
 
d0ea73
-=head3 network_bridge
d0ea73
-
d0ea73
-The libvirt backend supports:
d0ea73
-
d0ea73
- export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=virbrX
d0ea73
-
d0ea73
-This allows you to override the bridge that is connected to when the
d0ea73
-network is enabled.  The default is C<virbr0>.  See also
d0ea73
-L</guestfs_set_network>.
d0ea73
-
d0ea73
 =head2 ATTACHING TO RUNNING DAEMONS
d0ea73
 
d0ea73
 I<Note (1):> This is B<highly experimental> and has a tendency to eat
d0ea73
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
d0ea73
index 47e8f37de..f6c494d69 100644
d0ea73
--- a/lib/launch-direct.c
d0ea73
+++ b/lib/launch-direct.c
d0ea73
@@ -49,17 +49,6 @@
d0ea73
 #include "guestfs_protocol.h"
d0ea73
 #include "qemuopts.h"
d0ea73
 
d0ea73
-/* Differences in qemu device names on ARMv7 (virtio-mmio), s/390x
d0ea73
- * (CCW) vs normal hardware with PCI.
d0ea73
- */
d0ea73
-#if defined(__arm__)
d0ea73
-#define VIRTIO_DEVICE_NAME(type) type "-device"
d0ea73
-#elif defined(__s390x__)
d0ea73
-#define VIRTIO_DEVICE_NAME(type) type "-ccw"
d0ea73
-#else
d0ea73
-#define VIRTIO_DEVICE_NAME(type) type "-pci"
d0ea73
-#endif
d0ea73
-
d0ea73
 /* Per-handle data. */
d0ea73
 struct backend_direct_data {
d0ea73
   pid_t pid;                    /* Qemu PID. */
d0ea73
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
d0ea73
index 7121aee1b..4df26825a 100644
d0ea73
--- a/lib/launch-libvirt.c
d0ea73
+++ b/lib/launch-libvirt.c
d0ea73
@@ -116,7 +116,6 @@ struct backend_libvirt_data {
d0ea73
   char *selinux_label;
d0ea73
   char *selinux_imagelabel;
d0ea73
   bool selinux_norelabel_disks;
d0ea73
-  char *network_bridge;
d0ea73
   char name[DOMAIN_NAME_LEN];   /* random name */
d0ea73
   bool is_kvm;                  /* false = qemu, true = kvm (from capabilities)*/
d0ea73
   struct version libvirt_version; /* libvirt version */
d0ea73
@@ -157,7 +156,6 @@ static int is_blk (const char *path);
d0ea73
 static void ignore_errors (void *ignore, virErrorPtr ignore2);
d0ea73
 static void set_socket_create_context (guestfs_h *g);
d0ea73
 static void clear_socket_create_context (guestfs_h *g);
d0ea73
-static int check_bridge_exists (guestfs_h *g, const char *brname);
d0ea73
 
d0ea73
 #if HAVE_LIBSELINUX
d0ea73
 static void selinux_warning (guestfs_h *g, const char *func, const char *selinux_op, const char *data);
d0ea73
@@ -438,17 +436,8 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
d0ea73
     guestfs_get_backend_setting (g, "internal_libvirt_imagelabel");
d0ea73
   data->selinux_norelabel_disks =
d0ea73
     guestfs_int_get_backend_setting_bool (g, "internal_libvirt_norelabel_disks");
d0ea73
-  if (g->enable_network) {
d0ea73
-    data->network_bridge =
d0ea73
-      guestfs_get_backend_setting (g, "network_bridge");
d0ea73
-    if (!data->network_bridge)
d0ea73
-      data->network_bridge = safe_strdup (g, "virbr0");
d0ea73
-  }
d0ea73
   guestfs_pop_error_handler (g);
d0ea73
 
d0ea73
-  if (g->enable_network && check_bridge_exists (g, data->network_bridge) == -1)
d0ea73
-    goto cleanup;
d0ea73
-
d0ea73
   /* Locate and/or build the appliance. */
d0ea73
   TRACE0 (launch_build_libvirt_appliance_start);
d0ea73
 
d0ea73
@@ -1403,19 +1392,6 @@ construct_libvirt_xml_devices (guestfs_h *g,
d0ea73
       } end_element ();
d0ea73
     } end_element ();
d0ea73
 
d0ea73
-    /* Connect to libvirt bridge (see: RHBZ#1148012). */
d0ea73
-    if (g->enable_network) {
d0ea73
-      start_element ("interface") {
d0ea73
-        attribute ("type", "bridge");
d0ea73
-        start_element ("source") {
d0ea73
-          attribute ("bridge", params->data->network_bridge);
d0ea73
-        } end_element ();
d0ea73
-        start_element ("model") {
d0ea73
-          attribute ("type", "virtio");
d0ea73
-        } end_element ();
d0ea73
-      } end_element ();
d0ea73
-    }
d0ea73
-
d0ea73
     /* Libvirt adds some devices by default.  Indicate to libvirt
d0ea73
      * that we don't want them.
d0ea73
      */
d0ea73
@@ -1823,6 +1799,27 @@ construct_libvirt_xml_qemu_cmdline (guestfs_h *g,
d0ea73
       attribute ("value", tmpdir);
d0ea73
     } end_element ();
d0ea73
 
d0ea73
+    /* Workaround because libvirt user networking cannot specify "net="
d0ea73
+     * parameter.
d0ea73
+     */
d0ea73
+    if (g->enable_network) {
d0ea73
+      start_element ("qemu:arg") {
d0ea73
+        attribute ("value", "-netdev");
d0ea73
+      } end_element ();
d0ea73
+
d0ea73
+      start_element ("qemu:arg") {
d0ea73
+        attribute ("value", "user,id=usernet,net=169.254.0.0/16");
d0ea73
+      } end_element ();
d0ea73
+
d0ea73
+      start_element ("qemu:arg") {
d0ea73
+        attribute ("value", "-device");
d0ea73
+      } end_element ();
d0ea73
+
d0ea73
+      start_element ("qemu:arg") {
d0ea73
+        attribute ("value", VIRTIO_DEVICE_NAME ("virtio-net") ",netdev=usernet");
d0ea73
+      } end_element ();
d0ea73
+    }
d0ea73
+
d0ea73
     /* The qemu command line arguments requested by the caller. */
d0ea73
     for (hp = g->hv_params; hp; hp = hp->next) {
d0ea73
       start_element ("qemu:arg") {
d0ea73
@@ -2060,49 +2057,6 @@ is_blk (const char *path)
d0ea73
   return S_ISBLK (statbuf.st_mode);
d0ea73
 }
d0ea73
 
d0ea73
-static int
d0ea73
-is_dir (const char *path)
d0ea73
-{
d0ea73
-  struct stat statbuf;
d0ea73
-
d0ea73
-  if (stat (path, &statbuf) == -1)
d0ea73
-    return 0;
d0ea73
-  return S_ISDIR (statbuf.st_mode);
d0ea73
-}
d0ea73
-
d0ea73
-/* Used to check the network_bridge exists, or give a useful error
d0ea73
- * message.
d0ea73
- */
d0ea73
-static int
d0ea73
-check_bridge_exists (guestfs_h *g, const char *brname)
d0ea73
-{
d0ea73
-  CLEANUP_FREE char *path = NULL;
d0ea73
-
d0ea73
-  /* If this doesn't look like Linux, give up. */
d0ea73
-  if (!is_dir ("/sys/class/net"))
d0ea73
-    return 0;
d0ea73
-
d0ea73
-  /* Does the interface exist and is it a bridge? */
d0ea73
-  path = safe_asprintf (g, "/sys/class/net/%s/bridge", brname);
d0ea73
-  if (is_dir (path))
d0ea73
-    return 0;
d0ea73
-
d0ea73
-  error (g,
d0ea73
-         _("bridge ā€˜%sā€™ not found.  Try running:\n"
d0ea73
-           "\n"
d0ea73
-           "  brctl show\n"
d0ea73
-           "\n"
d0ea73
-           "to get a list of bridges on the host, and then selecting the\n"
d0ea73
-           "bridge you wish the appliance network to connect to using:\n"
d0ea73
-           "\n"
d0ea73
-           "  export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=<bridge name>\n"
d0ea73
-           "\n"
d0ea73
-           "You may also need to allow the bridge in /etc/qemu/bridge.conf.\n"
d0ea73
-           "For further information see guestfs(3)."),
d0ea73
-	 brname);
d0ea73
-  return -1;
d0ea73
-}
d0ea73
-
d0ea73
 static void
d0ea73
 ignore_errors (void *ignore, virErrorPtr ignore2)
d0ea73
 {
d0ea73
@@ -2148,9 +2102,6 @@ shutdown_libvirt (guestfs_h *g, void *datav, int check_for_errors)
d0ea73
   free (data->selinux_imagelabel);
d0ea73
   data->selinux_imagelabel = NULL;
d0ea73
 
d0ea73
-  free (data->network_bridge);
d0ea73
-  data->network_bridge = NULL;
d0ea73
-
d0ea73
   for (i = 0; i < data->nr_secrets; ++i)
d0ea73
     free (data->secrets[i].secret);
d0ea73
   free (data->secrets);
d0ea73
-- 
d0ea73
2.20.1
d0ea73