network: pass a virNetworkPtr to port management APIs

The APIs for allocating/notifying/removing network ports just take
an internal domain interface struct right now. As a step towards
turning these into public facing APIs, add a virNetworkPtr argument
to all of them.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-07-26 15:32:04 +01:00
parent dd52444f23
commit e1d10f8ef2
9 changed files with 226 additions and 85 deletions

View File

@ -30304,37 +30304,65 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
} }
int int
virDomainNetAllocateActualDevice(virDomainDefPtr dom, virDomainNetAllocateActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkPtr net = NULL;
int ret = -1;
if (!netAllocate) { if (!netAllocate) {
virReportError(VIR_ERR_NO_SUPPORT, "%s", virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("Virtual networking driver is not available")); _("Virtual networking driver is not available"));
return -1; return -1;
} }
return netAllocate(dom, iface); if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
return -1;
ret = netAllocate(net, dom, iface);
virObjectUnref(net);
return ret;
} }
void void
virDomainNetNotifyActualDevice(virDomainDefPtr dom, virDomainNetNotifyActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkPtr net = NULL;
if (!netNotify) if (!netNotify)
return; return;
netNotify(dom, iface); if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
return;
netNotify(net, dom, iface);
virObjectUnref(net);
} }
int int
virDomainNetReleaseActualDevice(virDomainDefPtr dom, virDomainNetReleaseActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkPtr net = NULL;
int ret;
if (!netRelease) if (!netRelease)
return 0; return 0;
return netRelease(dom, iface); if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
return -1;
ret = netRelease(net, dom, iface);
virObjectUnref(net);
return ret;
} }
bool bool

View File

