mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Refactor LXC NIC creation to allow reuse by hotplug code
The code for creating veth/macvlan devices is part of the LXC process startup code. Refactor this a little and export the methods to the rest of the LXC driver. This allows them to be reused for NIC hotplug code Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
aae0fc2a92
commit
e89c68b8bb
@ -297,14 +297,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
|
char *virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
|
||||||
virDomainDefPtr vm,
|
virDomainDefPtr vm,
|
||||||
virDomainNetDefPtr net,
|
virDomainNetDefPtr net,
|
||||||
const char *brname,
|
const char *brname)
|
||||||
unsigned int *nveths,
|
|
||||||
char ***veths)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
char *ret = NULL;
|
||||||
char *parentVeth;
|
char *parentVeth;
|
||||||
char *containerVeth = NULL;
|
char *containerVeth = NULL;
|
||||||
const virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
|
const virNetDevVPortProfilePtr vport = virDomainNetGetActualVirtPortProfile(net);
|
||||||
@ -318,24 +316,17 @@ static int virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
|
|||||||
if (net->ifname == NULL)
|
if (net->ifname == NULL)
|
||||||
net->ifname = parentVeth;
|
net->ifname = parentVeth;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(*veths, (*nveths)+1) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
VIR_FREE(containerVeth);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
(*veths)[(*nveths)] = containerVeth;
|
|
||||||
(*nveths)++;
|
|
||||||
|
|
||||||
if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
|
if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
|
if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
|
||||||
ret = virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac,
|
if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac,
|
||||||
vm->uuid, vport, virDomainNetGetActualVlan(net));
|
vm->uuid, vport, virDomainNetGetActualVlan(net)) < 0)
|
||||||
else
|
|
||||||
ret = virNetDevBridgeAddPort(brname, parentVeth);
|
|
||||||
if (ret < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
if (virNetDevBridgeAddPort(brname, parentVeth) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (virNetDevSetOnline(parentVeth, true) < 0)
|
if (virNetDevSetOnline(parentVeth, true) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -353,20 +344,18 @@ static int virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
|
|||||||
virDomainConfNWFilterInstantiate(conn, vm->uuid, net) < 0)
|
virDomainConfNWFilterInstantiate(conn, vm->uuid, net) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = containerVeth;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
virDomainNetDefPtr net,
|
virDomainNetDefPtr net)
|
||||||
unsigned int *nveths,
|
|
||||||
char ***veths)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
char *ret = NULL;
|
||||||
char *res_ifname = NULL;
|
char *res_ifname = NULL;
|
||||||
virLXCDriverPtr driver = conn->privateData;
|
virLXCDriverPtr driver = conn->privateData;
|
||||||
virNetDevBandwidthPtr bw;
|
virNetDevBandwidthPtr bw;
|
||||||
@ -381,7 +370,7 @@ static int virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
|||||||
if (bw) {
|
if (bw) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Unable to set network bandwidth on direct interfaces"));
|
_("Unable to set network bandwidth on direct interfaces"));
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX how todo port profiles ?
|
/* XXX how todo port profiles ?
|
||||||
@ -395,15 +384,9 @@ static int virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
|||||||
if (prof) {
|
if (prof) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Unable to set port profile on direct interfaces"));
|
_("Unable to set port profile on direct interfaces"));
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(*veths, (*nveths)+1) < 0) {
|
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
(*veths)[(*nveths)] = NULL;
|
|
||||||
|
|
||||||
if (virNetDevMacVLanCreateWithVPortProfile(
|
if (virNetDevMacVLanCreateWithVPortProfile(
|
||||||
net->ifname, &net->mac,
|
net->ifname, &net->mac,
|
||||||
virDomainNetGetActualDirectDev(net),
|
virDomainNetGetActualDirectDev(net),
|
||||||
@ -416,10 +399,7 @@ static int virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
|||||||
virDomainNetGetActualBandwidth(net)) < 0)
|
virDomainNetGetActualBandwidth(net)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
(*veths)[(*nveths)] = res_ifname;
|
ret = res_ifname;
|
||||||
(*nveths)++;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
@ -441,13 +421,14 @@ cleanup:
|
|||||||
*/
|
*/
|
||||||
static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
unsigned int *nveths,
|
size_t *nveths,
|
||||||
char ***veths)
|
char ***veths)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0 ; i < def->nnets ; i++) {
|
for (i = 0 ; i < def->nnets ; i++) {
|
||||||
|
char *veth = NULL;
|
||||||
/* If appropriate, grab a physical device from the configured
|
/* If appropriate, grab a physical device from the configured
|
||||||
* network's pool of devices, or resolve bridge device name
|
* network's pool of devices, or resolve bridge device name
|
||||||
* to the one defined in the network definition.
|
* to the one defined in the network definition.
|
||||||
@ -455,6 +436,11 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
|||||||
if (networkAllocateActualDevice(def->nets[i]) < 0)
|
if (networkAllocateActualDevice(def->nets[i]) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (VIR_EXPAND_N(*veths, *nveths, 1) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
switch (virDomainNetGetActualType(def->nets[i])) {
|
switch (virDomainNetGetActualType(def->nets[i])) {
|
||||||
case VIR_DOMAIN_NET_TYPE_NETWORK: {
|
case VIR_DOMAIN_NET_TYPE_NETWORK: {
|
||||||
virNetworkPtr network;
|
virNetworkPtr network;
|
||||||
@ -491,12 +477,10 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
|||||||
if (fail)
|
if (fail)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCProcessSetupInterfaceBridged(conn,
|
if (!(veth = virLXCProcessSetupInterfaceBridged(conn,
|
||||||
def,
|
def,
|
||||||
def->nets[i],
|
def->nets[i],
|
||||||
brname,
|
brname))) {
|
||||||
nveths,
|
|
||||||
veths) < 0) {
|
|
||||||
VIR_FREE(brname);
|
VIR_FREE(brname);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -510,21 +494,17 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
|||||||
_("No bridge name specified"));
|
_("No bridge name specified"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (virLXCProcessSetupInterfaceBridged(conn,
|
if (!(veth = virLXCProcessSetupInterfaceBridged(conn,
|
||||||
def,
|
def,
|
||||||
def->nets[i],
|
def->nets[i],
|
||||||
brname,
|
brname)))
|
||||||
nveths,
|
|
||||||
veths) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
||||||
if (virLXCProcessSetupInterfaceDirect(conn,
|
if (!(veth = virLXCProcessSetupInterfaceDirect(conn,
|
||||||
def,
|
def,
|
||||||
def->nets[i],
|
def->nets[i])))
|
||||||
nveths,
|
|
||||||
veths) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -542,6 +522,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
|
|||||||
));
|
));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(*veths)[(*nveths)-1] = veth;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -923,7 +905,7 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
size_t i;
|
size_t i;
|
||||||
char *logfile = NULL;
|
char *logfile = NULL;
|
||||||
int logfd = -1;
|
int logfd = -1;
|
||||||
unsigned int nveths = 0;
|
size_t nveths = 0;
|
||||||
char **veths = NULL;
|
char **veths = NULL;
|
||||||
int handshakefds[2] = { -1, -1 };
|
int handshakefds[2] = { -1, -1 };
|
||||||
off_t pos = -1;
|
off_t pos = -1;
|
||||||
|
@ -47,4 +47,12 @@ void virLXCProcessAutostartAll(virLXCDriverPtr driver);
|
|||||||
int virLXCProcessReconnectAll(virLXCDriverPtr driver,
|
int virLXCProcessReconnectAll(virLXCDriverPtr driver,
|
||||||
virDomainObjListPtr doms);
|
virDomainObjListPtr doms);
|
||||||
|
|
||||||
|
char *virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
|
||||||
|
virDomainDefPtr vm,
|
||||||
|
virDomainNetDefPtr net,
|
||||||
|
const char *brname);
|
||||||
|
char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
|
||||||
|
virDomainDefPtr def,
|
||||||
|
virDomainNetDefPtr net);
|
||||||
|
|
||||||
#endif /* __LXC_PROCESS_H__ */
|
#endif /* __LXC_PROCESS_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user