提交 e6336442 编写于 作者: C Chunyan Liu 提交者: Jim Fehlig

libxlDomainAttachNetDevice: release actual deivce and remove hostdev when fail

When AttachNetDevice failed, should call networkReleaseActualDevice
to release actual device, and if actual device is hostdev, should
remove the hostdev from vm->def->hostdevs.
Signed-off-by: NChunyan Liu <cyliu@suse.com>
上级 b41261f0
...@@ -3122,16 +3122,18 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, ...@@ -3122,16 +3122,18 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
int ret = -1; int ret = -1;
char mac[VIR_MAC_STRING_BUFLEN]; char mac[VIR_MAC_STRING_BUFLEN];
libxl_device_nic_init(&nic);
/* 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)
goto out; goto cleanup;
/* If appropriate, grab a physical device from the configured /* If appropriate, grab a physical device from the configured
* network's pool of devices, or resolve bridge device name * network's pool of devices, or resolve bridge device name
* to the one defined in the network definition. * to the one defined in the network definition.
*/ */
if (networkAllocateActualDevice(vm->def, net) < 0) if (networkAllocateActualDevice(vm->def, net) < 0)
goto out; goto cleanup;
actualType = virDomainNetGetActualType(net); actualType = virDomainNetGetActualType(net);
...@@ -3139,7 +3141,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, ...@@ -3139,7 +3141,7 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("network device with mac %s already exists"), _("network device with mac %s already exists"),
virMacAddrFormat(&net->mac, mac)); virMacAddrFormat(&net->mac, mac));
return -1; goto cleanup;
} }
if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) { if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
...@@ -3150,10 +3152,9 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, ...@@ -3150,10 +3152,9 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
*/ */
ret = libxlDomainAttachHostDevice(driver, vm, ret = libxlDomainAttachHostDevice(driver, vm,
virDomainNetGetActualHostdev(net)); virDomainNetGetActualHostdev(net));
goto out; goto cleanup;
} }
libxl_device_nic_init(&nic);
if (libxlMakeNic(vm->def, net, &nic) < 0) if (libxlMakeNic(vm->def, net, &nic) < 0)
goto cleanup; goto cleanup;
...@@ -3163,13 +3164,15 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver, ...@@ -3163,13 +3164,15 @@ libxlDomainAttachNetDevice(libxlDriverPrivatePtr driver,
goto cleanup; goto cleanup;
} }
vm->def->nets[vm->def->nnets++] = net;
ret = 0; ret = 0;
cleanup: cleanup:
libxl_device_nic_dispose(&nic); libxl_device_nic_dispose(&nic);
out: if (ret) {
if (!ret) virDomainNetRemoveHostdev(vm->def, net);
vm->def->nets[vm->def->nnets++] = net; networkReleaseActualDevice(vm->def, net);
}
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册