render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
9119d9
From 0d1763b206f9ff068c26f3b75dfc494117fdd51b Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <0d1763b206f9ff068c26f3b75dfc494117fdd51b@dist-git>
9119d9
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
9119d9
Date: Wed, 17 Sep 2014 19:15:59 +0200
9119d9
Subject: [PATCH] Wire up the interface backend options
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1139362
9119d9
9119d9
Pass the user-specified tun path down when creating tap device
9119d9
when called from the qemu driver.
9119d9
9119d9
Also honor the vhost device path specified by user.
9119d9
9119d9
(cherry picked from commit b20d39a56f36ee41f585864587c97137363acc3e)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/bhyve/bhyve_command.c   |  2 +-
9119d9
 src/bhyve/bhyve_process.c   |  2 +-
9119d9
 src/network/bridge_driver.c |  6 +++---
9119d9
 src/qemu/qemu_command.c     | 22 +++++++++++++++-------
9119d9
 src/qemu/qemu_process.c     |  2 +-
9119d9
 src/uml/uml_conf.c          |  2 +-
9119d9
 src/uml/uml_driver.c        |  3 ++-
9119d9
 src/util/virnetdevtap.c     | 37 +++++++++++++++++++++++++++----------
9119d9
 src/util/virnetdevtap.h     |  5 ++++-
9119d9
 9 files changed, 55 insertions(+), 26 deletions(-)
9119d9
9119d9
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
9119d9
index 94829e7..bea4a59 100644
9119d9
--- a/src/bhyve/bhyve_command.c
9119d9
+++ b/src/bhyve/bhyve_command.c
9119d9
@@ -72,7 +72,7 @@ bhyveBuildNetArgStr(const virDomainDef *def,
9119d9
 
9119d9
     if (!dryRun) {
9119d9
         if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
9119d9
-                                           def->uuid, NULL, 0,
9119d9
+                                           def->uuid, NULL, NULL, 0,
9119d9
                                            virDomainNetGetActualVirtPortProfile(net),
9119d9
                                            virDomainNetGetActualVlan(net),
9119d9
                                            VIR_NETDEV_TAP_CREATE_IFUP | VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
9119d9
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
9119d9
index 6b5403d..0bbe388 100644
9119d9
--- a/src/bhyve/bhyve_process.c
9119d9
+++ b/src/bhyve/bhyve_process.c
9119d9
@@ -82,7 +82,7 @@ bhyveNetCleanup(virDomainObjPtr vm)
9119d9
                 ignore_value(virNetDevBridgeRemovePort(
9119d9
                                 virDomainNetGetActualBridgeName(net),
9119d9
                                 net->ifname));
9119d9
-                ignore_value(virNetDevTapDelete(net->ifname));
9119d9
+                ignore_value(virNetDevTapDelete(net->ifname, NULL));
9119d9
             }
9119d9
         }
9119d9
     }
9119d9
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
9119d9
index 4b3f07f..b77dc76 100644
9119d9
--- a/src/network/bridge_driver.c
9119d9
+++ b/src/network/bridge_driver.c
9119d9
@@ -1991,7 +1991,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
9119d9
         /* Keep tun fd open and interface up to allow for IPv6 DAD to happen */
