mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 18:03:32 +00:00
lxc, libxl: notify network driver of NICs during reconnect
When starting up it is important to notify the network driver of any NICs which are used by running guests so that it can account for any resources they are using. Reviewed-by: Laine Stump <laine@laine.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
4a998fb824
commit
729a06c41a
@ -352,6 +352,34 @@ libxlAutostartDomain(virDomainObjPtr vm,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
libxlReconnectNotifyNets(virDomainDefPtr def)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < def->nnets; i++) {
|
||||||
|
virDomainNetDefPtr net = def->nets[i];
|
||||||
|
/* keep others from trying to use the macvtap device name, but
|
||||||
|
* don't return error if this happens, since that causes the
|
||||||
|
* domain to be unceremoniously killed, which would be *very*
|
||||||
|
* impolite.
|
||||||
|
*/
|
||||||
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT)
|
||||||
|
ignore_value(virNetDevMacVLanReserveName(net->ifname, false));
|
||||||
|
|
||||||
|
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||||
|
if (!conn && !(conn = virGetConnectNetwork()))
|
||||||
|
continue;
|
||||||
|
virDomainNetNotifyActualDevice(conn, def, net);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virObjectUnref(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reconnect to running domains that were previously started/created
|
* Reconnect to running domains that were previously started/created
|
||||||
* with libxenlight driver.
|
* with libxenlight driver.
|
||||||
@ -424,6 +452,8 @@ libxlReconnectDomain(virDomainObjPtr vm,
|
|||||||
/* Enable domain death events */
|
/* Enable domain death events */
|
||||||
libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW);
|
libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW);
|
||||||
|
|
||||||
|
libxlReconnectNotifyNets(vm->def);
|
||||||
|
|
||||||
/* now that we know it's reconnected call the hook if present */
|
/* now that we know it's reconnected call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) &&
|
if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) &&
|
||||||
STRNEQ("Domain-0", vm->def->name)) {
|
STRNEQ("Domain-0", vm->def->name)) {
|
||||||
|
@ -1646,6 +1646,34 @@ virLXCProcessAutostartAll(virLXCDriverPtr driver)
|
|||||||
virObjectUnref(conn);
|
virObjectUnref(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virLXCProcessReconnectNotifyNets(virDomainDefPtr def)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < def->nnets; i++) {
|
||||||
|
virDomainNetDefPtr net = def->nets[i];
|
||||||
|
/* keep others from trying to use the macvtap device name, but
|
||||||
|
* don't return error if this happens, since that causes the
|
||||||
|
* domain to be unceremoniously killed, which would be *very*
|
||||||
|
* impolite.
|
||||||
|
*/
|
||||||
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT)
|
||||||
|
ignore_value(virNetDevMacVLanReserveName(net->ifname, false));
|
||||||
|
|
||||||
|
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||||
|
if (!conn && !(conn = virGetConnectNetwork()))
|
||||||
|
continue;
|
||||||
|
virDomainNetNotifyActualDevice(conn, def, net);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virObjectUnref(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
@ -1692,6 +1720,8 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
|||||||
vm->def, vm->pid) < 0)
|
vm->def, vm->pid) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
virLXCProcessReconnectNotifyNets(vm->def);
|
||||||
|
|
||||||
/* now that we know it's reconnected call the hook if present */
|
/* now that we know it's reconnected call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->caps, 0);
|
char *xml = virDomainDefFormat(vm->def, driver->caps, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user