mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-07 04:07:17 +00:00
hypervisor: Introduce and use virDomainInterfaceVportRemove()
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@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
767d92f098
commit
f8b5bd855f
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -1642,6 +1642,7 @@ virDomainInterfaceStartDevice;
|
||||
virDomainInterfaceStartDevices;
|
||||
virDomainInterfaceStopDevice;
|
||||
virDomainInterfaceStopDevices;
|
||||
virDomainInterfaceVportRemove;
|
||||
|
||||
|
||||
# hypervisor/virclosecallbacks.h
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user