提交 7ab9bdd4 编写于 作者: D Daniel P. Berrangé

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: NLaine Stump <laine@laine.org>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 3eca0e30
......@@ -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)
......
......@@ -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,
......
......@@ -1097,6 +1097,7 @@ virNetworkObjLookupPort;
virNetworkObjMacMgrAdd;
virNetworkObjMacMgrDel;
virNetworkObjNew;
virNetworkObjPortForEach;
virNetworkObjPortListExport;
virNetworkObjRemoveInactive;
virNetworkObjReplacePersistentDef;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册