1. 29 3月, 2011 3 次提交
    • E
      util: use SCM_RIGHTS in virFileOperation when needed · 055d4ff8
      Eric Blake 提交于
      Currently, the hook function in virFileOperation is extremely limited:
      it must be async-signal-safe, and cannot modify any memory in the
      parent process.  It is much handier to return a valid fd and operate
      on it in the parent than to deal with hook restrictions.
      
      * src/util/util.h (VIR_FILE_OP_RETURN_FD): New flag.
      * src/util/util.c (virFileOperationNoFork, virFileOperation):
      Honor new flag.
      055d4ff8
    • E
      util: allow clearing cloexec bit · 296eb0bb
      Eric Blake 提交于
      * src/util/util.h (virSetInherit): New prototype.
      * src/util/util.c (virSetCloseExec): Move guts...
      (virSetInherit): ...to new function, and allow clearing.
      * src/libvirt_private.syms (util.h): Export it.
      296eb0bb
    • E
      logging: always NUL-terminate circular buffer · 60dea30b
      Eric Blake 提交于
      * src/util/logging.c (virLogStartup, virLogSetBufferSize):
      Over-allocate, so that a debugger can just print the circular
      buffer.  Suggested by Daniel Veillard.
      60dea30b
  2. 26 3月, 2011 1 次提交
  3. 25 3月, 2011 4 次提交
    • E
      command: add virCommandAbort for cleanup paths · 9ed54518
      Eric Blake 提交于
      Sometimes, an asynchronous helper is started (such as a compressor
      or iohelper program), but a later error means that we want to
      abort that child.  Make this easier.
      
      Note that since daemons and virCommandRunAsync can't mix, the only
      time virCommandFree can reap a process is if someone did
      virCommandRunAsync for a non-daemon and didn't stash the pid.
      
      * src/util/command.h (virCommandAbort): New prototype.
      * src/util/command.c (_virCommand): Add new field.
      (virCommandRunAsync, virCommandWait): Track whether pid was used.
      (virCommandFree): Reap child if caller did not request pid.
      (virCommandAbort): New function.
      * src/libvirt_private.syms (command.h): Export it.
      * tests/commandtest.c (test19): New test.
      9ed54518
    • E
      command: don't mix RunAsync and daemons · 4e808602
      Eric Blake 提交于
      It doesn't make sense to run a daemon without synchronously
      waiting for the child process to reply whether the daemon has
      been kicked off and pidfile written yet.
      
      * src/util/command.c (VIR_EXEC_RUN_SYNC): New constant.
      (virCommandRun): Set temporary flag.
      (virCommandRunAsync): Use it to prevent async runs of intermediate
      child when spawning asynchronous daemon grandchild.
      4e808602
    • E
      command: properly diagnose process exit via signal · 208a044a
      Eric Blake 提交于
      Child processes don't always reach _exit(); if they die from a
      signal, then any messages should still be accurate.  Most users
      either expect a 0 status (thankfully, if status==0, then
      WIFEXITED(status) is true and WEXITSTATUS(status)==0 for all
      known platforms) or were filtering on WIFEXITED before printing
      a status, but a few were missing this check.  Additionally,
      nwfilter_ebiptables_driver was making an assumption that works
      on Linux (where WEXITSTATUS shifts and WTERMSIG just masks)
      but fails on other platforms (where WEXITSTATUS just masks and
      WTERMSIG shifts).
      
      * src/util/command.h (virCommandTranslateStatus): New helper.
      * src/libvirt_private.syms (command.h): Export it.
      * src/util/command.c (virCommandTranslateStatus): New function.
      (virCommandWait): Use it to also diagnose status from signals.
      * src/security/security_apparmor.c (load_profile): Likewise.
      * src/storage/storage_backend.c
      (virStorageBackendQEMUImgBackingFormat): Likewise.
      * src/util/util.c (virExecDaemonize, virRunWithHook)
      (virFileOperation, virDirCreate): Likewise.
      * daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
      * src/nwfilter/nwfilter_ebiptables_driver.c (ebiptablesExecCLI):
      Likewise.
      208a044a
    • E
      maint: prohibit access(,X_OK) · 391c397e
      Eric Blake 提交于
      This simplifies several callers that were repeating checks already
      guaranteed by util.c, and makes other callers more robust to now
      reject directories.  remote_driver.c was over-strict - access(,R_OK)
      is only needed to execute a script file; a binary only needs
      access(,X_OK) (besides, it's unusual to see a file with x but not
      r permissions, whether script or binary).
      
      * cfg.mk (sc_prohibit_access_xok): New syntax-check rule.
      (exclude_file_name_regexp--sc_prohibit_access_xok): Exempt one use.
      * src/network/bridge_driver.c (networkStartRadvd): Fix offenders.
      * src/qemu/qemu_capabilities.c (qemuCapsProbeMachineTypes)
      (qemuCapsInitGuest, qemuCapsInit, qemuCapsExtractVersionInfo):
      Likewise.
      * src/remote/remote_driver.c (remoteFindDaemonPath): Likewise.
      * src/uml/uml_driver.c (umlStartVMDaemon): Likewise.
      * src/util/hooks.c (virHookCheck): Likewise.
      391c397e
  4. 24 3月, 2011 1 次提交
  5. 23 3月, 2011 2 次提交
    • O
      util: Fix return value for virJSONValueFromString if it fails · 93e8b877
      Osier Yang 提交于
      Problem:
        "parser.head" is not NULL even if it's free'ed by "virJSONValueFree",
      returning "parser.head" when "virJSONValueFromString" fails will cause
      unexpected errors (libvirtd will crash sometimes), e.g.
        In function "qemuMonitorJSONArbitraryCommand":
      
              if (!(cmd = virJSONValueFromString(cmd_str)))
                  goto cleanup;
      
              if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
                  goto cleanup;
      
              ......
      
           cleanup:
              virJSONValueFree(cmd);
      
        It will continues to send command to monitor even if "virJSONValueFromString"
      is failed, and more worse, it trys to free "cmd" again.
      
        Crash example:
      {"error":{"class":"QMPBadInputObject","desc":"Expected 'execute' in QMP input","data":{"expected":"execute"}}}
      {"error":{"class":"QMPBadInputObject","desc":"Expected 'execute' in QMP input","data":{"expected":"execute"}}}
      error: server closed connection:
      error: unable to connect to '/var/run/libvirt/libvirt-sock', libvirtd may need to be started: Connection refused
      error: failed to connect to the hypervisor
      
        This fix is to:
          1) return NULL for failure of "virJSONValueFromString",
          2) and it seems "virJSONValueFree" uses incorrect loop index for type
             of "VIR_JSON_TYPE_OBJECT", fix it together.
      
      * src/util/json.c
      93e8b877
    • R
      8021Qbh: use preassociate-rr during the migration prepare stage · 7708da38
      Roopa Prabhu 提交于
      This patch introduces PREASSOCIATE-RR during incoming VM migration on the
      destination host. This is similar to the usage of PREASSOCIATE during
      migration in 8021qbg libvirt code today. PREASSOCIATE-RR is a VDP operation.
      With the latest at IEEE, 8021qbh will need to support VDP operations.
      A corresponding enic driver patch to support PREASSOCIATE-RR for 8021qbh
      will be posted for net-next-2.6 inclusion soon.
      7708da38
  6. 22 3月, 2011 1 次提交
  7. 21 3月, 2011 2 次提交
    • E
      logging: fix off-by-one bug · dd5564f2
      Eric Blake 提交于
      Valgrind caught that our log wrap-around was going 1 past the end.
      Regression introduced in commit b16f47ab; previously the
      buffer was static and size+1 bytes, but now it is dynamic and
      exactly size bytes.
      
      * src/util/logging.c (virLogStr): Don't write past end of log.
      dd5564f2
    • E
      util: guarantee sane errno in virFileIsExecutable · 8351358f
      Eric Blake 提交于
      If virFileIsExecutable is to replace access(file,X_OK), then
      errno must be usable on failure.
      
      * src/util/util.c (virFileIsExecutable): Set errno on failure.
      8351358f
  8. 19 3月, 2011 2 次提交
  9. 18 3月, 2011 5 次提交
    • J
      Add libxenlight driver · 2b84e445
      Jim Fehlig 提交于
      Add a new xen driver based on libxenlight [1], which is the primary
      toolstack starting with Xen 4.1.0.  The driver is stateful and runs
      privileged only.
      
      Like the existing xen-unified driver, the libxenlight driver is
      accessed with xen:// URI.  Driver selection is based on the status
      of xend.  If xend is running, the libxenlight driver will not load
      and xen:// connections are handled by xen-unified.  If xend is not
      running *and* the libxenlight driver is available, xen://
      connections are deferred to the libxenlight driver.
      
      V6:
       - Address several code style issues noted by Daniel Veillard
       - Make drive work with xen:/// URI
       - Hold domain object reference while domain is injected in
         libvirt event loop.  Race found and fixed by Markus Groß.
      
      V5:
       - Ensure events are unregistered when domain private data
         is destroyed.  Discovered and fixed by Markus Groß.
      
      V4:
       - Handle restart of libvirtd, reconnecting to previously
         started domains
       - Rebased to current master
       - Tested against Xen 4.1 RC7-pre (c/s 22961:c5d121fd35c0)
      
      V3:
        - Reserve vnc port within driver when autoport=yes
      
      V2:
        - Update to Xen 4.1 RC6-pre (c/s 22940:5a4710640f81)
        - Rebased to current master
        - Plug memory leaks found by Stefano Stabellini and valgrind
        - Handle SHUTDOWN_crash domain death event
      
      [1] http://lists.xensource.com/archives/html/xen-devel/2009-11/msg00436.html
      2b84e445
    • J
      util: Forbid calling hash APIs from iterator callback · fba550f6
      Jiri Denemark 提交于
      Calling most hash APIs is not safe from inside of an iterator callback.
      Exceptions are APIs that do not modify the hash table and removing
      current hash entry from virHashFroEach callback.
      
      This patch make all APIs which are not safe fail instead of just relying
      on the callback being nice not calling any unsafe APIs.
      fba550f6
    • D
      Avoid taking lock in libvirt debug dump · 10598dd5
      Daniel Veillard 提交于
      As pointed out, locking the buffer from the signal handler
      cannot been guaranteed to be safe, so to avoid any hazard
      we prefer the trade off of dumping logs possibly messed up
      by concurrent logging activity rather than risk a daemon
      crash.
      
      * src/util/logging.c: change virLogEmergencyDumpAll() to not
        take any lock on the log buffer but reset buffer content variables
        to an empty set before starting the actual dump.
      10598dd5
    • N
      virsh: fix memtune's help message for swap_hard_limit · 78ba748e
      Nikunj A. Dadhania 提交于
      * Correct the documentation for cgroup: the swap_hard_limit indicates
        mem+swap_hard_limit.
      * Change cgroup private apis to: virCgroupGet/SetMemSwapHardLimit
      Signed-off-by: NNikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
      78ba748e
    • A
      Add PCI sysfs reset access · 2090b0f5
      Alex Williamson 提交于
      I'm proposing we make use of $PCIDIR/reset in qemu-kvm to reset
      devices on VM reset.  We need to add it to libvirt's list of
      files that get ownership for device assignment.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      2090b0f5
  10. 17 3月, 2011 1 次提交
    • L
      macvtap: log an error if on failure to connect to netlink socket · 12775d94
      Laine Stump 提交于
      A bug in libnl (see https://bugzilla.redhat.com/show_bug.cgi?id=677724
      and https://bugzilla.redhat.com/show_bug.cgi?id=677725) makes it very
      easy to create a failure to connect to the netlink socket when trying
      to open a macvtap network device ("type='direct'" in domain interface
      XML). When that error occurred (during a call to libnl's nl_connect()
      from libvirt's nlComm(), there was no log message, leading virsh (for
      example) to report "unknown error".
      
      There were two other cases in nlComm where an error in a libnl
      function might return with failure but no error reported. In all three
      cases, this patch logs a message which will hopefully be more useful.
      
      Note that more detailed information about the failure might be
      available from libnl's nl_geterror() function, but it calls
      strerror(), which is not threadsafe, so we can't use it.
      12775d94
  11. 15 3月, 2011 5 次提交
    • D
      Change message for VIR_FROM_RPC error domain · a9c32b5d
      Daniel P. Berrange 提交于
      The VIR_FROM_RPC error domain is used generically for any RPC
      problem, not simply XML-RPC problems.
      
      * src/util/virterror.c: s/XML-RPC/RPC/
      a9c32b5d
    • D
      Add compat function for geteuid() · bd82db40
      Daniel P. Berrange 提交于
      * configure.ac: Check for geteuid()
      * src/util/util.h: Compat for geteuid()
      bd82db40
    • D
      Fix misc bugs in virCommandPtr · 2a2a00eb
      Daniel P. Berrange 提交于
      The virCommandNewArgs() method would free the virCommandPtr
      if it failed to add the args. This meant errors reported in
      virCommandAddArgSet() were lost. Simply removing the check
      for errors from the constructor means they can be reported
      correctly later
      
      The virCommandAddEnvPassCommon() method failed to check for
      errors before reallocating the cmd->env array, causing a
      potential SEGV if cmd was NULL
      
      The virCommandAddArgSet() method needs to validate that at
      least 1 element in 'val's parameter is non-NULL, otherwise
      code like
      
          cmd = virCommandNew(binary)
          virCommandAddAtg(cmd, "foo")
      
      Would end up trying todo  execve("foo"), if binary was
      NULL.
      2a2a00eb
    • D
      Add virSetBlocking() to allow O_NONBLOCK to be toggle on or off · 2737b6c2
      Daniel P. Berrange 提交于
      The virSetNonBlock() API only allows enabling non-blocking
      operations. It doesn't allow turning blocking back on. Add
      a new API to allow arbitrary toggling.
      
      * src/libvirt_private.syms, src/util/util.h
        src/util/util.c: Add virSetBlocking
      2737b6c2
    • D
      Allow to dynamically set the size of the debug buffer · b16f47ab
      Daniel Veillard 提交于
      This is the part allowing to dynamically resize the debug log
      buffer from it's default 64kB size. The buffer is now dynamically
      allocated.
      It adds a new API virLogSetBufferSize() which resizes the buffer
      If passed a zero size, the buffer is deallocated and we do the small
      optimization of not formatting messages which are not output anymore.
      On the daemon side, it just adds a new option log_buffer_size to
      libvirtd.conf and call virLogSetBufferSize() if needed
      * src/util/logging.h src/util/logging.c src/libvirt_private.syms:
        make buffer dynamic and add virLogSetBufferSize() internal API
      * daemon/libvirtd.conf: document the new log_buffer_size option
      * daemon/libvirtd.c: read and use the new log_buffer_size option
      b16f47ab
  12. 10 3月, 2011 2 次提交
    • E
      cgroup: allow fine-tuning of device ACL permissions · 5564c575
      Eric Blake 提交于
      Adding audit points showed that we were granting too much privilege
      to qemu; it should not need any mknod rights to recreate any
      devices.  On the other hand, lxc should have all device privileges.
      The solution is adding a flag parameter.
      
      This also lets us restrict write access to read-only disks.
      
      * src/util/cgroup.h (virCgroup*Device*): Adjust prototypes.
      * src/util/cgroup.c (virCgroupAllowDevice)
      (virCgroupAllowDeviceMajor, virCgroupAllowDevicePath)
      (virCgroupDenyDevice, virCgroupDenyDeviceMajor)
      (virCgroupDenyDevicePath): Add parameter.
      * src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update clients.
      * src/lxc/lxc_controller.c (lxcSetContainerResources): Likewise.
      * src/qemu/qemu_cgroup.c: Likewise.
      (qemuSetupDiskPathAllow): Also, honor read-only disks.
      5564c575
    • E
      audit: also audit cgroup controller path · f2512684
      Eric Blake 提交于
      Although the cgroup device ACL controller path can be worked out
      by researching the code, it is more efficient to include that
      information directly in the audit message.
      
      * src/util/cgroup.h (virCgroupPathOfController): New prototype.
      * src/util/cgroup.c (virCgroupPathOfController): Export.
      * src/libvirt_private.syms: Likewise.
      * src/qemu/qemu_audit.c (qemuAuditCgroup): Use it.
      f2512684
  13. 09 3月, 2011 2 次提交
    • E
      docs: silence warnings about generated API docs · b12a0280
      Eric Blake 提交于
      I noticed these while testing 'make dist'.
      
      Parsing ./../src/util/event.c
      Function comment for virEventRegisterDefaultImpl lacks description of return value
      Function comment for virEventRunDefaultImpl lacks description of return value
      Parsing ./../src/util/virterror.c
      Missing comment for function virSetErrorLogPriorityFunc
      
      * src/util/event.c (virEventRegisterDefaultImpl)
      (virEventRunDefaultImpl): Document return types.
      * src/util/virterror.c (virSetErrorLogPriorityFunc): Provide docs.
      b12a0280
    • E
      build: fix build on cygwin · b1a5aefc
      Eric Blake 提交于
      On cygwin:
      
        CC        libvirt_util_la-cgroup.lo
      util/cgroup.c: In function 'virCgroupKillRecursiveInternal':
      util/cgroup.c:1458: warning: implicit declaration of function 'virCgroupNew' [-Wimplicit-function-declaration]
      
      * src/util/cgroup.c (virCgroupKill): Don't build on platforms
      where virCgroupNew is unsupported.
      b1a5aefc
  14. 08 3月, 2011 2 次提交
    • D
      Fix build on cygwin · d299e1d0
      Daniel Veillard 提交于
      Apparently some signals found on Unix are not exposed, this led
      to a compilation failure
      * src/util/logging.c: make code related to each signal dependant
        upon the definition of that signal
      d299e1d0
    • W
      unlock eventLoop before calling callback function · ac9ee6b5
      Wen Congyang 提交于
      When I use newest libvirt to save a domain, libvirtd will be deadlock.
      Here is the output of gdb:
      (gdb) thread 3
      [Switching to thread 3 (Thread 0x7f972a1fc710 (LWP 30265))]#0  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
      (gdb) bt
          at qemu/qemu_driver.c:2074
          ret=0x7f972a1fbbe0) at remote.c:2273
      (gdb) thread 7
      [Switching to thread 7 (Thread 0x7f9730bcd710 (LWP 30261))]#0  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
      (gdb) bt
      (gdb) p *(virMutexPtr)0x6fdd60
      $2 = {lock = {__data = {__lock = 2, __count = 0, __owner = 30261, __nusers = 1, __kind = 0, __spins = 0, __list = {__prev = 0x0, __next = 0x0}},
          __size = "\002\000\000\000\000\000\000\000\065v\000\000\001", '\000' <repeats 26 times>, __align = 2}}
      (gdb) p *(virMutexPtr)0x1a63ac0
      $3 = {lock = {__data = {__lock = 2, __count = 0, __owner = 30265, __nusers = 1, __kind = 0, __spins = 0, __list = {__prev = 0x0, __next = 0x0}},
          __size = "\002\000\000\000\000\000\000\000\071v\000\000\001", '\000' <repeats 26 times>, __align = 2}}
      (gdb) info threads
        7 Thread 0x7f9730bcd710 (LWP 30261)  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
        6 Thread 0x7f972bfff710 (LWP 30262)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
        5 Thread 0x7f972b5fe710 (LWP 30263)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
        4 Thread 0x7f972abfd710 (LWP 30264)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
      * 3 Thread 0x7f972a1fc710 (LWP 30265)  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
        2 Thread 0x7f97297fb710 (LWP 30266)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
        1 Thread 0x7f9737aac800 (LWP 30260)  0x000000351fe0803d in pthread_join () from /lib64/libpthread.so.0
      
      The reason is that we will try to lock some object in callback function, and we may call event API with locking the same object.
      In the function virEventDispatchHandles(), we unlock eventLoop before calling callback function. I think we should
      do the same thing in the function virEventCleanupTimeouts() and virEventCleanupHandles().
      Signed-off-by: NWen Congyang <wency@cn.fujitsu.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      ac9ee6b5
  15. 07 3月, 2011 3 次提交
    • D
      Expose event loop implementation as a public API · 2ed6cc7b
      Daniel P. Berrange 提交于
      Not all applications have an existing event loop they need
      to integrate with. Forcing them to implement the libvirt
      event loop integration APIs is an undue burden. This just
      exposes our simple poll() based implementation for apps
      to use. So instead of calling
      
         virEventRegister(....callbacks...)
      
      The app would call
      
         virEventRegisterDefaultImpl()
      
      And then have a thread somewhere calling
      
          static bool quit = false;
          ....
          while (!quit)
            virEventRunDefaultImpl()
      
      * daemon/libvirtd.c, tools/console.c,
        tools/virsh.c: Convert to public event loop APIs
      * include/libvirt/libvirt.h.in, src/libvirt_private.syms: Add
        virEventRegisterDefaultImpl and virEventRunDefaultImpl
      * src/util/event.c: Implement virEventRegisterDefaultImpl
        and virEventRunDefaultImpl using poll() event loop
      * src/util/event_poll.c: Add full error reporting
      * src/util/virterror.c, include/libvirt/virterror.h: Add
        VIR_FROM_EVENTS
      2ed6cc7b
    • D
      Move event code out of the daemon/ into src/util/ · 343eaa15
      Daniel P. Berrange 提交于
      The event loop implementation is used by more than just the
      daemon, so move it into the shared area.
      
      * daemon/event.c, src/util/event_poll.c: Renamed
      * daemon/event.h, src/util/event_poll.h: Renamed
      * tools/Makefile.am, tools/console.c, tools/virsh.c: Update
        to use new virEventPoll APIs
      * daemon/mdns.c, daemon/mdns.c, daemon/Makefile.am: Update
        to use new virEventPoll APIs
      343eaa15
    • D
      Cleaning up some of the logging code · bcb40b85
      Daniel Veillard 提交于
      * src/util/logging.c: fix virLogDumpAllFD() to avoid snprintf, simplify
        the code and provide more useful signal descriptions. Also remove an
        unused variable.
      bcb40b85
  16. 05 3月, 2011 1 次提交
  17. 04 3月, 2011 3 次提交