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

libxl_driver.c: cleanup code

Following Jim's comments about "add pci passthrough to libxl" patch:

https://www.redhat.com/archives/libvir-list/2014-March/msg00170.htmlSigned-off-by: NChunyan Liu <cyliu@suse.com>
上级 4dae396f
...@@ -2616,10 +2616,10 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2616,10 +2616,10 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
if (virHostdevPreparePCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME, if (virHostdevPreparePCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def->name, vm->def->uuid, vm->def->name, vm->def->uuid,
&hostdev, 1, 0) < 0) &hostdev, 1, 0) < 0)
goto cleanup; return -1;
if (libxlMakePci(hostdev, &pcidev) < 0) if (libxlMakePci(hostdev, &pcidev) < 0)
goto reattach_hostdev; goto error;
if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) { if (libxl_device_pci_add(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -2628,17 +2628,15 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2628,17 +2628,15 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver,
hostdev->source.subsys.u.pci.addr.bus, hostdev->source.subsys.u.pci.addr.bus,
hostdev->source.subsys.u.pci.addr.slot, hostdev->source.subsys.u.pci.addr.slot,
hostdev->source.subsys.u.pci.addr.function); hostdev->source.subsys.u.pci.addr.function);
goto reattach_hostdev; goto error;
} }
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev; vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
return 0; return 0;
reattach_hostdev: error:
virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME, virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def->name, &hostdev, 1, NULL); vm->def->name, &hostdev, 1, NULL);
cleanup:
return -1; return -1;
} }
...@@ -2660,20 +2658,17 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver, ...@@ -2660,20 +2658,17 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
switch (hostdev->source.subsys.type) { switch (hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (libxlDomainAttachHostPCIDevice(driver, priv, vm, hostdev) < 0) if (libxlDomainAttachHostPCIDevice(driver, priv, vm, hostdev) < 0)
goto error; return -1;
break; break;
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hostdev subsys type '%s' not supported"), _("hostdev subsys type '%s' not supported"),
virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type)); virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type));
goto error; return -1;
} }
return 0; return 0;
error:
return -1;
} }
static int static int
...@@ -2867,14 +2862,14 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2867,14 +2862,14 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
_("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"), _("cannot hot unplug multifunction PCI device: %.4x:%.2x:%.2x.%.1x"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
goto cleanup; goto error;
} }
libxl_device_pci_init(&pcidev); libxl_device_pci_init(&pcidev);
if (libxlMakePci(detach, &pcidev) < 0) if (libxlMakePci(detach, &pcidev) < 0)
goto cleanup; goto error;
if (libxl_device_pci_remove(priv->ctx, vm->def->id, &pcidev, 0) < 0) { if (libxl_device_pci_remove(priv->ctx, vm->def->id, &pcidev, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -2882,7 +2877,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2882,7 +2877,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
%.4x:%.2x:%.2x.%.1x"), %.4x:%.2x:%.2x.%.1x"),
subsys->u.pci.addr.domain, subsys->u.pci.addr.bus, subsys->u.pci.addr.domain, subsys->u.pci.addr.bus,
subsys->u.pci.addr.slot, subsys->u.pci.addr.function); subsys->u.pci.addr.slot, subsys->u.pci.addr.function);
goto cleanup; goto error;
} }
libxl_device_pci_dispose(&pcidev); libxl_device_pci_dispose(&pcidev);
...@@ -2894,7 +2889,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, ...@@ -2894,7 +2889,7 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver,
return 0; return 0;
cleanup: error:
virDomainHostdevDefFree(detach); virDomainHostdevDefFree(detach);
return -1; return -1;
} }
...@@ -4156,7 +4151,6 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, ...@@ -4156,7 +4151,6 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
unsigned *function) unsigned *function)
{ {
virNodeDevCapsDefPtr cap; virNodeDevCapsDefPtr cap;
int ret = -1;
cap = def->caps; cap = def->caps;
while (cap) { while (cap) {
...@@ -4174,12 +4168,10 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def, ...@@ -4174,12 +4168,10 @@ libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
if (!cap) { if (!cap) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("device %s is not a PCI device"), def->name); _("device %s is not a PCI device"), def->name);
goto out; return -1;
} }
ret = 0; return 0;
out:
return ret;
} }
static int static int
...@@ -4271,12 +4263,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev) ...@@ -4271,12 +4263,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
goto cleanup; goto cleanup;
if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0) if (virHostdevPCINodeDeviceReAttach(hostdev_mgr, pci) < 0)
goto out; goto cleanup;
ret = 0; ret = 0;
out:
virPCIDeviceFree(pci);
cleanup: cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
VIR_FREE(xml); VIR_FREE(xml);
return ret; return ret;
...@@ -4285,7 +4277,7 @@ cleanup: ...@@ -4285,7 +4277,7 @@ cleanup:
static int static int
libxlNodeDeviceReset(virNodeDevicePtr dev) libxlNodeDeviceReset(virNodeDevicePtr dev)
{ {
virPCIDevicePtr pci; virPCIDevicePtr pci = NULL;
unsigned domain = 0, bus = 0, slot = 0, function = 0; unsigned domain = 0, bus = 0, slot = 0, function = 0;
int ret = -1; int ret = -1;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
...@@ -4312,12 +4304,12 @@ libxlNodeDeviceReset(virNodeDevicePtr dev) ...@@ -4312,12 +4304,12 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
goto cleanup; goto cleanup;
if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0) if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0)
goto out; goto cleanup;
ret = 0; ret = 0;
out:
virPCIDeviceFree(pci);
cleanup: cleanup:
virPCIDeviceFree(pci);
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
VIR_FREE(xml); VIR_FREE(xml);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册