Commit Graph

14 Commits

Author SHA1 Message Date
Mark McLoughlin
78675b228b Simplify PCI hostdev prepare/re-attach using a pciDeviceList type
The qemuPrepareHostDevices() and qemuDomainReAttachHostDevices()
functions are clutter with a bunch of calls to pciGetDevice() and
pciFreeDevice() obscuring the basic logic.

Add a pciDeviceList type and add a qemuGetPciHostDeviceList() function
to build a list from a domain definition. Use this in prepare/re-attach
fto simplify things and eliminate the multiple pciGetDevice calls.

This is especially useful because in the next patch we need to iterate
the hostdevs list a third time and we also need a list type for keeping
track of active devices.

* src/pci.[ch]: add pciDeviceList type and also a per-device 'managed'
  property

* src/libvirt_private.syms: export the new functions

* src/qemu_driver.c: add qemuGetPciHostDeviceList() and re-write
  qemuPrepareHostDevices() and qemuDomainReAttachHostDevices() to use it
2009-08-18 09:41:57 +01:00
Mark McLoughlin
4954e079c8 Revert changes to allow pciResetDevice() reset multiple devices
It turns out that the previous attempt at this doesn't work well
in the case of hotplug. We need qemuCheckPciHostDevice() to
disallow the reset affecting devices already attach to the guest,
but we still need to avoid double locking the virDomainObjPtr.

This is all getting messy, I've a better idea.

This reverts commit 6318808270 and
c106c8a18c.

* src/qemu_driver.c, src/pci.[ch], src/xen_unified.c,
  src/libvirt_private.syms: revert a bunch of stuff.
2009-08-18 09:41:56 +01:00
Mark McLoughlin
c106c8a18c Check active domain hostdevs before allowing PCI reset
If a PCI device reset causes other devices to be reset, allow it so long
as those other devices are note assigned to another active domain.

Note, we need to take the driver lock qemudNodeDeviceReset() because the
check function will iterate over the domain list.

* src/qemu_conf.c: add qemuCheckPciHostDevice() to iterate over active
  domains checking whether the affected device is assigned

* src/pci.[ch]: add pciDeviceEquals() helper
2009-08-14 08:31:11 +01:00
Mark McLoughlin
6318808270 Allow pciResetDevice() to reset multiple devices
When using a Secondary Bus Reset, all devices on the bus are reset.

Extend the pciResetDevice() API so that a 'check' callback can be
supplied which will verify that it is safe to reset the other devices
on the bus.

The virDomainObjPtr parameter is needed so that when the check function
iterates over the domain list, it can avoid double locking.

* src/pci.[ch]: add a 'check' callback to pciResetDevice(), re-work
  pciIterDevices() to pass the check function to the iter functions,
  use the check function in the bus iterator, return the first unsafe
  device from pciBusCheckOtherDevices() and include its details in
  the bus reset error message.

* src/qemu_driver.c, src/xen_uninified.c: just pass NULL as the
  check function for now
2009-08-14 08:31:11 +01:00
Mark McLoughlin
ebea341856 Improve PCI host device reset error message
Currently, if we are unable to reset a PCI device we return a fairly
generic 'No PCI reset capability available' error message.

Fix that by returning an error from the individual reset messages and
using that error to construct the higher level error mesage.

* src/pci.c: set errors in pciTryPowerManagementReset() and
  pciTrySecondaryBusReset() on failure; use those error messages
  in pciResetDevice(), or explain that no reset support is available
2009-08-14 08:31:11 +01:00
Mark McLoughlin
64a6682b93 Allow PM reset on multi-function PCI devices
It turns out that a PCI Power Management reset only affects individual
functions, and not the whole device.

The PCI Power Management spec talks about resetting the 'device' rather
than the 'function', but Intel's Dexuan Cui informs me that it is
actually a per-function reset.

Also, Yu Zhao has added pci_pm_reset() to the kernel, and it doesn't
reject multi-function devices, so it must be true! :-)

(A side issue is that we could defer the PM reset to the kernel if we
could detect that the kernel has PM reset support, but barring version
number checks we don't have a way to detect that support)

* src/pci.c: remove the pciDeviceContainsOtherFunctions() check from
  pciTryPowerManagementReset() and prefer PM reset over bus reset
  where both are available

Cc: Cui, Dexuan <dexuan.cui@intel.com>
Cc: Yu Zhao <yu.zhao@intel.com>
2009-08-14 08:31:11 +01:00
Mark McLoughlin
a49cf8a57d Fix PCIe FLR detection
PCIe DevCap register is actually 32 bits, not 16 bits. Since FLR is
bit 28, we clearly are failing to detect FLR support.

Known to fix device reset with some SR-IOV devices.

* src/pci.c: fix pciDetectFunctionLevelReset()
2009-07-31 15:41:36 +01:00
Daniel P. Berrange
4a7acedd3c Fix free of unitialized data upon PCI open fail 2009-07-16 13:57:44 +01:00
Daniel Veillard
d879d360eb * src/pci.c: small portability patch
daniel
2009-05-20 13:34:15 +00:00
Daniel P. Berrange
e4073623a6 Support PCI passthrough for Xen 2009-04-03 12:38:52 +00:00
Daniel P. Berrange
3aed672836 Use lseek+saferead/write for pci.c & dont link to qemu driver for nodedevxml2xmltest 2009-03-03 17:00:18 +00:00
Jim Meyering
10e3148f0a avoid file descriptor leak when fd == 0
* src/pci.c (pciGetDevice): Initialize dev->fd to -1, not 0.
(pciFreeDevice): Close fd also when it is 0.
2009-03-03 11:25:52 +00:00
Jim Meyering
8343dcb893 don't leak a file descriptor on failed pciGetDevice call
* src/pci.c (pciIterDevices): Always close dir handle.
2009-03-03 11:25:35 +00:00
Daniel Veillard
d217641314 implements dettach, reattach and reset for PCI devices
* configure.in po/POTFILES.in src/Makefile.am src/libvirt_private.syms
  src/pci.c src/pci.h: Add implementations of dettach, reattach and
  reset for PCI devices, patch by Mark McLoughlin
Daniel
2009-03-02 16:18:11 +00:00