1. 20 1月, 2014 2 次提交
    • J
      pci: Fix failure paths in detach · d8ab981b
      Jiri Denemark 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=1046919
      
      Since commit v0.9.0-47-g4e8969eb (released in 0.9.1) some failures during
      device detach were reported to callers of virPCIDeviceBindToStub as
      success. For example, even though a device seemed to be detached
      
          virsh # nodedev-detach pci_0000_07_05_0 --driver vfio
          Device pci_0000_07_05_0 detached
      
      one could find similar message in libvirt logs:
      
          Failed to bind PCI device '0000:07:05.0' to vfio-pci: No such device
      
      This patch fixes these paths and also avoids overwriting real errors
      with errors encountered during a cleanup phase.
      d8ab981b
    • J
      pci: Make reattach work for unbound devices · c982e5e8
      Jiri Denemark 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=1046919
      
      When a PCI device is not bound to any driver, reattach should just
      trigger driver probe rather than failing with
      
          Invalid device 0000:00:19.0 driver file
          /sys/bus/pci/devices/0000:00:19.0/driver is not a symlink
      
      While virPCIDeviceGetDriverPathAndName was documented to return success
      and NULL driver and path when a device is not attached to any driver but
      didn't do so. Thus callers could not distinguish unbound devices from
      failures.
      Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
      c982e5e8
  2. 08 1月, 2014 2 次提交
    • O
      util: Use new array management macros · 6f989485
      Osier Yang 提交于
      Like commit 94a26c7e from Eric Blake, the old fuzzy code should
      be replaced by the new array management macros now.
      
      And the type of scsi->count should be changed into "size_t", and
      thus virSCSIDeviceListCount should return size_t instead, similar
      for vir{PCI,USB}DeviceListCount.
      6f989485
    • T
      Read PCI class from sysfs class file instead of config space. · 9a3d7a47
      Thadeu Lima de Souza Cascardo 提交于
      When determining if a device is behind a PCI bridge, the PCI device
      class is checked by reading the config space. However, there are some
      devices which have the wrong class on the config space, but the class is
      initialized by Linux correctly as a PCI BRIDGE. This class can be read
      by the sysfs file '/sys/bus/pci/devices/xxxx:xx:xx.x/class'.
      
      One example of such bridge is IBM PCI Bridge 1014:03b9, which is
      identified as a Host Bridge when reading the config space.
      Signed-off-by: NThadeu Lima de Souza Cascardo <cascardo@linux.vnet.ibm.com>
      9a3d7a47
  3. 21 11月, 2013 1 次提交
    • E
      maint: fix comma style issues: util · c7c84fa5
      Eric Blake 提交于
      Most of our code base uses space after comma but not before;
      fix the remaining uses before adding a syntax check.
      
      * src/util/vircommand.c: Consistently use commas.
      * src/util/virlog.c: Likewise.
      * src/util/virnetdevbandwidth.c: Likewise.
      * src/util/virnetdevmacvlan.c: Likewise.
      * src/util/virnetdevvportprofile.c: Likewise.
      * src/util/virnetlink.c: Likewise.
      * src/util/virpci.c: Likewise.
      * src/util/virsysinfo.c: Likewise.
      * src/util/virusb.c: Likewise.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      c7c84fa5
  4. 15 11月, 2013 1 次提交
  5. 08 11月, 2013 2 次提交
    • L
      pci: properly handle out-of-order SRIOV virtual functions · 88c1fcd5
      Laine Stump 提交于
      This resolves:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=1025397
      
      When virPCIGetVirtualFunctions created the list of an SRIOV Physical
      Function's (PF) Virtual Functions (VF), it had assumed that the order
      of "virtfn*" links returned by readdir() from the PF's sysfs directory
      was already in the correct order. Experience has shown that this is
      not always the case - it can be in alphabetical order (which would
      e.g. place virtfn11 before virtfn2) or even some seemingly random
      order (see the example in the bugzilla report)
      
      This results in 1) incorrect assumptions made by consumers of the
      output of the virt_functions list of virsh nodedev-dumpxml, and 2)
      setting MAC address and vlan tag on the wrong VF (since libvirt uses
      netlink to set mac address and vlan tag, netlink requires the VF#, and
      the function virPCIGetVirtualFunctionIndex() returns the wrong index
      due to the improperly ordered VF list).
      
      The solution provided by this patch is for virPCIGetVirtualFunctions
      to no longer scan the entire device directory in its natural order,
      but instead to check for links individually by name "virtfn%d" where
      %d starts at 0 and increases with each success. Since VFs are created
      contiguously by the kernel, this will guarantee that all VFs are
      found, and placed in the arry in the correct order.
      
      One note of use to the uninitiated is that VIR_APPEND_ELEMENT always
      either increments *num_virtual_functions or fails, so no this isn't an
      endless loop.
      
      (NB: the SRIOV_* defines at the top of virpci.c were removed
      because they are unnecessary and/or not used.)
      88c1fcd5
    • L
      util: use size_t instead of unsigned int for num_virtual_functions · 89e2a6c8
      Laine Stump 提交于
      This is a prerequisite to the fix for the fix to:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=1025397
      
      num_virtual_functions needs to be size_t in order to use the
      VIR_APPEND_ELEMENT macro.
      89e2a6c8
  6. 05 11月, 2013 1 次提交
  7. 16 9月, 2013 1 次提交
  8. 11 9月, 2013 1 次提交
  9. 18 7月, 2013 1 次提交
    • J
      virAsprintf: correctly check return value · 23e938ee
      Ján Tomko 提交于
      When virAsprintf was changed from a function to a macro
      reporting OOM error in dc6f2dad, it was documented as returning
      0 on success. This is incorrect, it returns the number of bytes
      written as asprintf does.
      
      Some of the functions were converted to use virAsprintf's return
      value directly, changing the return value on success from 0 to >= 0.
      
      For most of these, this is not a problem, but the change in
      virPCIDriverDir breaks PCI passthrough.
      
      The return value check in virhashtest pre-dates virAsprintf OOM
      conversion.
      
      vmwareMakePath seems to be unused.
      23e938ee
  10. 15 7月, 2013 2 次提交
    • L
      pci: make virPCIDeviceReset more autonomous · 9e37f57f
      Laine Stump 提交于
      I recently patches the callers to virPCIDeviceReset() to not call it
      if the current driver for a device was vfio-pci (since that driver
      will always reset the device itself when appropriate. At the time, Dan
      Berrange suggested that I could instead modify virPCIDeviceReset
      to check the currently bound driver for the device, and decide
      for itself whether or not to go ahead with the reset.
      
      This patch removes the previously added checks, and replaces them with
      a check down in virPCIDeviceReset(), as suggested.
      
      The functional difference here is that previously we were deciding
      based on either the hostdev configuration or the value of
      stubDriverName in the virPCIDevice object, but now we are actually
      comparing to the "driver" link in the device's sysfs entry
      directly. In practice, both should be the same.
      9e37f57f
    • L
      pci: reorder static functions · 333a2a72
      Laine Stump 提交于
      virPCIDeviceGetDriverPathAndName is a static function that will need
      to be called by another function that occurs above it in the
      file. This patch reorders the static functions so that a forward
      declaration isn't needed.
      333a2a72
  11. 11 7月, 2013 3 次提交
  12. 10 7月, 2013 2 次提交
  13. 01 7月, 2013 1 次提交
    • L
      pci: initialize virtual_functions array pointer to avoid segfault · 2c2525ab
      Laine Stump 提交于
      This fixes https://bugzilla.redhat.com/show_bug.cgi?id=971325
      
      The problem was that if virPCIGetVirtualFunctions was given the name
      of a non-existent interface, it would return to its caller without
      initializing the pointer to the array of virtual functions to NULL,
      and the caller (virNetDevGetVirtualFunctions) would try to VIR_FREE()
      the invalid pointer.
      
      The final error message before the crash would be:
      
       virPCIGetVirtualFunctions:2088 :
        Failed to open dir '/sys/class/net/eth2/device':
        No such file or directory
      
      In this patch I move the initialization in virPCIGetVirtualFunctions()
      to the begining of the function, and also do an explicit
      initialization in virNetDevGetVirtualFunctions, just in case someone
      in the future adds code into that function prior to the call to
      virPCIGetVirtualFunctions.
      2c2525ab
  14. 28 6月, 2013 1 次提交
    • L
      util: fix build error on non-Linux systems · a7578222
      Laine Stump 提交于
      Building on FreeBSD had this linker error:
      
      /work/a/ports/devel/libvirt/work/libvirt-1.1.0/src/.libs/libvirt.so:
         undefined reference to `virPCIDeviceAddressParse'
      
      This was caused by the new use of virPCIDeviceAddressParse in a
      portion of virpci.c that wasn't linux-only (in commit 72c029d8). The
      problem was that virPCIDeviceAddressParse had originally been defined
      inside #ifdef _linux (because it was only used by another function
      that was inside the same ifdef).
      
      The solution is to move it out to the part of virpci.c that is
      compiled on all platforms.
      
      (Because the portion that was "moved" was 40-50 lines, but only moved
      up by 15 lines, the diff for the patch is less than non-informative -
      rather than showing that part that I moved, it shows the bit that was
      previously before the moved part, and now sits *after* it.)
      a7578222
  15. 27 6月, 2013 1 次提交
    • L
      pci: new iommu_group functions · 72c029d8
      Laine Stump 提交于
      Any device which belongs to an "IOMMU group" (used by vfio) will
      have links to all devices of its group listed in
      /sys/bus/pci/$device/iommu_group/devices;
      /sys/bus/pci/$device/iommu_group is actually a link to
      /sys/kernel/iommu_groups/$n, where $n is the group number (there
      will be a corresponding device node at /dev/vfio/$n once the
      devices are bound to the vfio-pci driver)
      
      The following functions are added:
      
      virPCIDeviceGetIOMMUGroupList
      
        Gets a virPCIDeviceList with one virPCIDeviceList for each device
        in the same IOMMU group as the provided virPCIDevice (a copy of the
        original device object is included in the list.
      
      virPCIDeviceAddressIOMMUGroupIterate
      
        Calls the function @actor once for each device in the group that
        contains the given virPCIDeviceAddress.
      
      virPCIDeviceAddressGetIOMMUGroupAddresses
      
        Fills in a virPCIDeviceAddressPtr * with an array of
        virPCIDeviceAddress, one for each device in the iommu group of the
        provided virPCIDeviceAddress (including a copy of the original).
      
      virPCIDeviceAddressGetIOMMUGroupNum
      
        Returns the group number as an int (a valid group number will always
        be 0 or greater).  If there is no iommu_group link in the device's
        directory (usually indicating that vfio isn't loaded), -2 will be
        returned. On any real error, -1 will be returned.
      72c029d8
  16. 26 6月, 2013 7 次提交
    • L
      pci: eliminate leak in OOM condition · 2a2739a8
      Laine Stump 提交于
      The "fix" I pushed a few commits ago would still leak a virPCIDevice
      in case of an OOM error. Although it's inconsequential in practice,
      this patch satisfies my OCD.
      2a2739a8
    • L
      pci: virPCIDeviceListAddCopy API · 0e89a543
      Laine Stump 提交于
      Make a copy of the device and add the copy to the
      list. (virPCIDeviceListAdd() adds the original object to the list
      instead).
      0e89a543
    • L
      pci: update stubDriver name in virPCIDeviceBindToStub · 6e8003ad
      Laine Stump 提交于
      If the device is bound to a stub driver different from what is saved
      in the virPCIDevice's stubDriver attribute, update it.
      6e8003ad
    • L
      pci: eliminate repetitive path constructions in virPCIDeviceBindToStub · c13dddaf
      Laine Stump 提交于
      The same strings were being re-created multiple times just to save
      declaring a new variable. In the meantime, the use of the generic
      variable names led to confusion when trying to follow the code. This
      patch creates strings for:
      
       stubDriverName  (was called "driver" in original args)
       stubDriverPath  ("/sys/bus/pci/drivers/${stubDriverName}")
       driverLink      ("${device}/driver")
       oldDriverName   (the final component of path linked to by
                        "${device}/driver")
       oldDriverPath   ("/sys/bus/pci/drivers/${oldDriverName}")
      
      then re-uses them as necessary.
      c13dddaf
    • L
      pci: rename virPCIParseDeviceAddress and make it public · 31a4a679
      Laine Stump 提交于
      This function has utility outside of virpci.c, so make it public.
      
      Also the name didn't fit convention, so change it to
      virPCIDeviceAddressParse.
      31a4a679
    • L
      pci: rename virPCIDeviceGetVFIOGroupDev to virPCIDeviceGetIOMMUGroupDev · 1d829e13
      Laine Stump 提交于
      I realized after the fact that it's probably better in the long run to
      give this function a name that matches the name of the link used in
      sysfs to hold the group (iommu_group).
      
      I'm changing it now because I'm about to add several more functions
      that deal with iommu groups.
      1d829e13
    • L
      pci: eliminate unused driver arg from virPCIDeviceDetach · ee1d1f3b
      Laine Stump 提交于
      The driver arg to virPCIDeviceDetach is no longer used (the name of the stub driver is now set in the virPCIDevice object, and virPCIDeviceDetach retrieves it from there). Remove it.
      ee1d1f3b
  17. 25 6月, 2013 5 次提交
    • L
      pci: make virPCIDeviceDetach consistent in behavior · 9b4a6666
      Laine Stump 提交于
      virPCIDeviceDetach would previously sometimes consume the input device
      object (to put it on the inactive list) and sometimes not. Avoiding
      memory leaks required checking beforehand to see if the device was
      already on the list, and freeing the device object in the caller only
      if there wasn't already an identical object on the inactive list.
      
      This patch makes it consistent - virPCIDeviceDetach will *never*
      consume the input virPCIDevice object; if it needs to put one on the
      inactive list, it will create a copy and put *that* on the list. This
      way the caller knows that it is always their responsibility to free
      the device object they created.
      9b4a6666
    • L
      pci: eliminate memory leak in virPCIDeviceReattach · f962e8b6
      Laine Stump 提交于
      virPCIDeviceReattach was making the assumption that the dev object
      given to it was one and the same with the dev object on the
      inactiveDevs list. If that had been the case, it would not need to
      free the dev object it removed from the inactive list, because the
      caller of virPCIDeviceReattach always frees the dev object that it
      passes in. Since the dev object passed in is *never* the same object
      that's on the list (it is a different object with the same name and
      attributes, created just for the purpose of searching for the actual
      object), simply doing a "ListSteal" to remove the object from the list
      results in one leaked object; we need to actually free the object
      after removing it from the list.
      f962e8b6
    • L
      pci: new utility functions · 50a8d850
      Laine Stump 提交于
      * virPCIDeviceFindByIDs - find a device on a list w/o creating an object
          This makes searching for an existing device on a list lighter weight.
      
      * virPCIDeviceCopy - make a copy of an existing virPCIDevice object.
      
      * virPCIDeviceGetDriverPathAndName - construct new strings containing
          1) the name of the driver bound to this device.
          2) the full path to the sysfs config for that driver.
          (This code was lifted from virPCIDeviceUnbindFromStub, and replaced
          there with a call to this new function).
      50a8d850
    • L
      pci: change stubDriver from const char* to char* · 53e52b4a
      Laine Stump 提交于
      Previously stubDriver was always set from a string literal, so it was
      okay to use a const char * that wasn't freed when the virPCIDevice was
      freed. This will not be the case in the near future, so it is now a
      char* that is allocated in virPCIDeviceSetStubDriver() and freed
      during virPCIDeviceFree().
      53e52b4a
    • L
      syntax: virPCIDeviceFree is also a NOP for NULL args · d80d0d5d
      Laine Stump 提交于
      add it to the syntax-check list and fix the one offending caller.
      d80d0d5d
  18. 06 6月, 2013 1 次提交
  19. 24 5月, 2013 1 次提交
  20. 02 5月, 2013 2 次提交
    • M
      virutil: Move string related functions to virstring.c · 7c9a2d88
      Michal Privoznik 提交于
      The source code base needs to be adapted as well. Some files
      include virutil.h just for the string related functions (here,
      the include is substituted to match the new file), some include
      virutil.h without any need (here, the include is removed), and
      some require both.
      7c9a2d88
    • L
      pci: autolearn name of stub driver, remove from arglist · e482693b
      Laine Stump 提交于
      virPCIDeviceReattach and virPCIDeviceUnbindFromStub (called by
      virPCIDeviceReattach) had previously required the name of the stub
      driver as input. This is unnecessary, because the name of the driver
      the device is currently bound to can be found by looking at the link:
      
        /sys/bus/pci/dddd:bb:ss.ff/driver
      
      Instead of requiring that the name of the expected stub driver name
      and only unbinding if that one name is matched, we no longer take a
      driver name in the arglist for either of these
      functions. virPCIDeviceUnbindFromStub just compares the name of the
      currently bound driver to a list of "well known" stubs (right now
      contains "pci-stub" and "vfio-pci" for qemu, and "pciback" for xen),
      and only performs the unbind if it's one of those devices.
      
      This allows virsh nodedevice-reattach to work properly across a
      libvirtd restart, and fixes a couple of cases where we were
      erroneously still hard-coding "pci-stub" as the drive name.
      
      For some unknown reason, virPCIDeviceReattach had been calling
      modprobe on the stub driver prior to unbinding the device. This was
      problematic because we no longer know the name of the stub driver in
      that function. However, it is pointless to probe for the stub driver
      at that time anyway - because the device is bound to the stub driver,
      we are guaranteed that it is already loaded, and so that call to
      modprobe has been removed.
      e482693b
  21. 26 4月, 2013 2 次提交
    • L
      util: new function virPCIDeviceGetVFIOGroupDev · b210208f
      Laine Stump 提交于
      Given a virPCIDevice, this function returns the path for the device
      that controls the vfio group the device belongs to,
      e.g. "/dev/vfio/15".
      b210208f
    • L
      pci: keep a stubDriver in each virPCIDevice · be64199e
      Laine Stump 提交于
      This can be set when the virPCIDevice is created and placed on a list,
      then used later when traversing the list to determine which stub
      driver to bind/unbind for managed devices.
      
      The existing Detach and Attach functions' signatures haven't been
      changed (they still accept a stub driver name in the arg list), but if
      the arg list has NULL for stub driver and one is available in the
      device's object, that will be used. (we may later deprecate and remove
      the arg from those functions).
      be64199e