When detaching interface without <mac> specified a one is generated
which leads to not found device.
---
src/qemu/qemu_hotplug.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0002af0..54c97db 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1436,18 +1436,32 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver,
virDomainDeviceDefPtr dev,
virBitmapPtr qemuCaps)
{
- int i, ret = -1;
+ int i = 0, ret = -1;
virDomainNetDefPtr detach = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
int vlan;
char *hostnet_name = NULL;
- for (i = 0 ; i < vm->def->nnets ; i++) {
- virDomainNetDefPtr net = vm->def->nets[i];
+ if (!vm->def->nnets) {
+ qemuReportError(VIR_ERR_OPERATION_FAILED,
+ _("domain has no interfaces."));
+ goto cleanup;
+ } else if ((vm->def->nnets > 2) &&
(dev->data.net->mac_generated)) {
+ qemuReportError(VIR_ERR_OPERATION_FAILED,
+ _("You must specify mac address in xml file"));
+ goto cleanup;
+ }
- if (!memcmp(net->mac, dev->data.net->mac, sizeof(net->mac))) {
- detach = net;
- break;
+ if ((vm->def->nnets==1) && (dev->data.net->mac_generated)) {
+ detach = vm->def->nets[0];
+ } else {
+ for (i = 0 ; i < vm->def->nnets ; i++) {
+ virDomainNetDefPtr net = vm->def->nets[i];
+
+ if (!memcmp(net->mac, dev->data.net->mac, sizeof(net->mac))) {
+ detach = net;
+ break;
+ }
}
}
--
1.7.4