network: fix connection usage counts after restart

Since the introduction of the virNetworkPort object, the network driver
has a persistent record of ports that have been created against the
networks. Thus the hypervisor drivers no longer communicate to the
network driver during libvirtd restart.

This change, however, meant that the connection usage counts were
no longer re-initialized during a libvirtd restart. To deal with this we
must iterate over all virNetworkPortDefPtr objects we have and invoke
the notify callback to record the connection usage count.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-09-13 15:54:18 +01:00
parent 3eca0e300d
commit 7ab9bdd470
4 changed files with 60 additions and 0 deletions

View File

@ -1844,6 +1844,39 @@ virNetworkObjPortListExport(virNetworkPtr net,
}
typedef struct _virNetworkObjPortListForEachData virNetworkObjPortListForEachData;
struct _virNetworkObjPortListForEachData {
virNetworkPortListIter iter;
void *opaque;
bool err;
};
static int
virNetworkObjPortForEachCallback(void *payload,
const void *name ATTRIBUTE_UNUSED,
void *opaque)
{
virNetworkObjPortListForEachData *data = opaque;
if (!data->iter(payload, data->opaque))
data->err = true;
return 0;
}
int
virNetworkObjPortForEach(virNetworkObjPtr obj,
virNetworkPortListIter iter,
void *opaque)
{
virNetworkObjPortListForEachData data = { iter, opaque, false };
virHashForEach(obj->ports, virNetworkObjPortForEachCallback, &data);
if (data.err)
return -1;
return 0;
}
static int
virNetworkObjLoadAllPorts(virNetworkObjPtr net,
const char *stateDir)

View File

@ -190,6 +190,15 @@ virNetworkObjPortListExport(virNetworkPtr net,
virNetworkPortPtr **ports,
virNetworkPortListFilter filter);
typedef bool
(*virNetworkPortListIter)(virNetworkPortDefPtr portdef,
void *opaque);
int
virNetworkObjPortForEach(virNetworkObjPtr obj,
virNetworkPortListIter iter,
void *opaque);
int
virNetworkObjSaveStatus(const char *statusDir,
virNetworkObjPtr net,

View File

@ -1097,6 +1097,7 @@ virNetworkObjLookupPort;
virNetworkObjMacMgrAdd;
virNetworkObjMacMgrDel;
virNetworkObjNew;
virNetworkObjPortForEach;
virNetworkObjPortListExport;
virNetworkObjRemoveInactive;
virNetworkObjReplacePersistentDef;

View File

@ -527,6 +527,21 @@ networkBridgeDummyNicName(const char *brname)
}
static int
networkNotifyPort(virNetworkObjPtr obj,
virNetworkPortDefPtr port);
static bool
networkUpdatePort(virNetworkPortDefPtr port,
void *opaque)
{
virNetworkObjPtr obj = opaque;
networkNotifyPort(obj, port);
return false;
}
static int
networkUpdateState(virNetworkObjPtr obj,
void *opaque)
@ -591,6 +606,8 @@ networkUpdateState(virNetworkObjPtr obj,
goto cleanup;
}
virNetworkObjPortForEach(obj, networkUpdatePort, obj);
/* Try and read dnsmasq/radvd pids of active networks */
if (virNetworkObjIsActive(obj) && def->ips && (def->nips > 0)) {
pid_t radvdPid;