@ -3502,15 +3502,18 @@ virDomainDefLifecycleActionAllowed(virDomainLifecycle type,
virDomainLifecycleAction action); virDomainLifecycleAction action);
typedef int typedef int
(*virDomainNetAllocateActualDeviceImpl)(virDomainDefPtr dom, (*virDomainNetAllocateActualDeviceImpl)(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface); virDomainNetDefPtr iface);
typedef void typedef void
(*virDomainNetNotifyActualDeviceImpl)(virDomainDefPtr dom, (*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface); virDomainNetDefPtr iface);
typedef int typedef int
(*virDomainNetReleaseActualDeviceImpl)(virDomainDefPtr dom, (*virDomainNetReleaseActualDeviceImpl)(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface); virDomainNetDefPtr iface);
typedef bool typedef bool
@ -3530,17 +3533,20 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
virDomainNetBandwidthUpdateImpl bandwidthUpdate); virDomainNetBandwidthUpdateImpl bandwidthUpdate);
int int
virDomainNetAllocateActualDevice(virDomainDefPtr dom, virDomainNetAllocateActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void void
virDomainNetNotifyActualDevice(virDomainDefPtr dom, virDomainNetNotifyActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int int
virDomainNetReleaseActualDevice(virDomainDefPtr dom, virDomainNetReleaseActualDevice(virConnectPtr conn,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

View File

@ -35,6 +35,7 @@
#include "virtime.h" #include "virtime.h"
#include "locking/domain_lock.h" #include "locking/domain_lock.h"
#include "xen_common.h" #include "xen_common.h"
#include "driver.h"
#define VIR_FROM_THIS VIR_FROM_LIBXL #define VIR_FROM_THIS VIR_FROM_LIBXL
@ -845,6 +846,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
char *file; char *file;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI; unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
virConnectPtr conn = NULL;
#ifdef LIBXL_HAVE_PVUSB #ifdef LIBXL_HAVE_PVUSB
hostdev_flags |= VIR_HOSTDEV_SP_USB; hostdev_flags |= VIR_HOSTDEV_SP_USB;
@ -904,8 +906,12 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
/* cleanup actual device */ /* cleanup actual device */
virDomainNetRemoveHostdev(vm->def, net); virDomainNetRemoveHostdev(vm->def, net);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, net); if (conn || (conn = virGetConnectNetwork()))
virDomainNetReleaseActualDevice(conn, vm->def, net);
else
VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
}
} }
} }
@ -928,6 +934,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
virObjectUnref(cfg); virObjectUnref(cfg);
virObjectUnref(conn);
} }
/* /*
@ -1053,6 +1060,8 @@ static int
libxlNetworkPrepareDevices(virDomainDefPtr def) libxlNetworkPrepareDevices(virDomainDefPtr def)
{ {
size_t i; size_t i;
virConnectPtr conn = NULL;
int ret = -1;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
@ -1062,9 +1071,12 @@ libxlNetworkPrepareDevices(virDomainDefPtr def)
* 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.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(def, net) < 0) if (!conn && !(conn = virGetConnectNetwork()))
return -1; goto cleanup;
if (virDomainNetAllocateActualDevice(conn, def, net) < 0)
goto cleanup;
}
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV && if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
@ -1084,10 +1096,14 @@ libxlNetworkPrepareDevices(virDomainDefPtr def)
pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN; pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
if (virDomainHostdevInsert(def, hostdev) < 0) if (virDomainHostdevInsert(def, hostdev) < 0)
return -1; goto cleanup;
} }
} }
return 0;
ret = 0;
cleanup:
virObjectUnref(conn);
return ret;
} }
static void static void

View File

@ -3379,6 +3379,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
libxl_device_nic nic; libxl_device_nic nic;
int ret = -1; int ret = -1;
char mac[VIR_MAC_STRING_BUFLEN]; char mac[VIR_MAC_STRING_BUFLEN];
virConnectPtr conn = NULL;
libxl_device_nic_init(&nic); libxl_device_nic_init(&nic);
@ -3390,9 +3391,12 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
* 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.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(vm->def, net) < 0) if (!(conn = virGetConnectNetwork()))
goto cleanup; goto cleanup;
if (virDomainNetAllocateActualDevice(conn, vm->def, net) < 0)
goto cleanup;
}
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
@ -3441,9 +3445,10 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
vm->def->nets[vm->def->nnets++] = net; vm->def->nets[vm->def->nnets++] = net;
} else { } else {
virDomainNetRemoveHostdev(vm->def, net); virDomainNetRemoveHostdev(vm->def, net);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && conn)
virDomainNetReleaseActualDevice(vm->def, net); virDomainNetReleaseActualDevice(conn, vm->def, net);
} }
virObjectUnref(conn);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
@ -3865,8 +3870,15 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
cleanup: cleanup:
libxl_device_nic_dispose(&nic); libxl_device_nic_dispose(&nic);
if (!ret) { if (!ret) {
if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, detach); virConnectPtr conn = virGetConnectNetwork();
if (conn) {
virDomainNetReleaseActualDevice(conn, vm->def, detach);
virObjectUnref(conn);
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname));
}
}
virDomainNetRemove(vm->def, detachidx); virDomainNetRemove(vm->def, detachidx);
} }
virObjectUnref(cfg); virObjectUnref(cfg);

View File

@ -3834,9 +3834,16 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
* 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.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(vm->def, net) < 0) virConnectPtr netconn = virGetConnectNetwork();
return -1; if (!netconn)
return -1;
if (virDomainNetAllocateActualDevice(netconn, vm->def, net) < 0) {
virObjectUnref(netconn);
return -1;
}
virObjectUnref(netconn);
}
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
@ -4389,8 +4396,15 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
ret = 0; ret = 0;
cleanup: cleanup:
if (!ret) { if (!ret) {
if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (detach->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, detach); virConnectPtr conn = virGetConnectNetwork();
if (conn) {
virDomainNetReleaseActualDevice(conn, vm->def, detach);
virObjectUnref(conn);
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(detach->ifname));
}
}
virDomainNetRemove(vm->def, detachidx); virDomainNetRemove(vm->def, detachidx);
virDomainNetDefFree(detach); virDomainNetDefFree(detach);
} }

View File

@ -165,6 +165,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virLXCDomainObjPrivatePtr priv = vm->privateData; virLXCDomainObjPrivatePtr priv = vm->privateData;
virNetDevVPortProfilePtr vport = NULL; virNetDevVPortProfilePtr vport = NULL;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver); virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
virConnectPtr conn = NULL;
VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d", VIR_DEBUG("Cleanup VM name=%s pid=%d reason=%d",
vm->def->name, (int)vm->pid, (int)reason); vm->def->name, (int)vm->pid, (int)reason);
@ -224,8 +225,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
iface->ifname)); iface->ifname));
ignore_value(virNetDevVethDelete(iface->ifname)); ignore_value(virNetDevVethDelete(iface->ifname));
} }
if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, iface); if (conn || (conn = virGetConnectNetwork()))
virDomainNetReleaseActualDevice(conn, vm->def, iface);
else
VIR_WARN("Unable to release network device '%s'", NULLSTR(iface->ifname));
}
} }
virDomainConfVMNWFilterTeardown(vm); virDomainConfVMNWFilterTeardown(vm);
@ -255,6 +260,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
virDomainObjRemoveTransientDef(vm); virDomainObjRemoveTransientDef(vm);
virObjectUnref(cfg); virObjectUnref(cfg);
virObjectUnref(conn);
} }
@ -543,6 +549,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
size_t niface = 0; size_t niface = 0;
virDomainNetDefPtr net; virDomainNetDefPtr net;
virDomainNetType type; virDomainNetType type;
virConnectPtr netconn = NULL;
if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0) if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0)
return -1; return -1;
@ -559,9 +566,12 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
if (virLXCProcessValidateInterface(net) < 0) if (virLXCProcessValidateInterface(net) < 0)
goto cleanup; goto cleanup;
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(def, net) < 0) if (!netconn && !(netconn = virGetConnectNetwork()))
goto cleanup; goto cleanup;
if (virDomainNetAllocateActualDevice(netconn, def, net) < 0)
goto cleanup;
}
type = virDomainNetGetActualType(net); type = virDomainNetGetActualType(net);
switch (type) { switch (type) {
@ -639,10 +649,11 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
ignore_value(virNetDevOpenvswitchRemovePort( ignore_value(virNetDevOpenvswitchRemovePort(
virDomainNetGetActualBridgeName(iface), virDomainNetGetActualBridgeName(iface),
iface->ifname)); iface->ifname));
if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (iface->type == VIR_DOMAIN_NET_TYPE_NETWORK && netconn)
virDomainNetReleaseActualDevice(def, iface); virDomainNetReleaseActualDevice(netconn, def, iface);
} }
} }
virObjectUnref(netconn);
return ret; return ret;
} }

View File

@ -4376,7 +4376,8 @@ networkLogAllocation(virNetworkDefPtr netdef,
* Returns 0 on success, -1 on failure. * Returns 0 on success, -1 on failure.
*/ */
static int static int
networkAllocateActualDevice(virDomainDefPtr dom, networkAllocateActualDevice(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkDriverStatePtr driver = networkGetDriver();
@ -4391,6 +4392,14 @@ networkAllocateActualDevice(virDomainDefPtr dom,
size_t i; size_t i;
int ret = -1; int ret = -1;
obj = virNetworkObjFindByName(driver->networks, net->name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
net->name);
goto error;
}
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Expected an interface for a virtual network")); _("Expected an interface for a virtual network"));
@ -4400,13 +4409,6 @@ networkAllocateActualDevice(virDomainDefPtr dom,
virDomainActualNetDefFree(iface->data.network.actual); virDomainActualNetDefFree(iface->data.network.actual);
iface->data.network.actual = NULL; iface->data.network.actual = NULL;
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
goto error;
}
netdef = virNetworkObjGetDef(obj); netdef = virNetworkObjGetDef(obj);
if (!virNetworkObjIsActive(obj)) { if (!virNetworkObjIsActive(obj)) {
@ -4795,7 +4797,8 @@ networkAllocateActualDevice(virDomainDefPtr dom,
* No return value (but does log any failures) * No return value (but does log any failures)
*/ */
static void static void
networkNotifyActualDevice(virDomainDefPtr dom, networkNotifyActualDevice(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkDriverStatePtr driver = networkGetDriver();
@ -4806,19 +4809,20 @@ networkNotifyActualDevice(virDomainDefPtr dom,
size_t i; size_t i;
char *master = NULL; char *master = NULL;
obj = virNetworkObjFindByName(driver->networks, net->name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
net->name);
goto error;
}
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Expected an interface for a virtual network")); _("Expected an interface for a virtual network"));
goto error; goto error;
} }
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
goto error;
}
netdef = virNetworkObjGetDef(obj); netdef = virNetworkObjGetDef(obj);
if (!virNetworkObjIsActive(obj)) { if (!virNetworkObjIsActive(obj)) {
@ -5031,7 +5035,8 @@ networkNotifyActualDevice(virDomainDefPtr dom,
* Returns 0 on success, -1 on failure. * Returns 0 on success, -1 on failure.
*/ */
static int static int
networkReleaseActualDevice(virDomainDefPtr dom, networkReleaseActualDevice(virNetworkPtr net,
virDomainDefPtr dom,
virDomainNetDefPtr iface) virDomainNetDefPtr iface)
{ {
virNetworkDriverStatePtr driver = networkGetDriver(); virNetworkDriverStatePtr driver = networkGetDriver();
@ -5042,19 +5047,20 @@ networkReleaseActualDevice(virDomainDefPtr dom,
size_t i; size_t i;
int ret = -1; int ret = -1;
obj = virNetworkObjFindByName(driver->networks, net->name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
net->name);
goto error;
}
if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) { if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Expected an interface for a virtual network")); _("Expected an interface for a virtual network"));
goto error; goto error;
} }
obj = virNetworkObjFindByName(driver->networks, iface->data.network.name);
if (!obj) {
virReportError(VIR_ERR_NO_NETWORK,
_("no network with matching name '%s'"),
iface->data.network.name);
goto error;
}
netdef = virNetworkObjGetDef(obj); netdef = virNetworkObjGetDef(obj);
switch ((virNetworkForwardType) netdef->forward.type) { switch ((virNetworkForwardType) netdef->forward.type) {

View File

@ -1376,6 +1376,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
bool charDevPlugged = false; bool charDevPlugged = false;
bool netdevPlugged = false; bool netdevPlugged = false;
char *netdev_name; char *netdev_name;
virConnectPtr conn = NULL;
/* preallocate new slot for device */ /* preallocate new slot for device */
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0) if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
@ -1385,9 +1386,12 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
* 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.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(vm->def, net) < 0) if (!(conn = virGetConnectNetwork()))
goto cleanup; goto cleanup;
if (virDomainNetAllocateActualDevice(conn, vm->def, net) < 0)
goto cleanup;
}
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
@ -1690,8 +1694,12 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
virDomainNetRemoveHostdev(vm->def, net); virDomainNetRemoveHostdev(vm->def, net);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, net); if (conn)
virDomainNetReleaseActualDevice(conn, vm->def, net);
else
VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
}
} }
VIR_FREE(nicstr); VIR_FREE(nicstr);
@ -1711,6 +1719,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
VIR_FREE(vhostfd); VIR_FREE(vhostfd);
VIR_FREE(vhostfdName); VIR_FREE(vhostfdName);
VIR_FREE(charDevAlias); VIR_FREE(charDevAlias);
virObjectUnref(conn);
virDomainCCWAddressSetFree(ccwaddrs); virDomainCCWAddressSetFree(ccwaddrs);
return ret; return ret;
@ -3740,6 +3749,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
bool needVlanUpdate = false; bool needVlanUpdate = false;
int ret = -1; int ret = -1;
int changeidx = -1; int changeidx = -1;
virConnectPtr conn = NULL;
if ((changeidx = virDomainNetFindIdx(vm->def, newdev)) < 0) if ((changeidx = virDomainNetFindIdx(vm->def, newdev)) < 0)
goto cleanup; goto cleanup;
@ -3915,9 +3925,11 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
/* allocate new actual device to compare to old - we will need to /* allocate new actual device to compare to old - we will need to
* free it if we fail for any reason * free it if we fail for any reason
*/ */
if (newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(vm->def, newdev) < 0) { if (!(conn = virGetConnectNetwork()))
goto cleanup; goto cleanup;
if (virDomainNetAllocateActualDevice(conn, vm->def, newdev) < 0)
goto cleanup;
} }
newType = virDomainNetGetActualType(newdev); newType = virDomainNetGetActualType(newdev);
@ -4128,8 +4140,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
/* this function doesn't work with HOSTDEV networks yet, thus /* this function doesn't work with HOSTDEV networks yet, thus
* no need to change the pointer in the hostdev structure */ * no need to change the pointer in the hostdev structure */
if (olddev->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (olddev->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, olddev); if (conn || (conn = virGetConnectNetwork()))
virDomainNetReleaseActualDevice(conn, vm->def, olddev);
else
VIR_WARN("Unable to release network device '%s'", NULLSTR(olddev->ifname));
}
virDomainNetDefFree(olddev); virDomainNetDefFree(olddev);
/* move newdev into the nets list, and NULL it out from the /* move newdev into the nets list, and NULL it out from the
* virDomainDeviceDef that we were given so that the caller * virDomainDeviceDef that we were given so that the caller
@ -4160,8 +4176,9 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
* that the changes were minor enough that we didn't need to * that the changes were minor enough that we didn't need to
* replace the entire device object. * replace the entire device object.
*/ */
if (newdev && newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (newdev && newdev->type == VIR_DOMAIN_NET_TYPE_NETWORK && conn)
virDomainNetReleaseActualDevice(vm->def, newdev); virDomainNetReleaseActualDevice(conn, vm->def, newdev);
virObjectUnref(conn);
return ret; return ret;
} }
@ -4753,8 +4770,15 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
virDomainHostdevDefFree(hostdev); virDomainHostdevDefFree(hostdev);
if (net) { if (net) {
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, net); virConnectPtr conn = virGetConnectNetwork();
if (conn) {
virDomainNetReleaseActualDevice(conn, vm->def, net);
virObjectUnref(conn);
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
}
}
virDomainNetDefFree(net); virDomainNetDefFree(net);
} }
@ -4856,8 +4880,15 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
qemuDomainNetDeviceVportRemove(net); qemuDomainNetDeviceVportRemove(net);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, net); virConnectPtr conn = virGetConnectNetwork();
if (conn) {
virDomainNetReleaseActualDevice(conn, vm->def, net);
virObjectUnref(conn);
} else {
VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
}
}
virDomainNetDefFree(net); virDomainNetDefFree(net);
ret = 0; ret = 0;

