1. 04 6月, 2012 1 次提交
  2. 31 5月, 2012 2 次提交
    • W
      command: check for fork error before closing fd · 746ff701
      Wen Congyang 提交于
      We should not set *outfd or *errfd if virExecWithHook() failed
      because the caller may close these fds.
      
      Bug present since v0.4.5 (commit 60ed1d2a).
      746ff701
    • E
      command: avoid double close bugs · da831afc
      Eric Blake 提交于
      KAMEZAWA Hiroyuki reported a nasty double-free bug when virCommand
      is used to convert a string into input to a child command.  The
      problem is that the poll() loop of virCommandProcessIO would close()
      the write end of the pipe in order to let the child see EOF, then
      the caller virCommandRun() would also close the same fd number, with
      the second close possibly nuking an fd opened by some other thread
      in the meantime.  This in turn can have all sorts of bad effects.
      
      The bug has been present since the introduction of virCommand in
      commit f16ad06f.
      
      This is based on his first attempt at a patch, at
      https://bugzilla.redhat.com/show_bug.cgi?id=823716
      
      * src/util/command.c (_virCommand): Drop inpipe member.
      (virCommandProcessIO): Add argument, to avoid closing caller's fd
      without informing caller.
      (virCommandRun, virCommandNewArgs): Adjust clients.
      da831afc
  3. 30 5月, 2012 1 次提交
    • M
      virCommand: Extend debug message for handshake · 7454849e
      Michal Privoznik 提交于
      Currently, we are logging only one side of pipes we
      create in virCommandRequireHandshake(); This is enough
      in cases where pipe2() returns two consecutive FDs. However,
      it is not guaranteed and it may return any FDs.
      Therefore, it's wise to log the other ends as well.
      7454849e
  4. 29 5月, 2012 1 次提交
  5. 28 5月, 2012 3 次提交
    • D
      Santize the reporting of VIR_ERR_INVALID_ERROR · d91f3ef4
      Daniel P. Berrange 提交于
      To ensure consistent error reporting of invalid arguments,
      provide a number of predefined helper methods & macros.
      
       - An arg which must not be NULL:
      
         virCheckNonNullArgReturn(argname, retvalue)
         virCheckNonNullArgGoto(argname, label)
      
       - An arg which must be NULL
      
         virCheckNullArgGoto(argname, label)
      
       - An arg which must be positive (ie 1 or greater)
      
         virCheckPositiveArgGoto(argname, label)
      
       - An arg which must not be 0
      
         virCheckNonZeroArgGoto(argname, label)
      
       - An arg which must be zero
      
         virCheckZeroArgGoto(argname, label)
      
       - An arg which must not be negative (ie 0 or greater)
      
         virCheckNonNegativeArgGoto(argname, label)
      
      * src/libvirt.c, src/libvirt-qemu.c,
        src/nodeinfo.c, src/datatypes.c: Update to use
        virCheckXXXX macros
      * po/POTFILES.in: Add libvirt-qemu.c and virterror_internal.h
      * src/internal.h: Define macros for checking invalid args
      * src/util/virterror_internal.h: Define macros for reporting
        invalid args
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      d91f3ef4
    • D
      Add impl of APIs to get user directories on Win32 · 076f2006
      Daniel P. Berrange 提交于
      Add an impl of +virGetUserRuntimeDirectory, virGetUserCacheDirectory
      virGetUserConfigDirectory and virGetUserDirectory for Win32 platform.
      Also create stubs for non-Win32 platforms which lack getpwuid_r()
      
      In adding these two helpers were added virFileIsAbsPath and
      virFileSkipRoot, along with some macros VIR_FILE_DIR_SEPARATOR,
      VIR_FILE_DIR_SEPARATOR_S, VIR_FILE_IS_DIR_SEPARATOR,
      VIR_FILE_PATH_SEPARATOR, VIR_FILE_PATH_SEPARATOR_S
      
      All this code was adapted from GLib2 under terms of LGPLv2+ license.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      076f2006
    • D
      Remove uid param from directory lookup APIs · 517368a3
      Daniel P. Berrange 提交于
      Remove the uid param from virGetUserConfigDirectory,
      virGetUserCacheDirectory, virGetUserRuntimeDirectory,
      and virGetUserDirectory
      
      These functions were universally called with the
      results of getuid() or geteuid(). To make it practical
      to port to Win32, remove the uid parameter and hardcode
      geteuid()
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      517368a3
  6. 24 5月, 2012 2 次提交
  7. 22 5月, 2012 1 次提交
    • E
      virBuffer: add way to trim back extra text · cdb87b1c
      Eric Blake 提交于
      I'm tired of writing:
      
      bool sep = false;
      while (...) {
          if (sep)
             virBufferAddChar(buf, ',');
          sep = true;
          virBufferAdd(buf, str);
      }
      
      This makes it easier, allowing one to write:
      
      while (...)
          virBufferAsprintf(buf, "%s,", str);
      virBufferTrim(buf, ",", -1);
      
      to trim any remaining comma.
      
      * src/util/buf.h (virBufferTrim): Declare.
      * src/util/buf.c (virBufferTrim): New function.
      * tests/virbuftest.c (testBufTrim): Test it.
      cdb87b1c
  8. 18 5月, 2012 2 次提交
    • E
      build: fix virnetlink on glibc 2.11 · e8314e78
      Eric Blake 提交于
      We were being lazy - virnetlink.c was getting uint32_t as a
      side-effect from glibc 2.14's <unistd.h>, but older glibc 2.11
      does not provide uint32_t from <unistd.h>.  In fact, POSIX states
      that <unistd.h> need only provide intptr_t, not all of <stdint.h>,
      so the bug really is ours.  Reported by Jonathan Alescio.
      
      * src/util/virnetlink.h: Include <stdint.h>.
      e8314e78
    • H
      Adds support to param 'vcpu_time' in qemu_driver. · fe0aac05
      Hu Tao 提交于
      This involves setting the cpuacct cgroup to a per-vcpu granularity,
      as well as summing the each vcpu accounting into a common array.
      Now that we are reading more than one cgroup file, we double-check
      that cpus weren't hot-plugged between reads to invalidate our
      summing.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      fe0aac05
  9. 17 5月, 2012 1 次提交
  10. 16 5月, 2012 4 次提交
    • E
      build: fix recent syntax-check breakage · 3337ba6d
      Eric Blake 提交于
      The use of readlink() in lxc_container.c is intentional; we don't
      want an absolute pathname there.
      
      * src/util/cgroup.h (VIR_CGROUP_SYSFS_MOUNT): Indent properly.
      * cfg.mk (exclude_file_name_regexp--sc_prohibit_readlink): Add
      exemption.
      3337ba6d
    • D
      Remount cgroups controllers after setting up new /sys in LXC · a8c0b2fe
      Daniel P. Berrange 提交于
      Normal practice is for cgroups controllers to be mounted at
      /sys/fs/cgroup. When setting up a container, /sys is mounted
      with a new sysfs instance, thus we must re-mount all the
      cgroups controllers. The complexity is that we must mount
      them in the same layout as the host OS. ie if 'cpu' and 'cpuacct'
      were mounted at the same location in the host we must preserve
      this in the container. Also if any controllers are co-located
      we must setup symlinks from the individual controller name to
      the co-located mount-point
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      a8c0b2fe
    • D
      Remove redundant trailing slash in user dir paths · b3567ef3
      Daniel P. Berrange 提交于
      Callers of virGetUser{Config,Runtime,Cache}Directory all
      append further path component. We should not be
      adding a trailing slash in the return path otherwise we
      get paths containing '//'
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      b3567ef3
    • D
      Allow stack traces to be included with log messages · 54856395
      Daniel P. Berrange 提交于
      Sometimes it is useful to see the callpath for log messages.
      This change enhances the log filter syntax so that stack traces
      can be show by setting '1:+NAME' instead of '1:NAME'.
      
      This results in output like:
      
      2012-05-09 14:18:45.136+0000: 13314: debug : virInitialize:414 : register drivers
      /home/berrange/src/virt/libvirt/src/.libs/libvirt.so.0(virInitialize+0xd6)[0x7f89188ebe86]
      /home/berrange/src/virt/libvirt/tools/.libs/lt-virsh[0x431921]
      /lib64/libc.so.6(__libc_start_main+0xf5)[0x3a21e21735]
      /home/berrange/src/virt/libvirt/tools/.libs/lt-virsh[0x40a279]
      
      2012-05-09 14:18:45.136+0000: 13314: debug : virRegisterDriver:775 : driver=0x7f8918d02760 name=Test
      /home/berrange/src/virt/libvirt/src/.libs/libvirt.so.0(virRegisterDriver+0x6b)[0x7f89188ec717]
      /home/berrange/src/virt/libvirt/src/.libs/libvirt.so.0(+0x11b3ad)[0x7f891891e3ad]
      /home/berrange/src/virt/libvirt/src/.libs/libvirt.so.0(virInitialize+0xf3)[0x7f89188ebea3]
      /home/berrange/src/virt/libvirt/tools/.libs/lt-virsh[0x431921]
      /lib64/libc.so.6(__libc_start_main+0xf5)[0x3a21e21735]
      /home/berrange/src/virt/libvirt/tools/.libs/lt-virsh[0x40a279]
      
      * docs/logging.html.in: Document new syntax
      * configure.ac: Check for execinfo.h
      * src/util/logging.c, src/util/logging.h: Add support for
        stack traces
      * tests/testutils.c: Adapt to API change
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      54856395
  11. 14 5月, 2012 1 次提交
    • W
      Use XDG Base Directories instead of storing in home directory · 32a9aac2
      William Jon McCann 提交于
      As defined in:
      http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
      
      This offers a number of advantages:
       * Allows sharing a home directory between different machines, or
      sessions (eg. using NFS)
       * Cleanly separates cache, runtime (eg. sockets), or app data from
      user settings
       * Supports performing smart or selective migration of settings
      between different OS versions
       * Supports reseting settings without breaking things
       * Makes it possible to clear cache data to make room when the disk
      is filling up
       * Allows us to write a robust and efficient backup solution
       * Allows an admin flexibility to change where data and settings are stored
       * Dramatically reduces the complexity and incoherence of the
      system for administrators
      32a9aac2
  12. 09 5月, 2012 1 次提交
  13. 08 5月, 2012 4 次提交
    • L
      util: set src_pid for virNetlinkCommand when appropriate · cc073771
      Laine Stump 提交于
      Until now, the nl_pid of the source address of every message sent by
      virNetlinkCommand has been set to the value of getpid(). Most of the
      time this doesn't matter, and in the one case where it does
      (communication with lldpad), it previously was the proper thing to do,
      because the netlink event service (which listens on a netlink socket
      for unsolicited messages from lldpad) coincidentally always happened
      to bind with a local nl_pid == getpid().
      
      With the fix for:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=816465
      
      that particular nl_pid is now effectively a reserved value, so the
      netlink event service will always bind to something else
      (coincidentally "getpid() + (1 << 22)", but it really could be
      anything). The result is that communication between lldpad and
      libvirtd is broken (lldpad gets a "disconnected" error when it tries
      to send a directed message).
      
      The solution to this problem caused by a solution, is to query the
      netlink event service's nlhandle for its "local_port", and send that
      as the source nl_pid (but only when sending to lldpad, of course - in
      other cases we maintain the old behavior of sending getpid()).
      
      There are two cases where a message is being directed at lldpad - one
      in virNetDevLinkDump, and one in virNetDevVPortProfileOpSetLink.
      
      The case of virNetDevVPortProfileOpSetLink is simplest to explain -
      only if !nltarget_kernel, i.e. the message isn't targetted for the
      kernel, is the dst_pid set (by calling
      virNetDevVPortProfileGetLldpadPid()), so only in that case do we call
      virNetlinkEventServiceLocalPid() to set src_pid.
      
      For virNetDevLinkDump, it's a bit more complicated. The call to
      virNetDevVPortProfileGetLldpadPid() was effectively up one level (in
      virNetDevVPortProfileOpCommon), although obscured by an unnecessary
      passing of a function pointer. This patch removes the function
      pointer, and calls virNetDevVPortProfileGetLldpadPid() directly in
      virNetDevVPortProfileOpCommon - if it's doing this, it knows that it
      should also call virNetlinkEventServiceLocalPid() to set src_pid too;
      then it just passes src_pid and dst_pid down to
      virNetDevLinkDump. Since (src_pid == 0 && dst_pid == 0) implies that
      the kernel is the destination, there is no longer any need to send
      nltarget_kernel as an arg to virNetDevLinkDump, so it's been removed.
      
      The disparity between src_pid being int and dst_pid being uint32_t may
      be a bit disconcerting to some, but I didn't want to complicate
      virNetlinkEventServiceLocalPid() by having status returned separately
      from the value.
      cc073771
    • L
      util: function to get local nl_pid used by netlink event socket · c99e9375
      Laine Stump 提交于
      This value will be needed to set the src_pid when sending netlink
      messages to lldpad. It is part of the solution to:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=816465
      
      Note that libnl's port generation algorithm guarantees that the
      nl_socket_get_local_port() will always be > 0 (since it is "getpid() +
      (n << 22>" where n is always < 1024), so it is okay to cast the
      uint32_t to int (thus allowing us to use -1 as an error sentinel).
      c99e9375
    • L
      util: allow specifying both src and dst pid in virNetlinkCommand · cca7bb1f
      Laine Stump 提交于
      Until now, virNetlinkCommand has assumed that the nl_pid in the source
      address of outgoing netlink messages should always be the return value
      of getpid(). In most cases it actually doesn't matter, but in the case
      of communication with lldpad, lldpad saves this info and later uses it
      to send netlink messages back to libvirt. A recent patch to fix Bug
      816465 changed the order of the universe such that the netlink event
      service socket is no longer bound with nl_pid == getpid(), so lldpad
      could no longer send unsolicited messages to libvirtd. Adding src_pid
      as an argument to virNetlinkCommand() is the first step in notifying
      lldpad of the proper address of the netlink event service socket.
      cca7bb1f
    • L
      util: fix libvirtd startup failure due to netlink error · 64297313
      Laine Stump 提交于
      This is part of the solution to the problem detailed in:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=816465
      
      and further detailed in
      
        https://www.redhat.com/archives/libvir-list/2012-May/msg00202.htm
      
      A short explanation is included in the comments of the patch itself.
      
      Note that this patch by itself breaks communication between lldpad and
      libvirtd, so the other 3 patches in the series must be applied at the
      same time as this patch.
      64297313
  14. 07 5月, 2012 1 次提交
    • G
      usb: create functions to search usb device accurately · 9914477e
      Guannan Ren 提交于
      usbFindDevice():get usb device according to
                      idVendor, idProduct, bus, device
                      it is the exact match of the four parameters
      
      usbFindDeviceByBus():get usb device according to bus, device
                        it returns only one usb device same as usbFindDevice
      
      usbFindDeviceByVendor():get usb device according to idVendor,idProduct
                           it probably returns multiple usb devices.
      
      usbDeviceSearch(): a helper function to do the actual search
      9914477e
  15. 05 5月, 2012 2 次提交
    • L
      util: remove error log from stubs of virNetlinkEventServiceStart|Stop · bae4ff28
      Laine Stump 提交于
      These two functions are called from main() on all platforms, and
      always return success on platforms that don't support libnl. They
      still log an error message, though, which doesn't make sense - they
      should just be NOPs on those platforms. (Per a suggestion during
      review, I've turned the logs into debug messages rather than removing
      them completely).
      bae4ff28
    • S
      uuid: fix possible non-terminated string · b4586051
      Stefan Berger 提交于
      Error: STRING_NULL:
      /libvirt/src/util/uuid.c:273:
      string_null_argument: Function "getDMISystemUUID" does not terminate string "*dmiuuid".
      /libvirt/src/util/uuid.c:241:
      string_null_argument: Function "saferead" fills array "*uuid" with a non-terminated string.
      /libvirt/src/util/util.c:101:
      string_null_argument: Function "read" fills array "*buf" with a non-terminated string.
      /libvirt/src/util/uuid.c:274:
      string_null: Passing unterminated string "dmiuuid" to a function expecting a null-terminated string.
      /libvirt/src/util/uuid.c:138:
      var_assign_parm: Assigning: "cur" = "uuidstr". They now point to the same thing.
      /libvirt/src/util/uuid.c:164:
      string_null_sink_loop: Searching for null termination in an unterminated array "cur".
      b4586051
  16. 04 5月, 2012 2 次提交
  17. 03 5月, 2012 3 次提交
  18. 01 5月, 2012 1 次提交
    • A
      util: Avoid libvirtd crash in virNetDevTapCreate · 5ee18aaa
      Alex Jia 提交于
      In fact, the 'tapfd' is always NULL, the function 'virNetDevTapCreate()' hasn't
      assign 'fd' to 'tapfd', when the function 'virNetDevSetMAC()' is failed then
      goto 'error' label, finally, the VIR_FORCE_CLOSE() will deref a NULL 'tapfd'.
      
      * util/virnetdevtap.c (virNetDevTapCreateInBridgePort): fix a NULL pointer derefing.
      
      * How to reproduce?
      
      $ cat > /tmp/net.xml <<EOF
      <network>
        <name>test</name>
        <forward mode='nat'/>
        <bridge name='br1' stp='off' delay='1' />
        <mac address='00:00:00:00:00:00'/>
        <ip address='192.168.100.1' netmask='255.255.255.0'>
          <dhcp>
            <range start='192.168.100.2' end='192.168.100.254' />
          </dhcp>
        </ip>
      </network>
      EOF
      
      $ virsh net-define /tmp/net.xml
      
      $ virsh net-start test
      error: Failed to start network brTest
      error: End of file while reading data: Input/output error
      Signed-off-by: NAlex Jia <ajia@redhat.com>
      5ee18aaa
  19. 30 4月, 2012 1 次提交
    • J
      qemu: Make sure qemu can access its directory in hugetlbfs · 9d2ac545
      Jiri Denemark 提交于
      When libvirtd is started, we create "libvirt/qemu" directories under
      hugetlbfs mount point. Only the "qemu" subdirectory is chowned to qemu
      user and "libvirt" remains owned by root. If umask was too restrictive
      when libvirtd started, qemu user may lose access to "qemu"
      subdirectory. Let's explicitly grant search permissions to "libvirt"
      directory for all users.
      9d2ac545
  20. 27 4月, 2012 2 次提交
    • S
      macvtap: fix a typo · 4bf9061e
      Stefan Berger 提交于
      Below patch fixes the following coverity findings
      
      Error: OVERRUN_STATIC:
      /libvirt/src/qemu/qemu_command.c:152:
      overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
      /libvirt/src/util/virnetdevmacvlan.c:948:
      access_dbuff_const: Calling "virNetDevMacVLanVPortProfileRegisterCallback" indexes array "macaddress" at byte position 15.
      /libvirt/src/util/virnetdevmacvlan.c:773:
      access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.
      
      Error: OVERRUN_STATIC:
      /libvirt/src/qemu/qemu_migration.c:2744:
      overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
      /libvirt/src/util/virnetdevmacvlan.c:773:
      access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.
      
      Error: OVERRUN_STATIC:
      /libvirt/src/qemu/qemu_driver.c:435:
      overrun-buffer-val: Overrunning static array "net->mac" of size 6 bytes by passing it as an argument to a function which indexes it at byte position 15.
      /libvirt/src/util/virnetdevmacvlan.c:1036:
      access_dbuff_const: Calling "virNetDevMacVLanVPortProfileRegisterCallback" indexes array "macaddress" at byte position 15.
      /libvirt/src/util/virnetdevmacvlan.c:773:
      access_dbuff_const: Calling "memcpy" indexes array "macaddress" with index "16UL" at byte position 15.
      
      4bf9061e
    • L
      util: fix error messages in virNetlinkEventServiceStart · 9586925b
      Laine Stump 提交于
      Some of the error messages in this function should have been
      virReportSystemError (since they have an errno they want to log), but
      were mistakenly written as netlinkError, which expects a libvirt error
      code instead. The result was that when one of the errors was
      encountered, "No error message provided" would be printed instead of
      something meaningful (see
      https://bugzilla.redhat.com/show_bug.cgi?id=816465 for an example).
      9586925b
  21. 26 4月, 2012 1 次提交
    • L
      util: fix crash when starting macvtap interfaces · f78024b9
      Laine Stump 提交于
      This patch resolves https://bugzilla.redhat.com/show_bug.cgi?id=815270
      
      The function virNetDevMacVLanVPortProfileRegisterCallback() takes an
      arg "virtPortProfile", and was checking it for non-NULL before using
      it. However, the prototype for
      virNetDevMacVLanPortProfileRegisterCallback had marked that arg with
      ATTRIBUTE_NONNULL(). Contrary to what one may think,
      ATTRIBUTE_NONNULL() does not provide any guarantee that an arg marked
      as such really is always non-null; the only effect to the code
      generated by gcc, is that gcc *assumes* it is non-NULL; this results
      in, for example, the check for a non-NULL value being optimized out.
      
      (Unfortunately, this code removal only occurs when optimization is
      enabled, and I am in the habit of doing local builds with optimization
      off to ease debugging, so the bug didn't show up in my earlier local
      testing).
      
      In general, virPortProfile might always be NULL, so it shouldn't be
      marked as ATTRIBUTE_NONNULL. One other function prototype made this
      same error, so this patch fixes it as well.
      f78024b9
  22. 25 4月, 2012 2 次提交
  23. 24 4月, 2012 1 次提交
    • S
      Improve on virAtomic implementation · a4a5c00b
      Stefan Berger 提交于
      This patch improves the previously added virAtomicInt implementation
      by using gcc-builtins if possible. The needed builtins are available
      since GCC >= 4.1. At least the 4.0 docs don't mention them.
      a4a5c00b