libxlDomainDetachNetDevice: cleanup codes

Adjust codes to make it cleaner.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
This commit is contained in:
Chunyan Liu 2016-03-21 16:11:37 +08:00 committed by Jim Fehlig
parent e633644229
commit b5534e5391

View File

@ -3412,8 +3412,10 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
char mac[VIR_MAC_STRING_BUFLEN]; char mac[VIR_MAC_STRING_BUFLEN];
int ret = -1; int ret = -1;
libxl_device_nic_init(&nic);
if ((detachidx = virDomainNetFindIdx(vm->def, net)) < 0) if ((detachidx = virDomainNetFindIdx(vm->def, net)) < 0)
goto out; goto cleanup;
detach = vm->def->nets[detachidx]; detach = vm->def->nets[detachidx];
@ -3423,10 +3425,9 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
*/ */
ret = libxlDomainDetachHostDevice(driver, vm, ret = libxlDomainDetachHostDevice(driver, vm,
virDomainNetGetActualHostdev(detach)); virDomainNetGetActualHostdev(detach));
goto out; goto cleanup;
} }
libxl_device_nic_init(&nic);
if (libxl_mac_to_device_nic(cfg->ctx, vm->def->id, if (libxl_mac_to_device_nic(cfg->ctx, vm->def->id,
virMacAddrFormat(&detach->mac, mac), &nic)) virMacAddrFormat(&detach->mac, mac), &nic))
goto cleanup; goto cleanup;
@ -3437,13 +3438,11 @@ libxlDomainDetachNetDevice(libxlDriverPrivatePtr driver,
goto cleanup; goto cleanup;
} }
virDomainNetRemove(vm->def, detachidx);
ret = 0; ret = 0;
cleanup: cleanup:
libxl_device_nic_dispose(&nic); libxl_device_nic_dispose(&nic);
out:
if (!ret)
virDomainNetRemove(vm->def, detachidx);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }