1. 12 8月, 2017 3 次提交
    • L
      util: make virPCIGetNetName() more versatile · b3b5aa75
      Laine Stump 提交于
      A single PCI device may have multiple netdevs associated with it. Each
      of those netdevs will have a different phys_port_id entry in
      sysfs. This patch modifies virPCIGetNetName() to allow selecting one
      of the potential many netdevs in two different ways:
      
      1) by setting the "idx" argument, the caller can select the 1st (0),
      2nd (1), etc. netdev from the PCI device's net subdirectory.
      
      2) If the physPortID arg is set (to a null-terminated string) then
      virPCIGetNetName() returns the netdev that has that phys_port_id in
      the sysfs file of the same name in the netdev's directory.
      b3b5aa75
    • L
      util: Fix const'ness of 1st arg to virPCIGetNetName() · 0dc67e6d
      Laine Stump 提交于
      The first arg isn't modified in the function, so it should be const.
      0dc67e6d
    • L
      util: new function virNetDevGetPhysPortID() · 48f33bb5
      Laine Stump 提交于
      On Linux each network device *can* (but not necessarily *does*) have
      an attribute called phys_port_id which can be read from the file of
      that name in the netdev's sysfs directory. The examples I've seen have
      been a many-digit hexadecimal number (as an ASCII string).
      
      This value can be useful when a single PCI device is associated with
      multiple netdevs (e.g a dual port Mellanox SR-IOV NIC - this card has
      a single PCI Physical Function (PF), and that PF has two netdevs
      associated with it (the "net" subdirectory of the PF in sysfs has two
      links rather than the usual single link to a netdev directory). Each
      of the PF netdevs has a different phys_port_id. The Virtual Functions
      (VF) are similar - the PF (a PCI device) has "n" VFs (also each of
      these is a PCI device), each VF has two netdevs, and each of the VF
      netdevs points back to the VF PCI device (with the "device" entry in
      its sysfs directory) as well as having a phys_port_id matching the PF
      netdev it is associated with.
      
      virNetDevGetPhysPortID() simply attempts to read the phys_port_id for
      the given netdev and return it to the caller. If this particular
      netdev driver doesn't support phys_port_id, it returns NULL (*not* a
      NULL-terminated string, but a NULL pointer) but still counts it as a
      success.
      48f33bb5
  2. 08 8月, 2017 1 次提交
    • J
      introduce virConfReadString · e9f32227
      Ján Tomko 提交于
      Rewrite virConfReadMem to take a null-terminated string.
      All the callers were calling strlen on it anyway.
      e9f32227
  3. 03 8月, 2017 2 次提交
  4. 01 8月, 2017 1 次提交
    • M
      virCgroupValidateMachineGroup: Don't free @machinename · 3e609bf4
      Michal Privoznik 提交于
      We are given a string in @machinename, we never allocate it, just
      merely use it for reading. We should not free it otherwise it
      leads to double free:
      
      ==32191== Thread 17:
      ==32191== Invalid free() / delete / delete[] / realloc()
      ==32191==    at 0x4C2D1A0: free (vg_replace_malloc.c:530)
      ==32191==    by 0x54BBB84: virFree (viralloc.c:582)
      ==32191==    by 0x2BC04499: qemuProcessStop (qemu_process.c:6313)
      ==32191==    by 0x2BC500FF: processMonitorEOFEvent (qemu_driver.c:4724)
      ==32191==    by 0x2BC502FC: qemuProcessEventHandler (qemu_driver.c:4769)
      ==32191==    by 0x5550640: virThreadPoolWorker (virthreadpool.c:167)
      ==32191==    by 0x554FBCF: virThreadHelper (virthread.c:206)
      ==32191==    by 0x8F913D3: start_thread (in /lib64/libpthread-2.23.so)
      ==32191==    by 0x928DE3C: clone (in /lib64/libc-2.23.so)
      ==32191==  Address 0x31893d70 is 0 bytes inside a block of size 1,100 free'd
      ==32191==    at 0x4C2D1A0: free (vg_replace_malloc.c:530)
      ==32191==    by 0x54BBB84: virFree (viralloc.c:582)
      ==32191==    by 0x54C1936: virCgroupValidateMachineGroup (vircgroup.c:343)
      ==32191==    by 0x54C4B29: virCgroupNewDetectMachine (vircgroup.c:1550)
      ==32191==    by 0x2BBDDA29: qemuConnectCgroup (qemu_cgroup.c:972)
      ==32191==    by 0x2BC05DA7: qemuProcessReconnect (qemu_process.c:6822)
      ==32191==    by 0x554FBCF: virThreadHelper (virthread.c:206)
      ==32191==    by 0x8F913D3: start_thread (in /lib64/libpthread-2.23.so)
      ==32191==    by 0x928DE3C: clone (in /lib64/libc-2.23.so)
      ==32191==  Block was alloc'd at
      ==32191==    at 0x4C2BE80: malloc (vg_replace_malloc.c:298)
      ==32191==    by 0x4C2E35F: realloc (vg_replace_malloc.c:785)
      ==32191==    by 0x54BB492: virReallocN (viralloc.c:245)
      ==32191==    by 0x54BEDF2: virBufferGrow (virbuffer.c:150)
      ==32191==    by 0x54BF3B9: virBufferVasprintf (virbuffer.c:408)
      ==32191==    by 0x54BF324: virBufferAsprintf (virbuffer.c:381)
      ==32191==    by 0x55BB271: virDomainGenerateMachineName (domain_conf.c:27078)
      ==32191==    by 0x2BBD5B8F: qemuDomainGetMachineName (qemu_domain.c:9595)
      ==32191==    by 0x2BBDD9B4: qemuConnectCgroup (qemu_cgroup.c:966)
      ==32191==    by 0x2BC05DA7: qemuProcessReconnect (qemu_process.c:6822)
      ==32191==    by 0x554FBCF: virThreadHelper (virthread.c:206)
      ==32191==    by 0x8F913D3: start_thread (in /lib64/libpthread-2.23.so)
      
      Moreover, make the @machinename 'const char *' to mark it
      explicitly that we are not changing the passed string.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      3e609bf4
  5. 27 7月, 2017 2 次提交
  6. 26 7月, 2017 1 次提交
    • P
      util: introduce virFileCache · ac3eb2ab
      Pavel Hrdina 提交于
      The new virFileCache will nicely handle the caching logic for any data
      that we would like to cache.  For each type of data we will just need
      to implement few handlers that will take care of creating, validating,
      loading and saving the cached data.
      
      The cached data must be an instance of virObject.
      
      Currently we cache QEMU capabilities which will start using
      virFileCache.
      Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
      Reviewed-by: NJiri Denemark <jdenemar@redhat.com>
      ac3eb2ab
  7. 25 7月, 2017 2 次提交
  8. 24 7月, 2017 6 次提交
  9. 20 7月, 2017 4 次提交
  10. 19 7月, 2017 1 次提交
    • M
      virFileInData: Report an error if unable to reposition file · 8ae82e67
      Michal Privoznik 提交于
      The purpose of this function is to tell if the current position
      in given FD is in data section or a hole and how much bytes there
      is remaining until the end of the section. This is achieved by
      couple of lseeks(). The most important part is that we reposition
      the FD back, so that the position is unchanged from the caller
      POV. And until now the final lseek() back to the original
      position was done with no check for errors. And I was convinced
      that that's okay since nothing can go wrong. However, review
      feedback from a related series persuaded me, that it's better to
      be safe than sorry. Therefore, lets check if the final lseek()
      succeeded and if it doesn't report an error.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      8ae82e67
  11. 14 7月, 2017 3 次提交
  12. 13 7月, 2017 3 次提交
    • D
      Revert "Prevent more compiler optimization of mockable functions" · 407a281a
      Daniel P. Berrange 提交于
      This reverts commit e4b980c8.
      
      When a binary links against a .a archive (as opposed to a shared library),
      any symbols which are marked as 'weak' get silently dropped. As a result
      when the binary later runs, those 'weak' functions have an address of
      0x0 and thus crash when run.
      
      This happened with virtlogd and virtlockd because they don't link to
      libvirt.so, but instead just libvirt_util.a and libvirt_rpc.a. The
      virRandomBits symbols was weak and so left out of the virtlogd &
      virtlockd binaries, despite being required by virHashTable functions.
      
      Various other binaries like libvirt_lxc, libvirt_iohelper, etc also
      link directly to .a files instead of libvirt.so, so are potentially
      at risk of dropping symbols leading to a later runtime crash.
      
      This is normal linker behaviour because a weak symbol is not treated
      as undefined, so nothing forces it to be pulled in from the .a You
      have to force the linker to pull in weak symbols using -u$SYMNAME
      which is not a practical approach.
      
      This risk is silent bad linkage that affects runtime behaviour is
      not acceptable for a fix that was merely trying to fix the test
      suite. So stop using __weak__ again.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      407a281a
    • M
      util: Don't leak linksrc in vircgroup · 1701ba6f
      Martin Kletzander 提交于
      Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
      1701ba6f
    • J
      Avoid hidden cgroup mount points · dacd160d
      Juan Hernandez 提交于
      Currently the scan of the /proc/mounts file used to find cgroup mount
      points doesn't take into account that mount points may hidden by other
      mount points. For, example in certain Kubernetes environments the
      /proc/mounts contains the following lines:
      
        cgroup /sys/fs/cgroup/net_prio,net_cls cgroup ...
        tmpfs /sys/fs/cgroup tmpfs ...
        cgroup /sys/fs/cgroup/net_cls,net_prio cgroup ...
      
      In this particular environment the first mount point is hidden by the
      second one. The correct mount point is the third one, but libvirt will
      never process it because it only checks the first mount point for each
      controller (net_cls in this case). So libvirt will try to use the first
      mount point, which doesn't actually exist, and the complete detection
      process will fail.
      
      To avoid that issue this patch changes the virCgroupDetectMountsFromFile
      function so that when there are duplicates it takes the information from
      the last line in /proc/mounts. This requires removing the previous
      explicit condition to skip duplicates, and adding code to free the
      memory used by the processing of duplicated lines.
      
      Related-To: https://bugzilla.redhat.com/1468214
      Related-To: https://github.com/kubevirt/libvirt/issues/4Signed-off-by: NJuan Hernandez <jhernand@redhat.com>
      dacd160d
  13. 11 7月, 2017 11 次提交