diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 2b9c6f1866a41bcc05f05ae4f17dbe7e27513201..e2819eb0cc8c500a9325d5d61bbe13180c05a800 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -352,6 +352,34 @@ libxlAutostartDomain(virDomainObjPtr vm, 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 * with libxenlight driver. @@ -424,6 +452,8 @@ libxlReconnectDomain(virDomainObjPtr vm, /* Enable domain death events */ 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 */ if (virHookPresent(VIR_HOOK_DRIVER_LIBXL) && STRNEQ("Domain-0", vm->def->name)) { diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index de4d7c73fbac9a29edf81f48adbbc97eb91d4e33..b59cbbaba58414c9f127a90b13d5180ad192ec8c 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1646,6 +1646,34 @@ virLXCProcessAutostartAll(virLXCDriverPtr driver) 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 virLXCProcessReconnectDomain(virDomainObjPtr vm, void *opaque) @@ -1692,6 +1720,8 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, vm->def, vm->pid) < 0) goto error; + virLXCProcessReconnectNotifyNets(vm->def); + /* now that we know it's reconnected call the hook if present */ if (virHookPresent(VIR_HOOK_DRIVER_LXC)) { char *xml = virDomainDefFormat(vm->def, driver->caps, 0);