9119d9
         if (virNetDevTapCreateInBridgePort(network->def->bridge,
9119d9
                                            &macTapIfName, &network->def->mac,
9119d9
-                                           NULL, &tapfd, 1, NULL, NULL,
9119d9
+                                           NULL, NULL, &tapfd, 1, NULL, NULL,
9119d9
                                            VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE |
9119d9
                                            VIR_NETDEV_TAP_CREATE_IFUP |
9119d9
                                            VIR_NETDEV_TAP_CREATE_PERSIST) < 0) {
9119d9
@@ -2117,7 +2117,7 @@ networkStartNetworkVirtual(virNetworkDriverStatePtr driver,
9119d9
 
9119d9
     if (macTapIfName) {
9119d9
         VIR_FORCE_CLOSE(tapfd);
9119d9
-        ignore_value(virNetDevTapDelete(macTapIfName));
9119d9
+        ignore_value(virNetDevTapDelete(macTapIfName, NULL));
9119d9
         VIR_FREE(macTapIfName);
9119d9
     }
9119d9
 
9119d9
@@ -2156,7 +2156,7 @@ static int networkShutdownNetworkVirtual(virNetworkDriverStatePtr driver ATTRIBU
9119d9
     if (network->def->mac_specified) {
9119d9
         char *macTapIfName = networkBridgeDummyNicName(network->def->bridge);
9119d9
         if (macTapIfName) {
9119d9
-            ignore_value(virNetDevTapDelete(macTapIfName));
9119d9
+            ignore_value(virNetDevTapDelete(macTapIfName, NULL));
9119d9
             VIR_FREE(macTapIfName);
9119d9
         }
9119d9
     }
9119d9
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
9119d9
index ce5daae..81395a8 100644
9119d9
--- a/src/qemu/qemu_command.c
9119d9
+++ b/src/qemu/qemu_command.c
9119d9
@@ -288,6 +288,10 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
9119d9
     bool template_ifname = false;
9119d9
     int actualType = virDomainNetGetActualType(net);
9119d9
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
9119d9
+    const char *tunpath = "/dev/net/tun";
9119d9
+
9119d9
+    if (net->backend.tap)
9119d9
+        tunpath = net->backend.tap;
9119d9
 
9119d9
     if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
9119d9
         bool fail = false;
9119d9
@@ -336,18 +340,18 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
9119d9
 
9119d9
     if (cfg->privileged) {
9119d9
         if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
9119d9
-                                           def->uuid, tapfd, *tapfdSize,
9119d9
+                                           def->uuid, tunpath, tapfd, *tapfdSize,
9119d9
                                            virDomainNetGetActualVirtPortProfile(net),
9119d9
                                            virDomainNetGetActualVlan(net),
9119d9
                                            tap_create_flags) < 0) {
9119d9
-            virDomainAuditNetDevice(def, net, "/dev/net/tun", false);
9119d9
+            virDomainAuditNetDevice(def, net, tunpath, false);
9119d9
             goto cleanup;
9119d9
         }
9119d9
     } else {
9119d9
         if (qemuCreateInBridgePortWithHelper(cfg, brname,
9119d9
                                              &net->ifname,
9119d9
                                              tapfd, tap_create_flags) < 0) {
9119d9
-            virDomainAuditNetDevice(def, net, "/dev/net/tun", false);
9119d9
+            virDomainAuditNetDevice(def, net, tunpath, false);
9119d9
             goto cleanup;
9119d9
         }
9119d9
         /* qemuCreateInBridgePortWithHelper can only create a single FD */
9119d9
@@ -357,7 +361,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
9119d9
         }
9119d9
     }
9119d9
 
9119d9
-    virDomainAuditNetDevice(def, net, "/dev/net/tun", true);
9119d9
+    virDomainAuditNetDevice(def, net, tunpath, true);
9119d9
 
9119d9
     if (cfg->macFilter &&
9119d9
         ebtablesAddForwardAllowIn(driver->ebtables,
9119d9
@@ -441,6 +445,10 @@ qemuOpenVhostNet(virDomainDefPtr def,
9119d9
                  int *vhostfdSize)
9119d9
 {
9119d9
     size_t i;
9119d9
+    const char *vhostnet_path = net->backend.vhost;
9119d9
+
9119d9
+    if (!vhostnet_path)
9119d9
+        vhostnet_path = "/dev/vhost-net";
9119d9
 
9119d9
     /* If running a plain QEMU guest, or
9119d9
      * if the config says explicitly to not use vhost, return now*/
9119d9
@@ -478,13 +486,13 @@ qemuOpenVhostNet(virDomainDefPtr def,
9119d9
     }
9119d9
 
9119d9
     for (i = 0; i < *vhostfdSize; i++) {
9119d9
-        vhostfd[i] = open("/dev/vhost-net", O_RDWR);
9119d9
+        vhostfd[i] = open(vhostnet_path, O_RDWR);
9119d9
 
9119d9
         /* If the config says explicitly to use vhost and we couldn't open it,
9119d9
          * report an error.
9119d9
          */
9119d9
         if (vhostfd[i] < 0) {
9119d9
-            virDomainAuditNetDevice(def, net, "/dev/vhost-net", false);
9119d9
+            virDomainAuditNetDevice(def, net, vhostnet_path, false);
9119d9
             if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
9119d9
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
9119d9
                                "%s", _("vhost-net was requested for an interface, "
9119d9
@@ -497,7 +505,7 @@ qemuOpenVhostNet(virDomainDefPtr def,
9119d9
             break;
9119d9
         }
9119d9
     }
9119d9
-    virDomainAuditNetDevice(def, net, "/dev/vhost-net", *vhostfdSize);
9119d9
+    virDomainAuditNetDevice(def, net, vhostnet_path, *vhostfdSize);
9119d9
     return 0;
9119d9
 
9119d9
  error:
9119d9
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
9119d9
index d7f6bdf..bf1f0de 100644
9119d9
--- a/src/qemu/qemu_process.c
9119d9
+++ b/src/qemu/qemu_process.c
9119d9
@@ -4764,7 +4764,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
9119d9
         case VIR_DOMAIN_NET_TYPE_NETWORK:
9119d9
 #ifdef VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP
9119d9
             if (!(vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH))
9119d9
-                ignore_value(virNetDevTapDelete(net->ifname));
9119d9
+                ignore_value(virNetDevTapDelete(net->ifname, net->backend.tap));
9119d9
 #endif
9119d9
             break;
9119d9
         }
9119d9
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
9119d9
index 41ce03c..a99e8e9 100644
9119d9
--- a/src/uml/uml_conf.c
9119d9
+++ b/src/uml/uml_conf.c
9119d9
@@ -124,7 +124,7 @@ umlConnectTapDevice(virConnectPtr conn,
9119d9
     }
9119d9
 
9119d9
     if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, &net->mac,
9119d9
-                                       vm->uuid, &tapfd, 1,
9119d9
+                                       vm->uuid, net->backend.tap, &tapfd, 1,
9119d9
                                        virDomainNetGetActualVirtPortProfile(net),
9119d9
                                        virDomainNetGetActualVlan(net),
9119d9
                                        VIR_NETDEV_TAP_CREATE_IFUP |
9119d9
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
9119d9
index 7039afc..f9712e8 100644
9119d9
--- a/src/uml/uml_driver.c
9119d9
+++ b/src/uml/uml_driver.c
9119d9
@@ -1032,7 +1032,8 @@ static void umlCleanupTapDevices(virDomainObjPtr vm)
9119d9
             def->type != VIR_DOMAIN_NET_TYPE_NETWORK)
9119d9
             continue;
9119d9
 
9119d9
-        ignore_value(virNetDevTapDelete(def->ifname));
9119d9
+        ignore_value(virNetDevTapDelete(def->ifname,
9119d9
+                                        def->backend.tap));
9119d9
     }
9119d9
 }
9119d9
 
9119d9
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
9119d9
index d64e64f..3674f9b 100644
9119d9
--- a/src/util/virnetdevtap.c
9119d9
+++ b/src/util/virnetdevtap.c
9119d9
@@ -216,6 +216,7 @@ virNetDevProbeVnetHdr(int tapfd)
9119d9
 /**
9119d9
  * virNetDevTapCreate:
9119d9
  * @ifname: the interface name
9119d9
+ * @tunpath: path to the tun device (if NULL, /dev/net/tun is used)
9119d9
  * @tapfds: array of file descriptors return value for the new tap device
9119d9
  * @tapfdSize: number of file descriptors in @tapfd
9119d9
  * @flags: OR of virNetDevTapCreateFlags. Only one flag is recognized:
9119d9
@@ -233,6 +234,7 @@ virNetDevProbeVnetHdr(int tapfd)
9119d9
  * Returns 0 in case of success or -1 on failure.
9119d9
  */
9119d9
 int virNetDevTapCreate(char **ifname,
9119d9
+                       const char *tunpath,
9119d9
                        int *tapfd,
9119d9
                        int tapfdSize,
9119d9
                        unsigned int flags)
9119d9
@@ -242,11 +244,15 @@ int virNetDevTapCreate(char **ifname,
9119d9
     int ret = -1;
9119d9
     int fd;
9119d9
 
9119d9
+    if (!tunpath)
9119d9
+        tunpath = "/dev/net/tun";
9119d9
+
9119d9
     memset(&ifr, 0, sizeof(ifr));
9119d9
     for (i = 0; i < tapfdSize; i++) {
9119d9
-        if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
9119d9
-            virReportSystemError(errno, "%s",
9119d9
-                                 _("Unable to open /dev/net/tun, is tun module loaded?"));
9119d9
+        if ((fd = open(tunpath, O_RDWR)) < 0) {
9119d9
+            virReportSystemError(errno,
9119d9
+                                 _("Unable to open %s, is tun module loaded?"),
9119d9
+                                 tunpath);
9119d9
             goto cleanup;
9119d9
         }
9119d9
 
9119d9
@@ -316,15 +322,20 @@ int virNetDevTapCreate(char **ifname,
9119d9
 }
9119d9
 
9119d9
 
9119d9
-int virNetDevTapDelete(const char *ifname)
9119d9
+int virNetDevTapDelete(const char *ifname,
9119d9
+                       const char *tunpath)
9119d9
 {
9119d9
     struct ifreq try;
9119d9
     int fd;
9119d9
     int ret = -1;
9119d9
 
9119d9
-    if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
9119d9
-        virReportSystemError(errno, "%s",
9119d9
-                             _("Unable to open /dev/net/tun, is tun module loaded?"));
9119d9
+    if (!tunpath)
9119d9
+        tunpath = "/dev/net/tun";
9119d9
+
9119d9
+    if ((fd = open(tunpath, O_RDWR)) < 0) {
9119d9
+        virReportSystemError(errno,
9119d9
+                             _("Unable to open %s, is tun module loaded?"),
9119d9
+                             tunpath);
9119d9
         return -1;
9119d9
     }
9119d9
 
9119d9
@@ -358,6 +369,7 @@ int virNetDevTapDelete(const char *ifname)
9119d9
 }
9119d9
 #elif defined(SIOCIFCREATE2) && defined(SIOCIFDESTROY) && defined(IF_MAXUNIT)
9119d9
 int virNetDevTapCreate(char **ifname,
9119d9
+                       const char *tunpath ATTRIBUTE_UNUSED,
9119d9
                        int *tapfd,
9119d9
                        int tapfdSize,
9119d9
                        unsigned int flags ATTRIBUTE_UNUSED)
9119d9
@@ -444,7 +456,8 @@ int virNetDevTapCreate(char **ifname,
9119d9
     return ret;
9119d9
 }
9119d9
 
9119d9
-int virNetDevTapDelete(const char *ifname)
9119d9
+int virNetDevTapDelete(const char *ifname,
9119d9
+                       const char *tunpath ATTRIBUTE_UNUSED)
9119d9
 {
9119d9
     int s;
9119d9
     struct ifreq ifr;
9119d9
@@ -468,6 +481,7 @@ int virNetDevTapDelete(const char *ifname)
9119d9
 
9119d9
 #else
9119d9
 int virNetDevTapCreate(char **ifname ATTRIBUTE_UNUSED,
9119d9
+                       const char *tunpath ATTRIBUTE_UNUSED,
9119d9
                        int *tapfd ATTRIBUTE_UNUSED,
9119d9
                        int tapfdSize ATTRIBUTE_UNUSED,
9119d9
                        unsigned int flags ATTRIBUTE_UNUSED)
9119d9
@@ -476,7 +490,8 @@ int virNetDevTapCreate(char **ifname ATTRIBUTE_UNUSED,
9119d9
                          _("Unable to create TAP devices on this platform"));
9119d9
     return -1;
9119d9
 }
9119d9
-int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED)
9119d9
+int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED,
9119d9
+                       const char *tunpath ATTRIBUTE_UNUSED)
9119d9
 {
9119d9
     virReportSystemError(ENOSYS, "%s",
9119d9
                          _("Unable to delete TAP devices on this platform"));
9119d9
@@ -490,6 +505,7 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED)
9119d9
  * @brname: the bridge name
9119d9
  * @ifname: the interface name (or name template)
9119d9
  * @macaddr: desired MAC address
9119d9
+ * @tunpath: path to the tun device (if NULL, /dev/net/tun is used)
9119d9
  * @tapfd: array of file descriptor return value for the new tap device
9119d9
  * @tapfdSize: number of file descriptors in @tapfd
9119d9
  * @virtPortProfile: bridge/port specific configuration
9119d9
@@ -518,6 +534,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
9119d9
                                    char **ifname,
9119d9
                                    const virMacAddr *macaddr,
9119d9
                                    const unsigned char *vmuuid,
9119d9
+                                   const char *tunpath,
9119d9
                                    int *tapfd,
9119d9
                                    int tapfdSize,
9119d9
                                    virNetDevVPortProfilePtr virtPortProfile,
9119d9
@@ -528,7 +545,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
9119d9
     char macaddrstr[VIR_MAC_STRING_BUFLEN];
9119d9
     size_t i;
9119d9
 
9119d9
-    if (virNetDevTapCreate(ifname, tapfd, tapfdSize, flags) < 0)
9119d9
+    if (virNetDevTapCreate(ifname, tunpath, tapfd, tapfdSize, flags) < 0)
9119d9
         return -1;
9119d9
 
9119d9
     /* We need to set the interface MAC before adding it
9119d9
diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h
9119d9
index 03fb5f8..c0a4e15 100644
9119d9
--- a/src/util/virnetdevtap.h
9119d9
+++ b/src/util/virnetdevtap.h
9119d9
@@ -34,12 +34,14 @@
9119d9
 # endif
9119d9
 
9119d9
 int virNetDevTapCreate(char **ifname,
9119d9
+                       const char *tunpath,
9119d9
                        int *tapfd,
9119d9
                        int tapfdSize,
9119d9
                        unsigned int flags)
9119d9
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
9119d9
 
9119d9
-int virNetDevTapDelete(const char *ifname)
9119d9
+int virNetDevTapDelete(const char *ifname,
9119d9
+                       const char *tunpath)
9119d9
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
9119d9
 
9119d9
 int virNetDevTapGetName(int tapfd, char **ifname)
9119d9
@@ -64,6 +66,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
9119d9
                                    char **ifname,
9119d9
                                    const virMacAddr *macaddr,
9119d9
                                    const unsigned char *vmuuid,
9119d9
+                                   const char *tunpath,
9119d9
                                    int *tapfd,
9119d9
                                    int tapfdSize,
9119d9
                                    virNetDevVPortProfilePtr virtPortProfile,
9119d9
-- 
9119d9
2.1.0
9119d9