On 03/21/2016 02:11 AM, Chunyan Liu wrote:
Adjust codes to make it cleaner.
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/libxl/libxl_driver.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 05ebe29..74ebea4 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3413,8 +3413,10 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
char mac[VIR_MAC_STRING_BUFLEN];
int ret = -1;
+ libxl_device_nic_init(&nic);
+
if ((detachidx = virDomainNetFindIdx(vm->def, net)) < 0)
- goto out;
+ goto cleanup;
detach = vm->def->nets[detachidx];
@@ -3424,10 +3426,9 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
*/
ret = libxlDomainDetachHostDevice(driver, vm,
virDomainNetGetActualHostdev(detach));
- goto out;
+ goto cleanup;
}
- libxl_device_nic_init(&nic);
if (libxl_mac_to_device_nic(cfg->ctx, vm->def->id,
virMacAddrFormat(&detach->mac, mac), &nic))
goto cleanup;
@@ -3442,7 +3443,6 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
cleanup:
libxl_device_nic_dispose(&nic);
- out:
if (!ret)
virDomainNetRemove(vm->def, detachidx);
virObjectUnref(cfg);
Same comment here as in patch 1. The device can be removed after a successful
libxl_device_nic_remove(). I've squashed in the below change.
Regards,
Jim
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index ae900d8..b2e23c0 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3438,12 +3438,11 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
goto cleanup;
}
+ virDomainNetRemove(vm->def, detachidx);
ret = 0;
cleanup:
libxl_device_nic_dispose(&nic);
- if (!ret)
- virDomainNetRemove(vm->def, detachidx);
virObjectUnref(cfg);
return ret;
}