Re: [libvirt] [PATCH 12/17] qemu: refactor hotplug detach of hostdevs

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This refactoring is necessary to support hotplug detach of
 type=hostdev network devices, but needs to be in a separate patch to
 make potential debugging of regressions more practical.
 
 Rather than the lowest level functions searching for a matching
 device, the search is now done in the toplevel function, and an
 intermediate-level function (qemuDomainDetachThisHostDevice()), which
 expects that the device's entry is already found, is called (this
 intermediate function will be called by qemuDomainDetachNetDevice() in
 order to support detach of type=hostdev net devices)
 
 This patch should result in 0 differences in functionality.
 ---
 New patch for V2.
 
  src/qemu/qemu_hotplug.c |  228 
 +++
  1 files changed, 93 insertions(+), 135 deletions(-)

Nice cleanup. I wish we have more like these :)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 12/17] qemu: refactor hotplug detach of hostdevs

2012-02-28 Thread Laine Stump
This refactoring is necessary to support hotplug detach of
type=hostdev network devices, but needs to be in a separate patch to
make potential debugging of regressions more practical.

Rather than the lowest level functions searching for a matching
device, the search is now done in the toplevel function, and an
intermediate-level function (qemuDomainDetachThisHostDevice()), which
expects that the device's entry is already found, is called (this
intermediate function will be called by qemuDomainDetachNetDevice() in
order to support detach of type=hostdev net devices)

This patch should result in 0 differences in functionality.
---
New patch for V2.

 src/qemu/qemu_hotplug.c |  228 +++
 1 files changed, 93 insertions(+), 135 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e9df537..cb41388 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1,7 +1,7 @@
 /*
  * qemu_hotplug.h: QEMU device hotplug management
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -1836,48 +1836,20 @@ cleanup:
 static int
 qemuDomainDetachHostPciDevice(struct qemud_driver *driver,
   virDomainObjPtr vm,
-  virDomainDeviceDefPtr dev,
-  virDomainHostdevDefPtr *detach_ret)
+  virDomainHostdevDefPtr detach,
+  int idx)
 {
-virDomainHostdevDefPtr detach = NULL;
 qemuDomainObjPrivatePtr priv = vm-privateData;
-int i, ret;
+virDomainHostdevSubsysPtr subsys = detach-source.subsys;
+int ret;
 pciDevice *pci;
 pciDevice *activePci;
 
-for (i = 0 ; i  vm-def-nhostdevs ; i++) {
-if (vm-def-hostdevs[i]-mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-vm-def-hostdevs[i]-source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
-continue;
-
-unsigned domain   = vm-def-hostdevs[i]-source.subsys.u.pci.domain;
-unsigned bus  = vm-def-hostdevs[i]-source.subsys.u.pci.bus;
-unsigned slot = vm-def-hostdevs[i]-source.subsys.u.pci.slot;
-unsigned function = vm-def-hostdevs[i]-source.subsys.u.pci.function;
-
-if (dev-data.hostdev-source.subsys.u.pci.domain   == domain 
-dev-data.hostdev-source.subsys.u.pci.bus  == bus 
-dev-data.hostdev-source.subsys.u.pci.slot == slot 
-dev-data.hostdev-source.subsys.u.pci.function == function) {
-detach = vm-def-hostdevs[i];
-break;
-}
-}
-
-if (!detach) {
-qemuReportError(VIR_ERR_OPERATION_FAILED,
-_(host pci device %.4x:%.2x:%.2x.%.1x not found),
-dev-data.hostdev-source.subsys.u.pci.domain,
-dev-data.hostdev-source.subsys.u.pci.bus,
-dev-data.hostdev-source.subsys.u.pci.slot,
-dev-data.hostdev-source.subsys.u.pci.function);
-return -1;
-}
-
 if (qemuIsMultiFunctionDevice(vm-def, detach-info)) {
 qemuReportError(VIR_ERR_OPERATION_FAILED,
-_(cannot hot unplug multifunction PCI device: %s),
-dev-data.disk-dst);
+_(cannot hot unplug multifunction PCI device: 
%.4x:%.2x:%.2x.%.1x),
+subsys-u.pci.domain, subsys-u.pci.bus,
+subsys-u.pci.slot,   subsys-u.pci.function);
 return -1;
 }
 
@@ -1899,10 +1871,8 @@ qemuDomainDetachHostPciDevice(struct qemud_driver 
*driver,
 if (ret  0)
 return -1;
 
-pci = pciGetDevice(detach-source.subsys.u.pci.domain,
-   detach-source.subsys.u.pci.bus,
-   detach-source.subsys.u.pci.slot,
-   detach-source.subsys.u.pci.function);
+pci = pciGetDevice(subsys-u.pci.domain, subsys-u.pci.bus,
+   subsys-u.pci.slot,   subsys-u.pci.function);
 if (pci) {
 activePci = pciDeviceListSteal(driver-activePciHostdevs, pci);
 if (pciResetDevice(activePci, driver-activePciHostdevs,
@@ -1921,71 +1891,20 @@ qemuDomainDetachHostPciDevice(struct qemud_driver 
*driver,
 detach-info-addr.pci.slot)  0)
 VIR_WARN(Unable to release PCI address on host device);
 
-if (vm-def-nhostdevs  1) {
-memmove(vm-def-hostdevs + i,
-vm-def-hostdevs + i + 1,
-sizeof(*vm-def-hostdevs) *
-(vm-def-nhostdevs - (i + 1)));
-vm-def-nhostdevs--;
-if (VIR_REALLOC_N(vm-def-hostdevs, vm-def-nhostdevs)  0) {
-/* ignore, harmless */
-}
-} else {
-VIR_FREE(vm-def-hostdevs);
-vm-def-nhostdevs = 0;
-}
-if