1. 04 5月, 2010 1 次提交
    • E
      build: avoid compiler warning · 7f31e28c
      Eric Blake 提交于
      Necessary on cygwin, where uid_t and gid_t are 4-byte long rather
      than int, causing gcc -Wformat warnings.
      
      * src/util/util.c (virFileOperationNoFork, virDirCreateNoFork)
      (virFileOperation, virDirCreate, virGetUserEnt): Cast uid_t and
      gid_t before passing to printf.
      * .gitignore: Ignore Windows executables.
      7f31e28c
  2. 30 4月, 2010 1 次提交
  3. 24 4月, 2010 1 次提交
  4. 22 4月, 2010 1 次提交
  5. 15 4月, 2010 1 次提交
  6. 07 4月, 2010 1 次提交
  7. 01 4月, 2010 1 次提交
  8. 30 3月, 2010 1 次提交
    • D
      Export virPipeReadUntilEOF internally · b3bff954
      Daniel Veillard 提交于
      used to read the data from virExec stdout/err file descriptors
      
      * src/util/util.c src/util/util.h: not static anymore and export it
      * src/libvirt_private.syms: allow access internally
      b3bff954
  9. 23 3月, 2010 5 次提交
  10. 10 3月, 2010 1 次提交
  11. 08 3月, 2010 1 次提交
    • E
      build: consistently use C99 varargs macros · 2e56fb2b
      Eric Blake 提交于
      Prior to this patch, there was an inconsistent mix between GNU and C99.
      
      For consistency, and potential portability to other compilers, stick
      with the C99 vararg macro syntax.
      
      * src/conf/cpu_conf.c (virCPUReportError): Use C99 rather than GNU
        vararg macro syntax.
      * src/conf/domain_conf.c (virDomainReportError): Likewise.
      * src/conf/domain_event.c (eventReportError): Likewise.
      * src/conf/interface_conf.c (virInterfaceReportError): Likewise.
      * src/conf/network_conf.c (virNetworkReportError): Likewise.
      * src/conf/node_device_conf.h (virNodeDeviceReportError): Likewise.
      * src/conf/secret_conf.h (virSecretReportError): Likewise.
      * src/conf/storage_conf.h (virStorageReportError): Likewise.
      * src/esx/esx_device_monitor.c (ESX_ERROR): Use C99 rather than
        GNU vararg macro syntax.
      * src/esx/esx_driver.c (ESX_ERROR): Likewise.
      * src/esx/esx_interface_driver.c (ESX_ERROR): Likewise.
      * src/esx/esx_network_driver.c (ESX_ERROR): Likewise.
      * src/esx/esx_secret_driver.c (ESX_ERROR): Likewise.
      * src/esx/esx_storage_driver.c (ESX_ERROR): Likewise.
      * src/esx/esx_util.c (ESX_ERROR): Likewise.
      * src/esx/esx_vi.c (ESX_VI_ERROR): Likewise.
      * src/esx/esx_vi_methods.c (ESX_VI_ERROR): Likewise.
      * src/esx/esx_vi_types.c (ESX_VI_ERROR): Likewise.
      * src/esx/esx_vmx.c (ESX_ERROR): Likewise.
      * src/util/hostusb.c (usbReportError): Use C99 rather than GNU
        vararg macro syntax.
      * src/util/json.c (virJSONError): Likewise.
      * src/util/macvtap.c (ReportError): Likewise.
      * src/util/pci.c (pciReportError): Likewise.
      * src/util/stats_linux.c (virStatsError): Likewise.
      * src/util/util.c (virUtilError): Likewise.
      * src/util/xml.c (virXMLError): Likewise.
      * src/xen/proxy_internal.c (virProxyError): Use C99 rather than
        GNU vararg macro syntax.
      * src/xen/sexpr.c (virSexprError): Likewise.
      * src/xen/xen_driver.c (xenUnifiedError): Likewise.
      * src/xen/xen_hypervisor.c (virXenError): Likewise.
      * src/xen/xen_inotify.c (virXenInotifyError): Likewise.
      * src/xen/xend_internal.c (virXendError): Likewise.
      * src/xen/xm_internal.c (xenXMError): Likewise.
      * src/xen/xs_internal.c (virXenStoreError): Likewise.
      * src/cpu/cpu.h (virCPUReportError): Use C99 rather than GNU
        vararg macro syntax.
      * src/datatypes.c (virLibConnError): Likewise.
      * src/interface/netcf_driver.c (interfaceReportError): Likewise.
      * src/libvirt.c (virLibStreamError): Likewise.
      * src/lxc/lxc_conf.h (lxcError): Likewise.
      * src/network/bridge_driver.c (networkReportError): Likewise.
      * src/nodeinfo.c (nodeReportError): Likewise.
      * src/opennebula/one_conf.h (oneError): Likewise.
      * src/openvz/openvz_conf.h (openvzError): Likewise.
      * src/phyp/phyp_driver.c (PHYP_ERROR): Likewise.
      * src/qemu/qemu_conf.h (qemuReportError): Likewise.
      * src/remote/remote_driver.c (errorf): Likewise.
      * src/security/security_driver.h (virSecurityReportError): Likewise.
      * src/test/test_driver.c (testError): Likewise.
      * src/uml/uml_conf.h (umlReportError): Likewise.
      * src/vbox/vbox_driver.c (vboxError): Likewise.
      * src/vbox/vbox_tmpl.c (vboxError): Likewise.
      2e56fb2b
  12. 06 3月, 2010 1 次提交
  13. 03 3月, 2010 1 次提交
    • J
      Fix safezero() · a64e3b3e
      Jiri Denemark 提交于
      Various safezero() implementations used either -1, errno or -errno
      return values. This patch fixes them all to return -1 and set errno
      appropriately.
      
      There was also a bug in size parameter passed to safewrite() which could
      result in an attempt to write gigabytes out of a megabyte buffer.
      Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
      a64e3b3e
  14. 24 2月, 2010 1 次提交
  15. 20 2月, 2010 1 次提交
    • L
      Rename virFileCreate to virFileOperation, add hook function · fbadc2b6
      Laine Stump 提交于
      It turns out it is also useful to be able to perform other operations
      on a file created while running as a different uid (eg, write things
      to that file), and possibly to do this to a file that already
      exists. This patch adds an optional hook function to the renamed (for
      more accuracy of purpose) virFileOperation; the hook will be called
      after the file has been opened (possibly created) and gid/mode
      checked/set, before closing it.
      
      As with the other operations on the file, if the VIR_FILE_OP_AS_UID
      flag is set, this hook function will be called in the context of a
      child process forked from the process that called virFileOperation.
      The implication here is that, while all data in memory is available to
      this hook function, any modification to that data will not be seen by
      the caller - the only indication in memory of what happened in the
      hook will be the return value (which the hook should set to 0 on
      success, or one of the standard errno values on failure).
      
      Another piece of making the function more flexible was to add an
      "openflags" argument. This arg should contain exactly the flags to be
      passed to open(2), eg O_RDWR | O_EXCL, etc.
      
      In the process of adding the hook to virFileOperation, I also realized
      that the bits to fix up file owner/group/mode settings after creation
      were being done in the parent process, which could fail, so I moved
      them to the child process where they should be.
      
      * src/util/util.[ch]: rename and rework virFileCreate-->virFileOperation,
        and redo flags in virDirCreate
      * storage/storage_backend.c, storage/storage_backend_fs.c: update the
        calls to virFileOperation/virDirCreate to reflect changes in the API,
        but don't yet take advantage of the hook.
      fbadc2b6
  16. 19 2月, 2010 3 次提交
    • C
      Better error reporting for failed migration · b97c24b2
      Chris Lalancette 提交于
      If the hostname as returned by "gethostname" resolves
      to "localhost" (as it does with the broken Fedora-12
      installer), then live migration will fail because the
      source will try to migrate to itself.  Detect this
      situation up-front and abort the live migration before
      we do any real work.
      
      * src/util/util.h src/util/util.c: add a new virGetHostnameLocalhost
        with an optional localhost check, and rewire virGetHostname() to use
        it
      * src/libvirt_private.syms: expose the new function
      * src/qemu/qemu_driver.c: use it in qemudDomainMigratePrepare2()
      b97c24b2
    • L
      Use virFork() in __virExec(), virFileCreate() and virDirCreate() · 61497d95
      Laine Stump 提交于
      For __virExec() this is a semantic NOP except for when fork()
      fails. __virExec() would previously forget to restore the signal mask
      in this case; virFork() corrects this behavior.
      
      virFileCreate() and virDirCreate() gain the code to reset the logging
      and properly deal with the signal handling race condition.
      
      This also removes a log message that had a typo ("cannot fork o create
      file '%s'") - this error is now logged in a more generic manner in
      virFork() (more generic, but really just as informative, since the
      fact that it's forking to create a file is immaterial to the fact that
      it simply can't fork)
      
      * src/util/util.c: use the generic virFork() in the 3 functions
      61497d95
    • L
      Add virFork() function to utils · b4584612
      Laine Stump 提交于
      virFork() contains bookkeeping that must be done any time a process
      forks. Currently this includes:
      
      1) Call virLogLock() prior to fork() and virLogUnlock() just after,
         to avoid a deadlock if some other thread happens to hold that lock
         during the fork.
      
      2) Reset the logging hooks and send all child process log messages to
         stderr.
      
      3) Block all signals prior to fork(), then either a) reset the signal
         mask for the parent process, or b) clear the signal mask for the
         child process.
      
      Note that the signal mask handling in __virExec erroneously fails to
      restore the signal mask when fork() fails. virFork() fixes this
      problem.
      
      Other than this, it attempts to behave as closely to fork() as
      possible (including preserving errno for the caller), with a couple
      exceptions:
      
      1) The return value is 0 (success) or -1 (failure), while the pid is
         returned via the pid_t* argument. Like fork(), if pid < 0 there is
         no child process, otherwise both the child and the parent will
         return to the caller, and both should look at the return value,
         which will indicate if some of the extra processing outlined above
         encountered an error.
      
      2) If virFork() returns with pid < 0 or with a return value < 0
         indicating an error condition, the error has already been
         reported. You can log an additional message if you like, but it
         isn't necessary, and may be awkwardly extraneous.
      
      Note that virFork()'s child process will *never* call _exit() - if a
      child process is created, it will return to the caller.
      
      * util.c util.h: add virFork() function, based on what is currently
                       done in __virExec().
      b4584612
  17. 09 2月, 2010 3 次提交
  18. 05 2月, 2010 1 次提交
  19. 04 2月, 2010 2 次提交
    • L
      Another fork() log locking cleanup in file creation · 730801d9
      Laine Stump 提交于
      Similar fix as previous one but for fork() usage when creating
      a file or directory
      
      * src/util/util.c: virLogLock() and virLogUnlock() around fork()
        in virFileCreate() and virDirCreateSimple()
      730801d9
    • C
      Fix log locking problem when using fork() in the library · cd0ef0e0
      Cole Robinson 提交于
      Ad pointed out by Dan Berrange:
      So if some thread in libvirtd is currently executing a logging call,
      while another thread calls virExec(), that other thread no longer
      exists in the child, but its lock is never released. So when the
      child then does virLogReset() it deadlocks.
      
      The only way I see to address this, is for the parent process to call
      virLogLock(), immediately before fork(), and then virLogUnlock()
      afterwards in both parent & child. This will ensure that no other
      thread
      can be holding the lock across fork().
      
      * src/util/logging.[ch] src/libvirt_private.syms: export virLogLock() and
        virLogUnlock()
      * src/util/util.c: lock just before forking and unlock just after - in
        both parent and child.
      cd0ef0e0
  20. 02 2月, 2010 1 次提交
  21. 01 2月, 2010 1 次提交
    • C
      Look in /usr/libexec for the qemu-kvm binary. · b16cd226
      Chris Lalancette 提交于
      On RHEL-5 the qemu-kvm binary is located in /usr/libexec.
      To reduce confusion for people trying to run upstream libvirt
      on RHEL-5 machines, make the qemu driver look in /usr/libexec
      for the qemu-kvm binary.
      
      To make this work, I modified virFindFileInPath to handle an
      absolute path correctly.  I also ran into an issue where
      NULL was sometimes being passed for the file parameter
      to virFindFileInPath; it didn't crash prior to this patch
      since it was building paths like /usr/bin/(null).  This
      is non-standard behavior, though, so I added a NULL
      check at the beginning.
      Signed-off-by: NChris Lalancette <clalance@redhat.com>
      b16cd226
  22. 30 1月, 2010 1 次提交
  23. 26 1月, 2010 1 次提交
    • L
      Cleanup of large buffer on stack in virFileMakePath · ba1d379c
      Laine Stump 提交于
      virFileMakePath is a recursive function that was creates a buffer
      PATH_MAX bytes long for each recursion (one recursion for each element
      in the path). This changes it to have no buffers on the stack, and to
      allocate just one buffer total, no matter how many elements are in the
      path. Because the modified algorithm requires a char* to be passed in
      rather than const char *, it is now 2 functions - a toplevel API
      function that remains identical in function, and a 2nd helper function
      called for the recursions, which 1) doesn't allocate anything, and 2)
      takes a char* arg, so it can modify the contents.
      * src/util/util.c: rewrite virFileMakePath
      ba1d379c
  24. 21 1月, 2010 2 次提交
    • L
      New utility functions virFileCreate and virDirCreate · 98f6f381
      Laine Stump 提交于
      These functions create a new file or directory with the given
      uid/gid. If the flag VIR_FILE_CREATE_AS_UID is given, they do this by
      forking a new process, calling setuid/setgid in the new process, and
      then creating the file. This is better than simply calling open then
      fchown, because in the latter case, a root-squashing nfs server would
      create the new file as user nobody, then refuse to allow fchown.
      
      If VIR_FILE_CREATE_AS_UID is not specified, the simpler tactic of
      creating the file/dir, then chowning is is used. This gives better
      results in cases where the parent directory isn't on a root-squashing
      NFS server, but doesn't give permission for the specified uid/gid to
      create files. (Note that if the fork/setuid method fails to create the
      file due to access privileges, the parent process will make a second
      attempt using this simpler method.)
      
      If the bit VIR_FILE_CREATE_ALLOW_EXIST is set in the flags, an
      existing file/directory will not cause an error; in this case, the
      function will simply set the permissions of the file/directory to
      those requested. If VIR_FILE_CREATE_ALLOW_EXIST is not specified, an
      existing file/directory is considered (and reported as) an error.
      
      Return from both of these functions is 0 on success, or the value of
      errno if there was a failure.
      
      * src/util/util.[ch]: add the 2 new util functions
      98f6f381
    • L
      Add virRunWithHook util function · d2259ada
      Laine Stump 提交于
      * src/util/util.[ch]: similar to virExecWithHook, but waits for child to
        exit. Useful for doing things like setuid after the fork but before the
        exec.
      d2259ada
  25. 18 1月, 2010 1 次提交
    • J
      util.c: include required header, no longer masked by gnulib · 30a9329a
      Jim Meyering 提交于
      Until recently, some gnulib-generated replacement headers
      included *other* headers that were not strictly necessary,
      thus masking the need in this file for an explicit <stdlib.h>.
      * src/util/util.c: Include <stdlib.h> for declarations of e.g.,
      strtol, random_r, getenv, etc.
      30a9329a
  26. 14 1月, 2010 1 次提交
    • C
      util: Make sure virExec hook failures are raised · 522776ed
      Cole Robinson 提交于
      With the introduction virDispatchError, hook function errors are
      never sent through the error callback, so users will never see
      these messages.
      
      Fix this by calling virDispatchError after hook failure.
      522776ed
  27. 13 1月, 2010 1 次提交
    • C
      util: Remove logging handlers in virExec · 28613908
      Cole Robinson 提交于
      This allows debug statements and raised errors in hook functions to
      actually be logged somewhere (stderr). Users can enable debugging in the
      daemon and now see more info in /var/log/libvirt/...
      28613908
  28. 16 12月, 2009 1 次提交
    • J
      avoid malfunction when virFileResolveLink is applied to non-POSIX FS · 5baa4635
      Jim Meyering 提交于
      The virFileResolveLink utility function relied on the POSIX guarantee
      that stat.st_size of a symlink is the length of the value.  However,
      on some types of file systems, it is invalid, so do not rely on it.
      Use gnulib's areadlink module instead.
      * bootstrap (modules): Add areadlink.
      * src/util/util.c: Include "areadlink.h".
      Let areadlink perform the readlink and malloc.
      * configure.in (AC_CHECK_FUNCS): Remove readlink.  No need,
      since it's presence is guaranteed by gnulib.
      5baa4635
  29. 10 12月, 2009 1 次提交
    • M
      Add virBufferFreeAndReset() and replace free() · 1b9d0744
      Matthias Bolte 提交于
      Replace free(virBufferContentAndReset()) with virBufferFreeAndReset().
      Update documentation and replace all remaining calls to free() with
      calls to VIR_FREE(). Also add missing calls to virBufferFreeAndReset()
      and virReportOOMError() in OOM error cases.
      1b9d0744
  30. 04 12月, 2009 1 次提交
    • M
      Add virIndexToDiskName and fix mapping gap · 63166a4e
      Matthias Bolte 提交于
      esxVMX_IndexToDiskName handles indices up to 701. This limit comes
      from a mapping gap in virDiskNameToIndex:
      
        sdzy -> 700
        sdzz -> 701
        sdaaa -> 728
        sdaab -> 729
      
      This line in virDiskNameToIndex causes this gap:
      
        idx = (idx + i) * 26;
      
      Fixing it by altering this line to:
      
        idx = (idx + (i < 1 ? 0 : 1)) * 26;
      
      Also add a new version of virIndexToDiskName that handles the inverse
      mapping for arbitrary indices.
      
      * src/esx/esx_vmx.[ch]: remove esxVMX_IndexToDiskName
      * src/util/util.[ch]: add virIndexToDiskName and fix mapping gap
      * tests/esxutilstest.c: update test to verify that the gap is fixed
      63166a4e