View File

@ -3277,6 +3277,7 @@ static void
qemuProcessNotifyNets(virDomainDefPtr def) qemuProcessNotifyNets(virDomainDefPtr def)
{ {
size_t i; size_t i;
virConnectPtr conn = NULL;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
@ -3288,9 +3289,14 @@ qemuProcessNotifyNets(virDomainDefPtr def)
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT)
ignore_value(virNetDevMacVLanReserveName(net->ifname, false)); ignore_value(virNetDevMacVLanReserveName(net->ifname, false));
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetNotifyActualDevice(def, net); if (!conn && !(conn = virGetConnectNetwork()))
continue;
virDomainNetNotifyActualDevice(conn, def, net);
}
} }
virObjectUnref(conn);
} }
/* Attempt to instantiate the filters. Ignore failures because it's /* Attempt to instantiate the filters. Ignore failures because it's
@ -5466,6 +5472,7 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
{ {
int ret = -1; int ret = -1;
size_t i; size_t i;
virConnectPtr conn = NULL;
for (i = 0; i < def->nnets; i++) { for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i]; virDomainNetDefPtr net = def->nets[i];
@ -5475,9 +5482,12 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
* 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.
*/ */
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK && if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetAllocateActualDevice(def, net) < 0) if (!conn && !(conn = virGetConnectNetwork()))
goto cleanup; goto cleanup;
if (virDomainNetAllocateActualDevice(conn, def, net) < 0)
goto cleanup;
}
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV && if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV &&
@ -5508,6 +5518,7 @@ qemuProcessNetworkPrepareDevices(virDomainDefPtr def)
} }
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(conn);
return ret; return ret;
} }
@ -7123,6 +7134,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
size_t i; size_t i;
char *timestamp; char *timestamp;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virConnectPtr conn = NULL;
VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%lld, " VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%lld, "
"reason=%s, asyncJob=%s, flags=0x%x", "reason=%s, asyncJob=%s, flags=0x%x",
@ -7323,8 +7335,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
/* kick the device out of the hostdev list too */ /* kick the device out of the hostdev list too */
virDomainNetRemoveHostdev(def, net); virDomainNetRemoveHostdev(def, net);
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
virDomainNetReleaseActualDevice(vm->def, net); if (conn || (conn = virGetConnectNetwork()))
virDomainNetReleaseActualDevice(conn, vm->def, net);
else
VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
}
} }
retry: retry:
@ -7427,6 +7443,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virSetError(orig_err); virSetError(orig_err);
virFreeError(orig_err); virFreeError(orig_err);
} }
virObjectUnref(conn);
virObjectUnref(cfg); virObjectUnref(cfg);
} }