/********************************************************/
+/* A unified function to log network connections and disconnections */
+
+static void
+networkLogAllocation(virNetworkDefPtr netdef,
+ virDomainNetType actualType,
+ virNetworkForwardIfDefPtr dev,
+ virDomainNetDefPtr iface,
+ bool inUse)
+{
+ char macStr[VIR_MAC_STRING_BUFLEN];
+ const char *verb = inUse ? "using" : "releasing";
+
+ if (!dev) {
+ VIR_INFO("MAC %s %s network %s (%d connections)",
+ virMacAddrFormat(&iface->mac, macStr), verb,
+ netdef->name, netdef->connections);
+ } else {
+ if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+ VIR_INFO("MAC %s %s network %s (%d connections) "
+ "physical device %04x:%02x:%02x.%x (%d connections)",
+ virMacAddrFormat(&iface->mac, macStr), verb,
+ netdef->name, netdef->connections,
+ dev->device.pci.domain, dev->device.pci.bus,
+ dev->device.pci.slot, dev->device.pci.function,
+ dev->connections);
+ } else {
+ VIR_INFO("MAC %s %s network %s (%d connections) "
+ "physical device %s (%d connections)",
+ virMacAddrFormat(&iface->mac, macStr), verb,
+ netdef->name, netdef->connections,
+ dev->device.dev, dev->connections);
+ }
+ }
+}
+
/* Private API to deal with logical switch capabilities.
* These functions are exported so that other parts of libvirt can
* call them, but are not part of the public API and not in the
if (netdef) {
netdef->connections++;
- VIR_DEBUG("Using network %s, %d connections",
- netdef->name, netdef->connections);
-
- if (dev) {
- /* mark the allocation */
+ if (dev)
dev->connections++;
- if (actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
- VIR_DEBUG("Using physical device %s, %d connections",
- dev->device.dev, dev->connections);
- } else {
- VIR_DEBUG("Using physical device %04x:%02x:%02x.%x, connections %d",
- dev->device.pci.domain, dev->device.pci.bus,
- dev->device.pci.slot, dev->device.pci.function,
- dev->connections);
- }
- }
-
/* finally we can call the 'plugged' hook script if any */
if (networkRunHook(network, dom, iface,
VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
dev->connections--;
goto error;
}
+ networkLogAllocation(netdef, actualType, dev, iface, true);
}
ret = 0;
netdef->name, actualDev);
goto error;
}
-
- VIR_DEBUG("Using physical device %s, connections %d",
- dev->device.dev, dev->connections + 1);
-
} else /* if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) */ {
virDomainHostdevDefPtr hostdev;
dev->device.pci.slot, dev->device.pci.function);
goto error;
}
-
- VIR_DEBUG("Using physical device %04x:%02x:%02x.%x, connections %d",
- dev->device.pci.domain, dev->device.pci.bus,
- dev->device.pci.slot, dev->device.pci.function,
- dev->connections);
}
success:
netdef->connections++;
if (dev)
dev->connections++;
- VIR_DEBUG("Using network %s, %d connections",
- netdef->name, netdef->connections);
-
/* finally we can call the 'plugged' hook script if any */
if (networkRunHook(network, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_PLUGGED,
VIR_HOOK_SUBOP_BEGIN) < 0) {
netdef->connections--;
goto error;
}
+ networkLogAllocation(netdef, actualType, dev, iface, true);
ret = 0;
cleanup:
}
+
/* networkReleaseActualDevice:
* @dom: domain definition that @iface belongs to
* @iface: a domain's NetDef (interface definition)
netdef->name, actualDev);
goto error;
}
-
- VIR_DEBUG("Releasing physical device %s, connections %d",
- dev->device.dev, dev->connections - 1);
-
} else /* if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) */ {
virDomainHostdevDefPtr hostdev;
hostdev->source.subsys.u.pci.addr.function);
goto error;
}
-
- VIR_DEBUG("Releasing physical device %04x:%02x:%02x.%x, connections %d",
- dev->device.pci.domain, dev->device.pci.bus,
- dev->device.pci.slot, dev->device.pci.function,
- dev->connections - 1);
}
success:
netdef->connections--;
if (dev)
dev->connections--;
-
- VIR_DEBUG("Releasing network %s, %d connections",
- netdef->name, netdef->connections);
-
/* finally we can call the 'unplugged' hook script if any */
networkRunHook(network, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED,
VIR_HOOK_SUBOP_BEGIN);
+ networkLogAllocation(netdef, actualType, dev, iface, false);
}
ret = 0;
cleanup: