1. 26 5月, 2010 2 次提交
    • C
      Fix failing virGetHostname. · 0117b7da
      Chris Lalancette 提交于
      We've been running into a lot of situations where
      virGetHostname() is returning "localhost", where a plain
      gethostname() would have returned the correct thing.  This
      is because virGetHostname() is *always* trying to canonicalize
      the name returned from gethostname(), even when it doesn't
      have to.
      
      This patch changes virGetHostname so that if the value returned
      from gethostname() is already FQDN or localhost, it returns
      that string directly.  If the value returned from gethostname()
      is a shortened hostname, then we try to canonicalize it.  If
      that succeeds, we returned the canonicalized hostname.  If
      that fails, and/or returns "localhost", then we just return
      the original string we got from gethostname() and hope for
      the best.
      
      Note that after this patch it is up to clients to check whether
      "localhost" is an allowed return value.  The only place
      where it's currently not is in qemu migration.
      Signed-off-by: NChris Lalancette <clalance@redhat.com>
      0117b7da
    • C
      storage: Sanitize pool target paths · a7fb2258
      Cole Robinson 提交于
      Spurious / in a pool target path makes life difficult for apps using the
      GetVolByPath, and doing other path based comparisons with pools. This
      has caused a few issues for virt-manager users:
      
      https://bugzilla.redhat.com/show_bug.cgi?id=494005
      https://bugzilla.redhat.com/show_bug.cgi?id=593565
      
      Add a new util API which removes spurious /, virFileSanitizePath. Sanitize
      target paths when parsing pool XML, and for paths passed to GetVolByPath.
      
      v2: Leading // must be preserved, properly sanitize path=/, sanitize
          away /./ -> /
      
      v3: Properly handle starting ./ and ending /.
      
      v4: Drop all '.' handling, just sanitize / for now.
      a7fb2258
  2. 21 5月, 2010 1 次提交
  3. 18 5月, 2010 1 次提交
    • E
      virFileResolveLink: fix return value · d533a98e
      Eric Blake 提交于
      virFileResolveLink was returning a positive value on error,
      thus confusing callers that assumed failure was < 0.  The
      confusion is further evidenced by callers that would have
      ended up calling virReportSystemError with a negative value
      instead of a valid errno.
      
      Fixes Red Hat BZ #591363.
      
      * src/util/util.c (virFileResolveLink): Live up to documentation.
      * src/qemu/qemu_security_dac.c
      (qemuSecurityDACRestoreSecurityFileLabel): Adjust callers.
      * src/security/security_selinux.c
      (SELinuxRestoreSecurityFileLabel): Likewise.
      * src/storage/storage_backend_disk.c
      (virStorageBackendDiskDeleteVol): Likewise.
      d533a98e
  4. 07 5月, 2010 2 次提交
    • E
      build: use gnulib's sys/wait.h · 8acaeb73
      Eric Blake 提交于
      * configure.ac: Drop sys/wait.h check.
      * src/libvirt.c (includes): Use header unconditionally.
      * src/remote/remote_driver.c (includes): Likewise.
      * src/storage/storage_backend.c (includes): Likewise.
      * src/util/ebtables.c (includes): Likewise.
      * src/util/hooks.c (includes): Likewise.
      * src/util/iptables.c (includes): Likewise.
      * src/util/util.c (includes): Likewise.
      8acaeb73
    • E
      build: rely on gnulib's pthread module · 9017b9bc
      Eric Blake 提交于
      Gnulib can guarantee that pthread.h exists, but for now, it is a dummy
      header with no support for most pthread_* functions.  Modify our
      use of pthread to use function checks, rather than header checks,
      to determine how much pthread support is present.
      
      * bootstrap.conf (gnulib_modules): Add pthread.
      * configure.ac: Drop all pthread.h checks.  Optimize function
      checks.  Add check for pthread functions.
      * src/Makefile.am (libvirt_lxc_LDADD): Ensure proper link.
      * src/remote/remote_driver.c (remoteIOEventLoop): Depend on
      pthread_sigmask, now that gnulib guarantees pthread.h.
      * src/util/util.c (virFork): Likewise.
      * src/util/threads.c (threads-pthread.c): Depend on
      pthread_mutexattr_init, as a witness of full pthread support.
      * src/util/threads.h (threads-pthread.h): Likewise.
      9017b9bc
  5. 05 5月, 2010 1 次提交
    • E
      util: fix va_start usage bug · 62ee19c7
      Eric Blake 提交于
      Detected by clang.  POSIX requires that the second argument to
      va_start be the name of the last variable; and in some implementations,
      passing *path instead of path would dereference bogus memory instead
      of pulling arguments off the stack.
      
      * src/util/util.c (virBuildPathInternal): Use correct argument to
      va_start.
      62ee19c7
  6. 04 5月, 2010 2 次提交
    • M
      mingw: Fix two undefined symbols · ee234bfd
      Matthias Bolte 提交于
      Add an empty body for virCondWaitUntil and move virPipeReadUntilEOF
      out of the '#ifndef WIN32' block, because it compiles fine with MinGW
      in combination with gnulib.
      ee234bfd
    • 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
  7. 30 4月, 2010 1 次提交
  8. 24 4月, 2010 1 次提交
  9. 22 4月, 2010 1 次提交
  10. 15 4月, 2010 1 次提交
  11. 07 4月, 2010 1 次提交
  12. 01 4月, 2010 1 次提交
  13. 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
  14. 23 3月, 2010 5 次提交
  15. 10 3月, 2010 1 次提交
  16. 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
  17. 06 3月, 2010 1 次提交
  18. 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
  19. 24 2月, 2010 1 次提交
  20. 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
  21. 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
  22. 09 2月, 2010 3 次提交
  23. 05 2月, 2010 1 次提交
  24. 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
  25. 02 2月, 2010 1 次提交
  26. 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
  27. 30 1月, 2010 1 次提交
  28. 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