1. 10 3月, 2011 3 次提交
    • 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: rename remaining qemu audit functions · 48096a00
      Eric Blake 提交于
      Also add ATTRIBUTE_NONNULL markers.
      
      * src/qemu/qemu_audit.h: The pattern qemuDomainXXXAudit is
      inconsistent; prefer qemuAuditXXX instead.
      * src/qemu/qemu_audit.c: Reflect the renames.
      * src/qemu/qemu_driver.c: Likewise.
      * src/qemu/qemu_hotplug.c: Likewise.
      * src/qemu/qemu_migration.c: Likewise.
      * src/qemu/qemu_process.c: Likewise.
      48096a00
    • E
      audit: split cgroup audit types to allow more information · d04916fa
      Eric Blake 提交于
      Device names can be manipulated, so it is better to also log
      the major/minor device number corresponding to the cgroup ACL
      changes that libvirt made.  This required some refactoring
      of the relatively new qemu cgroup audit code.
      
      Also, qemuSetupChardevCgroup was only auditing on failure, not success.
      
      * src/qemu/qemu_audit.h (qemuDomainCgroupAudit): Delete.
      (qemuAuditCgroup, qemuAuditCgroupMajor, qemuAuditCgroupPath): New
      prototypes.
      * src/qemu/qemu_audit.c (qemuDomainCgroupAudit): Rename...
      (qemuAuditCgroup): ...and drop a parameter.
      (qemuAuditCgroupMajor, qemuAuditCgroupPath): New functions, to
      allow listing device major/minor in audit.
      (qemuAuditGetRdev): New helper function.
      * src/qemu/qemu_driver.c (qemudDomainSaveFlag): Adjust callers.
      * src/qemu/qemu_cgroup.c (qemuSetupDiskPathAllow)
      (qemuSetupHostUsbDeviceCgroup, qemuSetupCgroup)
      (qemuTeardownDiskPathDeny): Likewise.
      (qemuSetupChardevCgroup): Likewise, fixing missing audit.
      d04916fa
  2. 09 3月, 2011 2 次提交
    • C
      Don't overwrite virRun error messages · 91893014
      Cole Robinson 提交于
      virRun gives pretty useful error output, let's not overwrite it unless there
      is a good reason. Some places were providing more information about what
      the commands were _attempting_ to do, however that's usually less useful from
      a debugging POV than what actually happened.
      91893014
    • H
      Fix a wrong error message thrown to user · 83d35233
      Hu Tao 提交于
      * src/qemu/qemu_driver.c: qemuDomainUpdateDeviceFlags() is not disk
        specific as the message suggests
      83d35233
  3. 08 3月, 2011 2 次提交
  4. 02 3月, 2011 1 次提交
    • E
      qemu: avoid double close on domain restore · 4f805dcd
      Eric Blake 提交于
      qemudDomainSaveImageStartVM was evil - it closed the incoming fd
      argument on some, but not all, code paths, without informing the
      caller about that action.  No wonder that this resulted in
      double-closes: https://bugzilla.redhat.com/show_bug.cgi?id=672725
      
      * src/qemu/qemu_driver.c (qemudDomainSaveImageStartVM): Alter
      signature, to avoid double-close.
      (qemudDomainRestore, qemudDomainObjRestore): Update callers.
      4f805dcd
  5. 25 2月, 2011 5 次提交
    • D
      Allow hash tables to use generic pointers as keys · 16ba2aaf
      Daniel P. Berrange 提交于
      Relax the restriction that the hash table key must be a string
      by allowing an arbitrary hash code generator + comparison func
      to be provided
      
      * util/hash.c, util/hash.h: Allow any pointer as a key
      * internal.h: Include stdbool.h as standard.
      * conf/domain_conf.c, conf/domain_conf.c,
        conf/nwfilter_params.c, nwfilter/nwfilter_gentech_driver.c,
        nwfilter/nwfilter_gentech_driver.h, nwfilter/nwfilter_learnipaddr.c,
        qemu/qemu_command.c, qemu/qemu_driver.c,
        qemu/qemu_process.c, uml/uml_driver.c,
        xen/xm_internal.c: s/char */void */ in hash callbacks
      16ba2aaf
    • E
      audit: audit qemu memory and vcpu adjusments · e25f2c74
      Eric Blake 提交于
      * src/qemu/qemu_audit.h (qemuDomainMemoryAudit)
      (qemuDomainVcpuAudit): New prototypes.
      * src/qemu/qemu_audit.c (qemuDomainResourceAudit)
      (qemuDomainMemoryAudit, qemuDomainVcpuAudit): New functions.
      (qemuDomainStartAudit): Call as appropriate.
      * src/qemu/qemu_driver.c (qemudDomainSetMemory)
      (qemudDomainHotplugVcpus): Likewise.
      e25f2c74
    • E
      audit: add qemu hooks for auditing cgroup events · 6bb98d41
      Eric Blake 提交于
      * src/qemu/qemu_audit.h (qemuDomainCgroupAudit): New prototype.
      * src/qemu/qemu_audit.c (qemuDomainCgroupAudit): Implement it.
      * src/qemu/qemu_driver.c (qemudDomainSaveFlag): Add audit.
      * src/qemu/qemu_cgroup.c (qemuSetupDiskPathAllow)
      (qemuSetupChardevCgroup, qemuSetupHostUsbDeviceCgroup)
      (qemuSetupCgroup, qemuTeardownDiskPathDeny): Likewise.
      6bb98d41
    • E
      audit: prepare qemu for listing vm in cgroup audits · b4d3434f
      Eric Blake 提交于
      * src/qemu/qemu_cgroup.h (struct qemuCgroupData): New helper type.
      (qemuSetupDiskPathAllow, qemuSetupChardevCgroup)
      (qemuTeardownDiskPathDeny): Drop unneeded prototypes.
      (qemuSetupDiskCgroup, qemuTeardownDiskCgroup): Adjust prototype.
      * src/qemu/qemu_cgroup.c
      (qemuSetupDiskPathAllow, qemuSetupChardevCgroup)
      (qemuTeardownDiskPathDeny): Mark static and use new type.
      (qemuSetupHostUsbDeviceCgroup): Use new type.
      (qemuSetupDiskCgroup): Alter signature.
      (qemuSetupCgroup): Adjust caller.
      * src/qemu/qemu_hotplug.c (qemuDomainAttachHostUsbDevice)
      (qemuDomainDetachPciDiskDevice, qemuDomainDetachSCSIDiskDevice):
      Likewise.
      * src/qemu/qemu_driver.c (qemudDomainAttachDevice)
      (qemuDomainUpdateDeviceFlags): Likewise.
      b4d3434f
    • E
      cgroup: determine when skipping non-devices · 06173876
      Eric Blake 提交于
      * src/util/cgroup.c (virCgroupAllowDevicePath)
      (virCgroupDenyDevicePath): Don't fail with EINVAL for
      non-devices.
      * src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update caller.
      * src/qemu/qemu_cgroup.c (qemuSetupDiskPathAllow)
      (qemuSetupChardevCgroup, qemuSetupHostUsbDeviceCgroup)
      (qemuSetupCgroup, qemuTeardownDiskPathDeny): Likewise.
      06173876
  6. 24 2月, 2011 3 次提交
  7. 23 2月, 2011 1 次提交
    • E
      security: avoid memory leak · 009fce98
      Eric Blake 提交于
      Leak introduced in commit d6623003.
      
      * src/qemu/qemu_driver.c (qemuSecurityInit): Avoid leak on failure.
      * src/security/security_stack.c (virSecurityStackClose): Avoid
      leaking component drivers.
      009fce98
  8. 17 2月, 2011 3 次提交
    • D
      Move all the QEMU migration code to a new file · 766de435
      Daniel P. Berrange 提交于
      The introduction of the v3 migration protocol, along with
      support for migration cookies, will significantly expand
      the size of the migration code. Move it all to a separate
      file to make it more manageable
      
      The functions are not moved 100%. The API entry points
      remain in the main QEMU driver, but once the public
      virDomainPtr is resolved to the internal virDomainObjPtr,
      all following code is moved.
      
      This will allow the new v3 API entry points to call into the
      same shared internal migration functions
      
      * src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Add
        qemuDomainFormatXML helper method
      * src/qemu/qemu_driver.c: Remove all migration code
      * src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Add
        all migration code.
      766de435
    • D
      Split all QEMU process mangement code into separate file · 48c2d6c6
      Daniel P. Berrange 提交于
      Move the qemudStartVMDaemon and qemudShutdownVMDaemon
      methods into a separate file, renaming them to
      qemuProcessStart, qemuProcessStop. All helper methods
      called by these are also moved & renamed to match
      
      * src/Makefile.am: Add qemu_process.c/.h
      * src/qemu/qemu_command.c: Add qemuDomainAssignPCIAddresses
      * src/qemu/qemu_command.h: Add VNC port min/max
      * src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Add
        domain event queue helpers
      * src/qemu/qemu_driver.c, src/qemu/qemu_driver.h: Remove
        all QEMU process startup/shutdown functions
      * src/qemu/qemu_process.c, src/qemu/qemu_process.h: Add
        all QEMU process startup/shutdown functions
      48c2d6c6
    • O
      qemu: Error prompt when saving a shutoff domain · cd951ad2
      Osier Yang 提交于
      "qemudDomainSaveFlag" goto wrong label "endjob", which will cause
      error when security manager trying to restore label (regression).
      
      As it's more reasonable to check if vm is shutoff immediately, and
      return right away if it is, remove the checking in "qemudDomainSaveFlag",
      and add checking in "qemudDomainSave".
      
      * src/qemu/qemu_driver.c
      cd951ad2
  9. 16 2月, 2011 1 次提交
    • E
      qemu: avoid NULL derefs · abaa6560
      Eric Blake 提交于
      The processWatchdogEvent fix is real, although it can only trigger
      on OOM, since bad things happen if doCoreDump is called with a NULL
      pathname argument.  The other fixes silence clang, but aren't a real
      bug because virReportErrorHelper tolerates a NULL format string even
      though *printf does not.
      
      * src/qemu/qemu_driver.c (processWatchdogEvent): Exit on OOM.
      (qemuDomainIsActive, qemuDomainIsPersistent, qemuDomainIsUpdated):
      Provide valid message.
      abaa6560
  10. 15 2月, 2011 1 次提交
    • D
      Fix cleanup on VM state after failed QEMU startup · 41f551e2
      Daniel P. Berrange 提交于
      Commit 9962e406 introduced a
      problem where if the VM failed to startup, it would not be
      correctly cleaned up. Amongst other things the SELinux
      security label would not be removed, which prevents the VM
      from ever starting again.
      
      The virDomainIsActive() check at the start of qemudShutdownVMDaemon
      checks for vm->def->id not being -1. By moving the assignment of the
      VM id to the start of qemudStartVMDaemon, we can ensure cleanup will
      occur on failure
      
      * src/qemu/qemu_driver.c: Move initialization of 'vm->def->id'
        so that qemudShutdownVMDaemon() will process the shutdown
      41f551e2
  11. 12 2月, 2011 1 次提交
  12. 11 2月, 2011 1 次提交
    • W
      qemu: fix attach-interface regression · 6bf4788e
      Wen Congyang 提交于
      QEMUD_CMD_FLAG_PCI_MULTIBUS should be set in the function
      qemuCapsExtractVersionInfo()
      
      The flag QEMUD_CMD_FLAG_PCI_MULTIBUS is used in the function
      qemuBuildDeviceAddressStr(). All callers get qemuCmdFlags
      by the function qemuCapsExtractVersionInfo() except that
      testCompareXMLToArgvFiles() in qemuxml2argvtest.c.
      
      So we should set QEMUD_CMD_FLAG_PCI_MULTIBUS in the function
      qemuCapsExtractVersionInfo() instead of qemuBuildCommandLine()
      because the function qemuBuildCommandLine() does not be called
      when we attach a pci device.
      
      tests: set QEMUD_CMD_FLAG_PCI_MULTIBUS in testCompareXMLToArgvFiles()
      
      set QEMUD_CMD_FLAG_PCI_MULTIBUS before calling qemuBuildCommandLine()
      as the flags is not set by qemuCapsExtractVersionInfo().
      Signed-off-by: NWen Congyang <wency@cn.fujitsu.com>
      6bf4788e
  13. 10 2月, 2011 1 次提交
    • D
      Reduce log level when cgroups aren't mounted · eacb3bb0
      Daniel P. Berrange 提交于
      Quite a few hosts don't have cgroups mounted and so see warnings
      from libvirt logged, which then cause bug reports, etc. Reduce
      the log level to INFO so they're not visible by default
      
      * src/qemu/qemu_driver.c: Reduce log level for cgroups
      eacb3bb0
  14. 09 2月, 2011 2 次提交
    • E
      sysinfo: implement qemu support · 5ec8fb56
      Eric Blake 提交于
      * src/qemu/qemu_driver.c (qemuGetSysinfo): New function.
      (qemuDriver): Install it.
      5ec8fb56
    • E
      sysinfo: define internal driver API · dec13a5a
      Eric Blake 提交于
      * src/driver.h (virDrvGetSysinfo): New typedef.
      (_virDriver): New callback member.
      * src/esx/esx_driver.c (esxDriver): Add stub for driver.
      * src/lxc/lxc_driver.c (lxcDriver): Likewise.
      * src/opennebula/one_driver.c (oneDriver): Likewise.
      * src/openvz/openvz_driver.c (openvzDriver): Likewise.
      * src/phyp/phyp_driver.c (phypDriver): Likewise.
      * src/qemu/qemu_driver.c (qemuDriver): Likewise.
      * src/remote/remote_driver.c (remote_driver): Likewise.
      * src/test/test_driver.c (testDriver): Likewise.
      * src/uml/uml_driver.c (umlDriver): Likewise.
      * src/vbox/vbox_tmpl.c (Driver): Likewise.
      * src/vmware/vmware_driver.c (vmwareDriver): Likewise.
      * src/xen/xen_driver.c (xenUnifiedDriver): Likewise.
      * src/xenapi/xenapi_driver.c (xenapiDriver): Likewise.
      dec13a5a
  15. 04 2月, 2011 2 次提交
    • J
      qemu: Add shortcut for HMP pass through · 2169472a
      Jiri Denemark 提交于
      Currently users who want to use virDomainQemuMonitorCommand() API or
      it's virsh equivalent has to use the same protocol as libvirt uses for
      communication to qemu. Since the protocol is QMP with current qemu and
      HMP much more usable for humans, one ends up typing something like the
      following:
      
          virsh qemu-monitor-command DOM \
      '{"execute":"human-monitor-command","arguments":{"command-line":"info kvm"}}'
      
      which is not a very convenient way of debugging qemu.
      
      This patch introduces --hmp option to qemu-monitor-command, which says
      that the provided command is in HMP. If libvirt uses QMP to talk with
      qemu, the command will automatically be converted into QMP. So the
      example above is simplified to just
      
          virsh qemu-monitor-command --hmp DOM "info kvm"
      
      Also the result is converted from
      
          {"return":"kvm support: enabled\r\n"}
      
      to just plain HMP:
      
          kvm support: enabled
      
      If libvirt talks to qemu in HMP, --hmp flag is obviously a noop.
      2169472a
    • E
      qemu: avoid double shutdown · 9962e406
      Eric Blake 提交于
      * src/qemu/qemu_driver.c (qemudShutdownVMDaemon): Check that vm is
      still active.
      Reported by Wen Congyang as follows:
      
      Steps to reproduce this bug:
      
      1. use gdb to debug libvirtd, and set breakpoint in the function
         qemuConnectMonitor()
      2. start a vm, and the libvirtd will be stopped in qemuConnectMonitor()
      3. kill -STOP $(cat /var/run/libvirt/qemu/<domain>.pid)
      4. continue to run libvirtd in gdb, and libvirtd will be blocked in the
         function qemuMonitorSetCapabilities()
      5. kill -9 $(cat /var/run/libvirt/qemu/<domain>.pid)
      
      Here is log of the qemu:
      =========
      LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin ...
      char device redirected to /dev/pts/3
      2011-01-27 09:38:48.101: shutting down
      2011-01-27 09:41:26.401: shutting down
      =========
      
      The vm is shut down twice. I do not know whether this behavior has
      side effect, but I think we should shutdown the vm only once.
      9962e406
  16. 31 1月, 2011 1 次提交
  17. 28 1月, 2011 4 次提交
    • D
      Remove bogus log warning lines when launching QEMU · 0095edaa
      Daniel P. Berrange 提交于
      The refactoring of QEMU command startup was comitted with
      a couple of VIR_WARN lines left in from debugging.
      
      * src/qemu/qemu_driver.c: Remove log warning lines
      0095edaa
    • D
      Remove double close of qemu monitor · e85247e7
      Daniel P. Berrange 提交于
      When qemuMonitorSetCapabilities() fails, there is no need to
      call qemuMonitorClose(), because the caller will already see
      the error code and tear down the entire VM. The extra call to
      qemuMonitorClose resulted in a double-free due to it removing
      a ref count prematurely.
      
      * src/qemu/qemu_driver.c: Remove premature close of monitor
      e85247e7
    • E
      qemu: fix error messages · b96b6f47
      Eric Blake 提交于
      Regression in commit caa805ea let a lot of bad messages slip in.
      
      * cfg.mk (msg_gen_function): Fix function name.
      * src/qemu/qemu_cgroup.c (qemuRemoveCgroup): Fix fallout from
      'make syntax-check'.
      * src/qemu/qemu_driver.c (qemudDomainGetInfo)
      (qemuDomainWaitForMigrationComplete, qemudStartVMDaemon)
      (qemudDomainSaveFlag, qemudDomainAttachDevice)
      (qemuDomainUpdateDeviceFlags): Likewise.
      * src/qemu/qemu_hotplug.c (qemuDomainAttachHostUsbDevice)
      (qemuDomainDetachPciDiskDevice, qemuDomainDetachSCSIDiskDevice):
      Likewise.
      b96b6f47
    • W
      avoid vm to be deleted if qemuConnectMonitor failed · d96431f9
      Wen Congyang 提交于
      Steps to reproduce this bug:
      1. service libvirtd start
      2. virsh start <domain>
      3. kill -STOP $(cat /var/run/libvirt/qemu/<domain>.pid)
      4. service libvirtd restart
      5. kill -9 $(cat /var/run/libvirt/qemu/<domain>.pid)
      
      Then libvirtd will core dump or be in deadlock state.
      
      Make sure that json is built into libvirt and the version
      of qemu is newer than 0.13.0.
      
      The reason of libvirtd cores dump is that:
      We add vm->refs when we alloc the memory, and decrease it
      in the function qemuHandleMonitorEOF() in other thread.
      
      We add vm->refs in the function qemuConnectMonitor() and
      decrease it when the vm is inactive.
      
      The libvirtd will block in the function qemuMonitorSetCapabilities()
      because the vm is stopped by signal SIGSTOP. Now the vm->refs is 2.
      
      Then we kill the vm by signal SIGKILL. The function
      qemuMonitorSetCapabilities() failed, and then we will decrease vm->refs
      in the function qemuMonitorClose().
      In another thread, mon->fd is broken and the function
      qemuHandleMonitorEOF() is called.
      
      If qemuHandleMonitorEOF() decreases vm->refs before qemuConnectMonitor()
      returns, vm->refs will be decrease to 0 and the memory is freed.
      
      We will call qemudShutdownVMDaemon() as qemuConnectMonitor() failed.
      The memory has been freed, so qemudShutdownVMDaemon() is too dangerous.
      
      We will reference NULL pointer in the function virDomainConfVMNWFilterTeardown():
      =============
      void
      virDomainConfVMNWFilterTeardown(virDomainObjPtr vm) {
          int i;
      
          if (nwfilterDriver != NULL) {
              for (i = 0; i < vm->def->nnets; i++)
                  virDomainConfNWFilterTeardown(vm->def->nets[i]);
          }
      }
      ============
      vm->def->nnets is not 0 but vm->def->nets is NULL(We don't set vm->def->nnets
      to 0 when we free vm).
      
      We should add an extra reference of vm to avoid vm to be deleted if
      qemuConnectMonitor() failed.
      Signed-off-by: NWen Congyang <wency@cn.fujitsu.com>
      d96431f9
  18. 26 1月, 2011 3 次提交
    • L
      Manually kill gzip if restore fails before starting qemu · c9c794b5
      Laine Stump 提交于
      If a guest image is saved in compressed format, and the restore fails
      in some way after the intermediate process used to uncompress the
      image has been started, but before qemu has been started to hook up to
      the uncompressor, libvirt will endlessly wait for the uncompressor to
      finish, but it never will because it's still waiting to have something
      hooked up to drain its output.
      
      The solution is to close the pipes on both sides of the uncompressor,
      then send a SIGTERM before calling waitpid on it (only if the restore
      has failed, of course).
      c9c794b5
    • L
      Set SELinux context label of pipes used for qemu migration · 34a19dda
      Laine Stump 提交于
      This patch is a partial resolution to the following bug:
      
         https://bugzilla.redhat.com/show_bug.cgi?id=667756
      
      (to complete the fix, an updated selinux-policy package is required,
      to add the policy that allows libvirt to set the context of a fifo,
      which was previously not allowed).
      
      Explanation : When an incoming migration is over a pipe (for example,
      if the image was compressed and is being fed through gzip, or was on a
      root-squash nfs server, so needed to be opened by a child process
      running as a different uid), qemu cannot read it unless the selinux
      context label for the pipe has been set properly.
      
      The solution is to check the fd used as the source of the migration
      just before passing it to qemu; if it's a fifo (implying that it's a
      pipe), we call the newly added virSecurityManagerSetFDLabel() function
      to set the context properly.
      34a19dda
    • O
      qemu: Error prompt when managed save a shutoff domain · dbd63c4d
      Osier Yang 提交于
      The problem was introduced by commit 4303c91c, which removed the checking
      of domain state, this patch is to fix it.
      
      Otherwise, improper error will be thrown, e.g.
      
      error: Failed to save domain rhel6 state
      error: cannot resolve symlink /var/lib/libvirt/qemu/save/rhel6.save: No such
      file or directory
      dbd63c4d
  19. 22 1月, 2011 3 次提交
    • C
      qemu: Allow serving VNC over a unix domain socket · 1d9c0a08
      Cole Robinson 提交于
      QEMU supports serving VNC over a unix domain socket rather than traditional
      TCP host/port. This is specified with:
      
      <graphics type='vnc' socket='/foo/bar/baz'/>
      
      This provides better security access control than VNC listening on
      127.0.0.1, but will cause issues with tools that rely on the lax security
      (virt-manager in fedora runs as regular user by default, and wouldn't be
      able to access a socket owned by 'qemu' or 'root').
      
      Also not currently supported by any clients, though I have patches for
      virt-manager, and virt-viewer should be simple to update.
      
      v2:
          schema: Make listen vs. socket a <choice>
      1d9c0a08
    • C
      qemu: Set domain def transient at beginning of startup process · cb4c2694
      Cole Robinson 提交于
      This will allow us to record transient runtime state in vm->def, like
      default VNC parameters. Accomplish this by adding an extra 'live' parameter
      to SetDefTransient, with similar semantics to the 'live' flag for
      AssignDef.
      cb4c2694
    • D
      Fix error reporting when machine type probe fails · f0bbf960
      Daniel P. Berrange 提交于
      Avoid overwriting the real error message with a generic
      OOM failure message, when machine type probe fails
      
      * src/qemu/qemu_driver.c: Don't overwrite error
      f0bbf960