mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
libxl: prevent attaching multiple netdevs with the same MAC
It will not be possible to detach such device later. Also improve logging in such cases. Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
This commit is contained in:
parent
ed4db85a55
commit
1a01a2aa57
@ -2780,6 +2780,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
|
|||||||
int actualType;
|
int actualType;
|
||||||
libxl_device_nic nic;
|
libxl_device_nic nic;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
char mac[VIR_MAC_STRING_BUFLEN];
|
||||||
|
|
||||||
/* 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)
|
||||||
@ -2794,6 +2795,13 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
|
|||||||
|
|
||||||
actualType = virDomainNetGetActualType(net);
|
actualType = virDomainNetGetActualType(net);
|
||||||
|
|
||||||
|
if (virDomainHasNet(vm->def, net)) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("network device with mac %s already exists"),
|
||||||
|
virMacAddrFormat(&net->mac, mac));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
|
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
|
||||||
/* This is really a "smart hostdev", so it should be attached
|
/* This is really a "smart hostdev", so it should be attached
|
||||||
* as a hostdev (the hostdev code will reach over into the
|
* as a hostdev (the hostdev code will reach over into the
|
||||||
@ -2872,6 +2880,7 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
|
|||||||
virDomainHostdevDefPtr hostdev;
|
virDomainHostdevDefPtr hostdev;
|
||||||
virDomainHostdevDefPtr found;
|
virDomainHostdevDefPtr found;
|
||||||
virDomainHostdevSubsysPCIPtr pcisrc;
|
virDomainHostdevSubsysPCIPtr pcisrc;
|
||||||
|
char mac[VIR_MAC_STRING_BUFLEN];
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
case VIR_DOMAIN_DEVICE_DISK:
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
@ -2889,6 +2898,12 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
|
|||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_NET:
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
net = dev->data.net;
|
net = dev->data.net;
|
||||||
|
if (virDomainHasNet(vmdef, net)) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("network device with mac %s already exists"),
|
||||||
|
virMacAddrFormat(&net->mac, mac));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (virDomainNetInsert(vmdef, net))
|
if (virDomainNetInsert(vmdef, net))
|
||||||
return -1;
|
return -1;
|
||||||
dev->data.net = NULL;
|
dev->data.net = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user