[PATCH 2/5] hypervisor: Introduce and use virDomainInterfaceVportRemove()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Both LXC and QEMU drivers have the same code to remove vport when
removing a domain's interface. Instead of repeating the same
pattern in both drivers, move the code into hypervisor agnostic
location (src/hypervisor/) and switch to calling this new
function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/hypervisor/domain_interface.c | 38 ++++++++++++++++++++++---------
 src/hypervisor/domain_interface.h |  1 +
 src/libvirt_private.syms          |  1 +
 src/lxc/lxc_driver.c              |  9 +++-----
 src/lxc/lxc_process.c             | 18 +++++----------
 src/qemu/qemu_hotplug.c           | 22 ++----------------
 6 files changed, 40 insertions(+), 49 deletions(-)

diff --git a/src/hypervisor/domain_interface.c b/src/hypervisor/domain_interface.c
index 853814fe78..0003412065 100644
--- a/src/hypervisor/domain_interface.c
+++ b/src/hypervisor/domain_interface.c
@@ -374,6 +374,32 @@ virDomainInterfaceStopDevices(virDomainDef *def)
     return 0;
 }
 
+
+/**
+ * virDomainInterfaceVportRemove:
+ * @net: a net definition in the VM
+ *
+ * Removes vport profile from corresponding bridge.
+ * NOP if no vport profile is present in @net.
+ */
+void
+virDomainInterfaceVportRemove(virDomainNetDef *net)
+{
+    const virNetDevVPortProfile *vport = virDomainNetGetActualVirtPortProfile(net);
+    const char *brname;
+
+    if (!vport)
+        return;
+
+    if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) {
+        ignore_value(virNetDevMidonetUnbindPort(vport));
+    } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+        brname = virDomainNetGetActualBridgeName(net);
+        ignore_value(virNetDevOpenvswitchRemovePort(brname, net->ifname));
+    }
+}
+
+
 /**
  * virDomainInterfaceDeleteDevice:
  * @def: domain definition
@@ -390,10 +416,8 @@ virDomainInterfaceDeleteDevice(virDomainDef *def,
                                bool priv_net_created,
                                char *stateDir)
 {
-    const virNetDevVPortProfile *vport = NULL;
     g_autoptr(virConnect) conn = NULL;
 
-    vport = virDomainNetGetActualVirtPortProfile(net);
     switch (virDomainNetGetActualType(net)) {
     case VIR_DOMAIN_NET_TYPE_DIRECT:
         if (priv_net_created) {
@@ -435,15 +459,7 @@ virDomainInterfaceDeleteDevice(virDomainDef *def,
     /* release the physical device (or any other resources used by
         * this interface in the network driver
         */
-    if (vport) {
-        if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) {
-            ignore_value(virNetDevMidonetUnbindPort(vport));
-        } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
-            ignore_value(virNetDevOpenvswitchRemovePort(
-                                virDomainNetGetActualBridgeName(net),
-                                net->ifname));
-        }
-    }
+    virDomainInterfaceVportRemove(net);
 
     /* kick the device out of the hostdev list too */
     virDomainNetRemoveHostdev(def, net);
diff --git a/src/hypervisor/domain_interface.h b/src/hypervisor/domain_interface.h
index 3d15e000cc..8047fdadfa 100644
--- a/src/hypervisor/domain_interface.h
+++ b/src/hypervisor/domain_interface.h
@@ -39,6 +39,7 @@ int virDomainInterfaceStartDevice(virDomainNetDef *net);
 int virDomainInterfaceStartDevices(virDomainDef *def);
 int virDomainInterfaceStopDevice(virDomainNetDef *net);
 int virDomainInterfaceStopDevices(virDomainDef *def);
+void virDomainInterfaceVportRemove(virDomainNetDef *net);
 void virDomainInterfaceDeleteDevice(virDomainDef *def,
                                 virDomainNetDef *net,
                                 bool priv_net_created,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 84e30b711c..8642305a8b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1642,6 +1642,7 @@ virDomainInterfaceStartDevice;
 virDomainInterfaceStartDevices;
 virDomainInterfaceStopDevice;
 virDomainInterfaceStopDevices;
+virDomainInterfaceVportRemove;
 
 
 # hypervisor/virclosecallbacks.h
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 39992bdf96..89ef9416aa 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -70,6 +70,7 @@
 #include "virhostdev.h"
 #include "netdev_bandwidth_conf.h"
 #include "virutil.h"
+#include "domain_interface.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -4042,7 +4043,6 @@ lxcDomainDetachDeviceNetLive(virDomainObj *vm,
     int detachidx, ret = -1;
     virDomainNetType actualType;
     virDomainNetDef *detach = NULL;
-    const virNetDevVPortProfile *vport = NULL;
     virErrorPtr save_err = NULL;
 
     if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
@@ -4098,11 +4098,8 @@ lxcDomainDetachDeviceNetLive(virDomainObj *vm,
 
     virDomainConfNWFilterTeardown(detach);
 
-    vport = virDomainNetGetActualVirtPortProfile(detach);
-    if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
-        ignore_value(virNetDevOpenvswitchRemovePort(
-                        virDomainNetGetActualBridgeName(detach),
-                        detach->ifname));
+    virDomainInterfaceVportRemove(detach);
+
     ret = 0;
  cleanup:
     if (!ret) {
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index bfdcefd01b..30ff4eb3d0 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -49,6 +49,7 @@
 #include "virprocess.h"
 #include "netdev_bandwidth_conf.h"
 #include "virutil.h"
+#include "domain_interface.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -149,7 +150,6 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
 {
     size_t i;
     virLXCDomainObjPrivate *priv = vm->privateData;
-    const virNetDevVPortProfile *vport = NULL;
     g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
     g_autoptr(virConnect) conn = NULL;
 
@@ -210,13 +210,9 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
 
     for (i = 0; i < vm->def->nnets; i++) {
         virDomainNetDef *iface = vm->def->nets[i];
-        vport = virDomainNetGetActualVirtPortProfile(iface);
+
         if (iface->ifname) {
-            if (vport &&
-                vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
-                ignore_value(virNetDevOpenvswitchRemovePort(
-                                virDomainNetGetActualBridgeName(iface),
-                                iface->ifname));
+            virDomainInterfaceVportRemove(iface);
             ignore_value(virNetDevVethDelete(iface->ifname));
         }
         if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -637,11 +633,9 @@ virLXCProcessSetupInterfaces(virLXCDriver *driver,
         virErrorPreserveLast(&save_err);
         for (i = 0; i < def->nnets; i++) {
             virDomainNetDef *iface = def->nets[i];
-            const virNetDevVPortProfile *vport = virDomainNetGetActualVirtPortProfile(iface);
-            if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
-                ignore_value(virNetDevOpenvswitchRemovePort(
-                                virDomainNetGetActualBridgeName(iface),
-                                iface->ifname));
+
+            virDomainInterfaceVportRemove(iface);
+
             if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && netconn)
                 virDomainNetReleaseActualDevice(netconn, iface);
         }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 62dc879ed4..054053729c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1091,24 +1091,6 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriver *driver,
 }
 
 
-static void
-qemuDomainNetDeviceVportRemove(virDomainNetDef *net)
-{
-    const virNetDevVPortProfile *vport = virDomainNetGetActualVirtPortProfile(net);
-    const char *brname;
-
-    if (!vport)
-        return;
-
-    if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_MIDONET) {
-        ignore_value(virNetDevMidonetUnbindPort(vport));
-    } else if (vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
-        brname = virDomainNetGetActualBridgeName(net);
-        ignore_value(virNetDevOpenvswitchRemovePort(brname, net->ifname));
-    }
-}
-
-
 static int
 qemuDomainAttachNetDevice(virQEMUDriver *driver,
                           virDomainObj *vm,
@@ -1414,7 +1396,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
                                                        cfg->stateDir);
             }
 
-            qemuDomainNetDeviceVportRemove(net);
+            virDomainInterfaceVportRemove(net);
         }
 
         if (teardownlabel &&
@@ -4895,7 +4877,7 @@ qemuDomainRemoveNetDevice(virQEMUDriver *driver,
             VIR_WARN("Unable to restore security label on vhostuser char device");
     }
 
-    qemuDomainNetDeviceVportRemove(net);
+    virDomainInterfaceVportRemove(net);
 
     if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
         g_autoptr(virConnect) conn = virGetConnectNetwork();
-- 
2.43.2
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux