conf: rename interface "usageCount" to "connections"

I want to include this count in the xml output of networks, but
calling it "connections" in the XML sounds better than "usageCount", and it
would be better if the name in the XML matched the variable name.

In a few places, usageCount was being initialized to 0, but this is
unnecessary, because VIR_ALLOC_N zero-fills everything anyway.
This commit is contained in:
Laine Stump 2012-08-05 02:45:04 -04:00
parent 95ae4e7fa3
commit 643feae785
3 changed files with 24 additions and 26 deletions

View File

@ -1137,7 +1137,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
} }
if (forwardDev) { if (forwardDev) {
def->forwardIfs[0].usageCount = 0;
def->forwardIfs[0].dev = forwardDev; def->forwardIfs[0].dev = forwardDev;
forwardDev = NULL; forwardDev = NULL;
def->nForwardIfs++; def->nForwardIfs++;
@ -1169,7 +1168,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
def->forwardIfs[ii].dev = forwardDev; def->forwardIfs[ii].dev = forwardDev;
forwardDev = NULL; forwardDev = NULL;
def->forwardIfs[ii].usageCount = 0;
def->nForwardIfs++; def->nForwardIfs++;
} }
} }

View File

@ -132,7 +132,7 @@ typedef struct _virNetworkForwardIfDef virNetworkForwardIfDef;
typedef virNetworkForwardIfDef *virNetworkForwardIfDefPtr; typedef virNetworkForwardIfDef *virNetworkForwardIfDefPtr;
struct _virNetworkForwardIfDef { struct _virNetworkForwardIfDef {
char *dev; /* name of device */ char *dev; /* name of device */
int usageCount; /* how many guest interfaces are bound to this device? */ int connections; /* how many guest interfaces are connected to this device? */
}; };
typedef struct _virNetworkForwardPfDef virNetworkForwardPfDef; typedef struct _virNetworkForwardPfDef virNetworkForwardPfDef;

View File

@ -2914,10 +2914,11 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
} else { } else {
/* pick an interface from the pool */ /* pick an interface from the pool */
/* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both require /* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both
* exclusive access to a device, so current usageCount must be * require exclusive access to a device, so current
* 0. Other modes can share, so just search for the one with * connections count must be 0. Other modes can share, so
* the lowest usageCount. * just search for the one with the lowest number of
* connections.
*/ */
if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) { if (netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) {
if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 0)) { if ((netdef->nForwardPfs > 0) && (netdef->nForwardIfs <= 0)) {
@ -2949,14 +2950,13 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
netdef->forwardIfs[ii].usageCount = 0;
} }
} }
/* pick first dev with 0 usageCount */ /* pick first dev with 0 connections */
for (ii = 0; ii < netdef->nForwardIfs; ii++) { for (ii = 0; ii < netdef->nForwardIfs; ii++) {
if (netdef->forwardIfs[ii].usageCount == 0) { if (netdef->forwardIfs[ii].connections == 0) {
dev = &netdef->forwardIfs[ii]; dev = &netdef->forwardIfs[ii];
break; break;
} }
@ -2966,9 +2966,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
(iface->data.network.actual->virtPortProfile->virtPortType (iface->data.network.actual->virtPortProfile->virtPortType
== VIR_NETDEV_VPORT_PROFILE_8021QBH)) { == VIR_NETDEV_VPORT_PROFILE_8021QBH)) {
/* pick first dev with 0 usageCount */ /* pick first dev with 0 connections */
for (ii = 0; ii < netdef->nForwardIfs; ii++) { for (ii = 0; ii < netdef->nForwardIfs; ii++) {
if (netdef->forwardIfs[ii].usageCount == 0) { if (netdef->forwardIfs[ii].connections == 0) {
dev = &netdef->forwardIfs[ii]; dev = &netdef->forwardIfs[ii];
break; break;
} }
@ -2977,7 +2977,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
/* pick least used dev */ /* pick least used dev */
dev = &netdef->forwardIfs[0]; dev = &netdef->forwardIfs[0];
for (ii = 1; ii < netdef->nForwardIfs; ii++) { for (ii = 1; ii < netdef->nForwardIfs; ii++) {
if (netdef->forwardIfs[ii].usageCount < dev->usageCount) if (netdef->forwardIfs[ii].connections < dev->connections)
dev = &netdef->forwardIfs[ii]; dev = &netdef->forwardIfs[ii];
} }
} }
@ -3002,9 +3002,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
if (dev) { if (dev) {
/* we are now assured of success, so mark the allocation */ /* we are now assured of success, so mark the allocation */
dev->usageCount++; dev->connections++;
VIR_DEBUG("Using physical device %s, usageCount %d", VIR_DEBUG("Using physical device %s, %d connections",
dev->dev, dev->usageCount); dev->dev, dev->connections);
} }
ret = 0; ret = 0;
cleanup: cleanup:
@ -3077,7 +3077,7 @@ networkNotifyActualDevice(virDomainNetDefPtr iface)
int ii; int ii;
virNetworkForwardIfDefPtr dev = NULL; virNetworkForwardIfDefPtr dev = NULL;
/* find the matching interface in the pool and increment its usageCount */ /* find the matching interface and increment its connections */
for (ii = 0; ii < netdef->nForwardIfs; ii++) { for (ii = 0; ii < netdef->nForwardIfs; ii++) {
if (STREQ(actualDev, netdef->forwardIfs[ii].dev)) { if (STREQ(actualDev, netdef->forwardIfs[ii].dev)) {
@ -3094,10 +3094,10 @@ networkNotifyActualDevice(virDomainNetDefPtr iface)
} }
/* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both require /* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both require
* exclusive access to a device, so current usageCount must be * exclusive access to a device, so current connections count
* 0 in those cases. * must be 0 in those cases.
*/ */
if ((dev->usageCount > 0) && if ((dev->connections > 0) &&
((netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) || ((netdef->forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) ||
((netdef->forwardType == VIR_NETWORK_FORWARD_PRIVATE) && ((netdef->forwardType == VIR_NETWORK_FORWARD_PRIVATE) &&
iface->data.network.actual->virtPortProfile && iface->data.network.actual->virtPortProfile &&
@ -3109,9 +3109,9 @@ networkNotifyActualDevice(virDomainNetDefPtr iface)
goto cleanup; goto cleanup;
} }
/* we are now assured of success, so mark the allocation */ /* we are now assured of success, so mark the allocation */
dev->usageCount++; dev->connections++;
VIR_DEBUG("Using physical device %s, usageCount %d", VIR_DEBUG("Using physical device %s, %d connections",
dev->dev, dev->usageCount); dev->dev, dev->connections);
} }
ret = 0; ret = 0;
@ -3194,9 +3194,9 @@ networkReleaseActualDevice(virDomainNetDefPtr iface)
goto cleanup; goto cleanup;
} }
dev->usageCount--; dev->connections--;
VIR_DEBUG("Releasing physical device %s, usageCount %d", VIR_DEBUG("Releasing physical device %s, %d connections",
dev->dev, dev->usageCount); dev->dev, dev->connections);
} }
ret = 0; ret = 0;