1. 27 10月, 2012 9 次提交
    • E
      blockjob: allow mirroring under SELinux and cgroup · 35c7701c
      Eric Blake 提交于
      Use the recent addition of qemuDomainPrepareDiskChainElement to
      obtain locking manager lease, permit a block device through cgroups,
      and set the SELinux label; then audit the fact that we hand a new
      file over to qemu.  Alas, releasing the lease and label at the end
      of the mirroring is a trickier prospect (we would have to trace the
      backing chain of both source and destination, and be sure not to
      revoke rights to any part of the chain that is shared), so for now,
      virDomainBlockJobAbort still leaves things with additional access
      granted (as block-pull and block-commit have the same problem of
      not clamping access after completion, a future cleanup would cover
      all three commands).
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCopy): Set up labeling.
      35c7701c
    • E
      blockjob: allow for existing files in block-copy · 8ee5073c
      Eric Blake 提交于
      Support the REUSE_EXT flag, in part by copying sanity checks from
      snapshot code.  This code introduces a case of probing an external
      file for its type; such an action would be a security risk if the
      existing file is supposed to be raw but the contents resemble some
      other format; however, since the virDomainBlockRebase API has a
      flag to force treating the file as raw rather than probe, we can
      assume that probing is safe in all other instances.  Besides, if
      we don't probe or force raw, then qemu will.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockRebase): Allow REUSE_EXT
      flag.
      (qemuDomainBlockCopy): Wire up flag, and add some sanity checks.
      8ee5073c
    • E
      blockjob: implement block copy for qemu · c1eb3805
      Eric Blake 提交于
      Minimal patch to wire up all the pieces in the previous patches
      to actually enable a block copy job.  By minimal, I mean that
      qemu creates the file (that is, no REUSE_EXT flag support yet),
      SELinux must be disabled, a lock manager is not informed, and the
      audit logs aren't updated.  But those will be added as
      improvements in future patches.
      
      This patch is designed so that if we ever add a future API
      virDomainBlockCopy with more bells and whistles (such as letting
      the user specify a destination image format different than the
      source), where virDomainBlockRebase is a wrapper around the
      simpler portions of the new functionality, then the new API can
      just reuse the new qemuDomainBlockCopy function and already
      support _SHALLOW and _REUSE_EXT flags.  Also note that libvirt.c
      already filtered the new flags if _COPY is not present, so that
      we are not impacting the case of BlockRebase being a wrapper
      around BlockPull.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCopy): New function.
      (qemuDomainBlockRebase): Call it when appropriate.
      c1eb3805
    • E
      blockjob: make block pivot safer · 400ac797
      Eric Blake 提交于
      Since libvirt drops locks between issuing a monitor command and
      getting a response, it is possible for libvirtd to be restarted
      before getting a response on a block-job-complete command; worse, it
      is also possible for the guest to shut itself down during the window
      while libvirtd is down, ending the qemu process.  A management app
      needs to know if the pivot happened (and the destination file
      contains guest contents not in the source) or failed (and the source
      file contains guest contents not in the destination), but since
      the job is finished, 'query-block-jobs' no longer tracks the
      status of the job, and if the qemu process itself has disappeared,
      even 'query-block' cannot be checked to ask qemu its current state.
      
      At the time of this patch, the design for persistent bitmap has not
      been clarified, so a followup patch will be needed once qemu
      actually figures out how to expose it, and we figure out how to use
      it.  In the meantime, we have a solution that avoids the worst of
      the problem.  [This problem was first analyzed with the RHEL 6.3
      __com.redhat_drive-reopen command; which partly explains why
      upstream qemu 1.3 ditched the drive-reopen idea and went with
      block-job-complete plus persistent bitmap instead.]
      
      If we surround 'drive-reopen' with a pause/resume pair, then we can
      guarantee that the guest cannot modify either source or destination
      files in the window of libvirtd uncertainty, and the management app
      is guaranteed that either libvirt knows the outcome and reported it
      correctly; or that on libvirtd restart, the guest will still be
      paused and that the qemu process cannot have disappeared due to
      guest shutdown; and use that as a clue that the management app must
      implement recovery protocol, with both source and destination files
      still being in sync and with 'query-block' still being an option as
      part of that recovery.  My testing shows that the pause window will
      typically be only a fraction of a second.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockPivot): Pause around
      drive-reopen.
      (qemuDomainBlockJobImpl): Update caller.
      400ac797
    • E
      blockjob: support pivot operation on cancel · eaba79d2
      Eric Blake 提交于
      This is the bare minimum to end a copy job (of course, until a
      later patch adds the ability to start a copy job, this patch
      doesn't do much in isolation; I've just split the patches to
      ease the review).
      
      This patch intentionally avoids SELinux, lock manager, and audit
      actions.  Also, if libvirtd restarts at the exact moment that a
      'block-job-complete' is in flight, the proposed proper way to
      detect the outcome of that would be with a persistent bitmap and
      some additional query commands when libvirtd restarts.  This
      patch is enough to test the common case of success when used
      correctly, while saving the subtleties of proper cleanup for
      worst-case errors for later.
      
      When a mirror job is started, cancelling the job safely reverts back
      to the source disk, regardless of whether the destination is in
      phase 1 (streaming, in which case the destination is worthless) or
      phase 2 (mirroring, in which case the destination is synced up to
      the source at the time of the cancel).  Our existing code does just
      fine in either phase, other than some bookkeeping cleanup; this
      implements live block copy.
      
      Ideas for future enhancements via new flags:
      
      Depending on when persistent bitmap support is added, it may be
      worth adding a VIR_DOMAIN_REBASE_COPY_ATOMIC flag that fails up
      front if we detect an older qemu with risky pivot operation.
      
      Interesting side note: while snapshot-create --disk-only creates a
      copy of the disk at a point in time by moving the domain on to a
      new file (the copy is the file now in the just-extended backing
      chain), blockjob --abort of a copy job creates a copy of the disk
      while keeping the domain on the original file.  There may be
      potential improvements to the snapshot code to exploit block copy
      over multiple disks all at one point in time.  And, if
      'block-job-cancel' were made part of 'transaction', you could
      copy multiple disks at the same point in time without pausing
      the domain.  This also implies we may want to add a --quiesce flag
      to virDomainBlockJobAbort, so that when breaking a mirror (whether
      by cancel or pivot), the side of the mirror that we are abandoning
      is at least in a stable state with regards to guest I/O.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockJobAbort): Accept new flag.
      (qemuDomainBlockPivot): New helper function.
      (qemuDomainBlockJobImpl): Implement it.
      eaba79d2
    • E
      blockjob: return appropriate event and info · edecd45c
      Eric Blake 提交于
      Handle the new type of block copy event and info.  Of course,
      this patch does nothing until a later patch actually allows the
      creation/abort of a block copy job.
      
      * include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_JOB_READY): New
      block job status.
      * src/libvirt.c (virDomainBlockRebase): Document the event.
      * src/qemu/qemu_monitor_json.c (eventHandlers): New event.
      (qemuMonitorJSONHandleBlockJobReady): New function.
      (qemuMonitorJSONGetBlockJobInfoOne): Translate new job type.
      (qemuMonitorJSONHandleBlockJobImpl): Handle new event and job type.
      * src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Recognize
      the event to minimize snooping.
      * src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Snoop a successful
      info query to save effort on a pivot request.
      edecd45c
    • E
      blockjob: react to active block copy · b3822ed0
      Eric Blake 提交于
      For now, disk migration via block copy job is not implemented in
      libvirt.  But when we do implement it, we have to deal with the
      fact that qemu does not yet provide an easy way to re-start a qemu
      process with mirroring still intact.  Paolo has proposed an idea
      for a persistent dirty bitmap that might make this possible, but
      until that design is complete, it's hard to say what changes
      libvirt would need.  Even something like 'virDomainSave' becomes
      hairy, if you realize the implications that 'virDomainRestore'
      would be stuck with recreating the same mirror layout.
      
      But if we step back and look at the bigger picture, we realize that
      the initial client of live storage migration via disk mirroring is
      oVirt, which always uses transient domains, and that if a transient
      domain is destroyed while a mirror exists, oVirt can easily restart
      the storage migration by creating a new domain that visits just the
      source storage, with no loss in data.
      
      We can make life a lot easier by being cowards for now, forbidding
      certain operations on a domain.  This patch guarantees that we
      never get in a state where we would have to restart a domain with
      a mirroring block copy, by preventing saves, snapshots, migration,
      hot unplug of a disk in use, and conversion to a persistent domain
      (thankfully, it is still relatively easy to 'virsh undefine' a
      running domain to temporarily make it transient, run tests on
      'virsh blockcopy', then 'virsh define' to restore the persistence).
      Later, if the qemu design is enhanced, we can relax our code.
      
      The change to qemudDomainDefine looks a bit odd for undoing an
      assignment, rather than probing up front to avoid the assignment,
      but this is because of how virDomainAssignDef combines both a
      lookup and assignment into a single function call.
      
      * src/conf/domain_conf.h (virDomainHasDiskMirror): New prototype.
      * src/conf/domain_conf.c (virDomainHasDiskMirror): New function.
      * src/libvirt_private.syms (domain_conf.h): Export it.
      * src/qemu/qemu_driver.c (qemuDomainSaveInternal)
      (qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot)
      (qemuDomainBlockJobImpl, qemudDomainDefine): Prevent dangerous
      actions while block copy is already in action.
      * src/qemu/qemu_hotplug.c (qemuDomainDetachDiskDevice): Likewise.
      * src/qemu/qemu_migration.c (qemuMigrationIsAllowed): Likewise.
      b3822ed0
    • L
      qemu: fix attach/detach of netdevs with matching mac addrs · def31e4c
      Laine Stump 提交于
      This resolves:
      
         https://bugzilla.redhat.com/show_bug.cgi?id=862515
      
      which describes inconsistencies in dealing with duplicate mac
      addresses on network devices in a domain.
      
      (at any rate, it resolves *almost* everything, and prints out an
      informative error message for the one problem that isn't solved, but
      has a workaround.)
      
      A synopsis of the problems:
      
      1) you can't do a persistent attach-interface of a device with a mac
      address that matches an existing device.
      
      2) you *can* do a live attach-interface of such a device.
      
      3) you *can* directly edit a domain and put in two devices with
      matching mac addresses.
      
      4) When running virsh detach-device (live or config), only MAC address
      is checked when matching the device to remove, so the first device
      with the desired mac address will be removed. This isn't always the
      one that's wanted.
      
      5) when running virsh detach-interface (live or config), the only two
      items that can be specified to match against are mac address and model
      type (virtio, etc) - if multiple netdevs match both of those
      attributes, it again just finds the first one added and assumes that
      is the only match.
      
      Since it is completely valid to have multiple network devices with the
      same MAC address (although it can cause problems in many cases, there
      *are* valid use cases), what is needed is:
      
      1) remove the restriction that prohibits doing a persistent add of a
      netdev with a duplicate mac address.
      
      2) enhance the backend of virDomainDetachDeviceFlags to check for
      something that *is* guaranteed unique (but still work with just mac
      address, as long as it yields only a single results.
      
      This patch does three things:
      
      1) removes the check for duplicate mac address during a persistent
      netdev attach.
      
      2) unifies the searching for both live and config detach of netdevices
      in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
      new function virDomainNetFindIdx (which matches mac address and PCI
      address if available, checking for duplicates if only mac address was
      specified). This function returns -2 if multiple matches are found,
      allowing the callers to print out an appropriate message.
      
      Steps 1 & 2 are enough to fully fix the problem when using virsh
      attach-device and detach-device (which require an XML description of
      the device rather than a bunch of commandline args)
      
      3) modifies the virsh detach-interface command to check for multiple
      matches of mac address and show an error message suggesting use of the
      detach-device command in cases where there are multiple matching mac
      addresses.
      
      Later we should decide how we want to input a PCI address on the virsh
      commandline, and enhance detach-interface to take a --address option,
      eliminating the need to use detach-device
      
      * src/conf/domain_conf.c
      * src/conf/domain_conf.h
      * src/libvirt_private.syms
        * added new virDomainNetFindIdx function
        * removed now unused virDomainNetIndexByMac and
          virDomainNetRemoveByMac
      
      * src/qemu/qemu_driver.c
        * remove check for duplicate max from qemuDomainAttachDeviceConfig
        * use virDomainNetFindIdx/virDomainNetRemove instead
          of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
        * use virDomainNetFindIdx instead of virDomainIndexByMac
          in qemuDomainUpdateDeviceConfig
      
      * src/qemu/qemu_hotplug.c
        * use virDomainNetFindIdx instead of a homespun loop in
          qemuDomainDetachNetDevice.
      
      * tools/virsh-domain.c: modified detach-interface command as described
          above
      def31e4c
    • E
      cpustat: fix regression when cpus are offline · 4fbf322f
      Eric Blake 提交于
      It turns out that the cpuacct results properly account for offline
      cpus, and always returns results for every possible cpu, not just
      the online ones.  So there is no need to check the map of online
      cpus in the first place, merely only a need to know the maximum
      possible cpu.  Meanwhile, virNodeGetCPUBitmap had a subtle change
      from returning the maximum id to instead returning the width of
      the bitmap (one larger than the maximum id) in commit 2f4c5338,
      which made this code encounter some off-by-one logic leading to
      bad error messages when a cpu was offline:
      
      $ virsh cpu-stats dom
      error: Failed to virDomainGetCPUStats()
      
      error: An error occurred, but the cause is unknown
      
      Cleaning this up unraveled a chain of other unused variables.
      
      * src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Drop
      pointless check for cpumap changes, and use correct number of
      cpus.  Simplify signature.
      (qemuDomainGetCPUStats): Adjust caller.
      * src/nodeinfo.h (nodeGetCPUCount): New prototype.
      (nodeGetCPUBitmap): Drop unused parameter.
      * src/nodeinfo.c (nodeGetCPUBitmap): Likewise.
      (nodeGetCPUMap): Adjust caller.
      (nodeGetCPUCount): New function.
      * src/libvirt_private.syms (nodeinfo.h): Export it.
      4fbf322f
  2. 26 10月, 2012 2 次提交
    • V
      virNodeGetCPUMap: Implement driver support · e3ba6703
      Viktor Mihajlovski 提交于
      Driver support added for:
      - test: pretending 8 host CPUS, 3 being online
      - qemu, lxc, openvz, uml: using nodeGetCPUMap
      Signed-off-by: NViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
      e3ba6703
    • E
      nodeinfo: improve probing node cpu bitmap · 2f4c5338
      Eric Blake 提交于
      Callers should not need to know what the name of the file to
      be read in the Linux-specific version of nodeGetCPUmap;
      furthermore, qemu cares about online cpus, not present cpus,
      when determining which cpus to skip.
      
      While at it, I fixed the fact that we were computing the maximum
      online cpu id by doing a slow iteration, when what we really want
      to know is the max available cpu.
      
      * src/nodeinfo.h (nodeGetCPUmap): Rename...
      (nodeGetCPUBitmap): ...and simplify signature.
      * src/nodeinfo.c (linuxParseCPUmax): New function.
      (linuxParseCPUmap): Simplify and alter signature.
      (nodeGetCPUBitmap): Change implementation.
      * src/libvirt_private.syms (nodeinfo.h): Reflect rename.
      * src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Update
      caller.
      2f4c5338
  3. 24 10月, 2012 1 次提交
  4. 23 10月, 2012 1 次提交
    • E
      snapshot: sanity check when reusing file for snapshot · 33eaebe4
      Eric Blake 提交于
      The snapshot code when reusing an existing file had hard-to-read
      logic, as well as a missing sanity check: REUSE_EXT should require
      the destination to already be present.
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare): Require
      destination on REUSE_EXT, rename variable for legibility.
      33eaebe4
  5. 22 10月, 2012 2 次提交
    • E
      storage: let format probing work on root-squash NFS · d9d77bfa
      Eric Blake 提交于
      Yet another instance of where using plain open() mishandles files
      that live on root-squash NFS, and where improving the API can
      improve the chance of a successful probe.
      
      * src/util/storage_file.h (virStorageFileProbeFormat): Alter
      signature.
      * src/util/storage_file.c (virStorageFileProbeFormat): Use better
      method for opening file.
      * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Update caller.
      * src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
      Likewise.
      d9d77bfa
    • J
      migrate: v2: use VIR_DOMAIN_XML_MIGRATABLE when available · b6ab7a06
      Ján Tomko 提交于
      In v2 migration protocol, XML is obtained by calling domainGetXMLDesc.
      This includes the default USB controller in XML, which breaks migration
      to older libvirt (before 0.9.2).
      
      Commit 409b5f54
          qemu: Emit compatible XML when migrating a domain
      only fixed this for v3 migration.
      
      This patch uses the new VIR_DOMAIN_XML_MIGRATABLE flag (detected by
      VIR_DRV_FEATURE_XML_MIGRATABLE) to obtain XML without the default controller,
      enabling backward v2 migration.
      b6ab7a06
  6. 20 10月, 2012 12 次提交
    • E
      blockjob: avoid segv on early error · a172dfbe
      Eric Blake 提交于
      Gcc with optimization warns:
      ../../src/qemu/qemu_driver.c: In function 'qemuDomainBlockCommit':
      ../../src/qemu/qemu_driver.c:12813:46: error: 'disk' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      ../../src/qemu/qemu_driver.c:12698:25: note: 'disk' was declared here
      cc1: all warnings being treated as errors
      
      so obviously I had only been testing with optimization off.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCommit): Guard cleanup.
      a172dfbe
    • E
      blockjob: properly label disks for qemu block-commit · 2e43cb8e
      Eric Blake 提交于
      I finally have all the pieces in place to perform a block-commit with
      SELinux enforcing.  There's still missing cleanup work when the commit
      completes, but doing that requires tracking both the backing chain and
      the base and top files within that chain in domain XML across libvirtd
      restarts.  Furthermore, from a security standpoint, once you have
      granted access, you must assume any damage that can be done will be
      done; later revoking access is nice to minimize the window of damage,
      but less important as it does not affect the fact that damage can be
      done in the first place.  Therefore, deferring the revoke efforts until
      we have better XML tracking of what chain operations are in effect,
      including across a libvirtd restart, is reasonable.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCommit): Label disks as
      needed.
      (qemuDomainPrepareDiskChainElement): Cast away const.
      2e43cb8e
    • E
      blockjob: refactor qemu disk chain permission grants · 35a2f5bc
      Eric Blake 提交于
      Previously, snapshot code did its own permission granting (lock
      manager, cgroup device controller, and security manager labeling)
      inline.  But now that we are adding block-commit and block-copy
      which also have to change permissions, it's better to reuse
      common code for the task.  While snapshot should fall back to
      no access if read-write access failed, block-commit will want to
      fall back to read-only access.  The common code doesn't know
      whether failure to grant read-write access should revert to no
      access (snapshot, block-copy) or read-only access (block-commit).
      This code can also be used to revoke access to unused files after
      block-pull.
      
      It might be nice to clean things up in a future patch by adding
      new functions to the lock manager, cgroup manager, and security
      manager that takes a single file name and applies context of a
      disk to that file, rather than the current semantics of applying
      context to the entire chain already associated to a disk.  That
      way, we could avoid the games this patch plays of temporarily
      swapping out the disk->src and related fields of the disk.  But
      that would involve more code changes, so this patch really is
      the smallest hack for doing the necessary work; besides, this
      patch is more or less code motion (the hack was already employed
      by the snapshot creation code, we are just making it reusable).
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateSingleDiskActive)
      (qemuDomainSnapshotUndoSingleDiskActive): Refactor labeling hacks...
      (qemuDomainPrepareDiskChainElement): ...into new function.
      35a2f5bc
    • E
      blockjob: implement shallow commit flag in qemu · 0a220e22
      Eric Blake 提交于
      Now that we can crawl the chain of backing files, we can do
      argument validation and implement the 'shallow' flag.  In
      testing this, I discovered that it can be handy to pass the
      shallow flag and an explicit base, as a means of validating
      that the base is indeed the file we expected.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCommit): Crawl through
      chain to implement shallow flag.
      * src/libvirt.c (virDomainBlockCommit): Relax API.
      0a220e22
    • E
      blockjob: wire up online qemu block-commit · 2cbc1fd8
      Eric Blake 提交于
      This is the bare minimum to kick off a block commit.  In particular,
      flags support is missing (shallow requires us to crawl the backing
      chain to determine the file name to pass to the qemu monitor command;
      delete requires us to track what needs to be deleted at the time
      the completion event fires).  Also, we are relying on qemu to do
      error checking (such as validating 'top' and 'base' as being members
      of the backing chain), including the fact that the current qemu code
      does not support committing the active layer (although it is still
      planned to add that before qemu 1.3).  Since the active layer won't
      change, we have it easy and do not have to alter the domain XML.
      Additionally, this will fail if SELinux is enforcing, because we fail
      to grant qemu proper read/write access to the files it will modify.
      
      * src/qemu/qemu_driver.c (qemuDomainBlockCommit): New function.
      (qemuDriver): Register it.
      2cbc1fd8
    • E
      blockjob: remove unused parameters after previous patch · 67aea3fb
      Eric Blake 提交于
      Minor cleanup made possible by previous simplifications.
      
      * src/qemu/qemu_cgroup.h (qemuSetupDiskCgroup)
      (qemuTeardownDiskCgroup): Alter signature.
      * src/qemu/qemu_cgroup.c (qemuSetupDiskCgroup)
      (qemuTeardownDiskCgroup, qemuSetupCgroup): Update all uses.
      * src/qemu/qemu_hotplug.c (qemuDomainDetachPciDiskDevice)
      (qemuDomainDetachDiskDevice): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainAttachDeviceDiskLive)
      (qemuDomainChangeDiskMediaLive)
      (qemuDomainSnapshotCreateSingleDiskActive)
      (qemuDomainSnapshotUndoSingleDiskActive): Likewise.
      67aea3fb
    • E
      storage: cache backing chain while qemu domain is live · 4d34c929
      Eric Blake 提交于
      Technically, we should not be re-probing any file that qemu might
      be currently writing to.  As such, we should cache the backing
      file chain prior to starting qemu.  This patch adds the cache,
      but does not use it until the next patch.
      
      Ultimately, we want to also store the chain in domain XML, so that
      it is remembered across libvirtd restarts, and so that the only
      kosher way to modify the backing chain of an offline domain will be
      through libvirt API calls, but we aren't there yet.  So for now, we
      merely invalidate the cache any time we do a live operation that
      alters the chain (block-pull, block-commit, external disk snapshot),
      as well as tear down the cache when the domain is not running.
      
      * src/conf/domain_conf.h (_virDomainDiskDef): New field.
      * src/conf/domain_conf.c (virDomainDiskDefFree): Clean new field.
      * src/qemu/qemu_domain.h (qemuDomainDetermineDiskChain): New
      prototype.
      * src/qemu/qemu_domain.c (qemuDomainDetermineDiskChain): New
      function.
      * src/qemu/qemu_driver.c (qemuDomainAttachDeviceDiskLive)
      (qemuDomainChangeDiskMediaLive): Pre-populate chain.
      (qemuDomainSnapshotCreateSingleDiskActive): Uncache chain before
      snapshot.
      * src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Update
      chain after block pull.
      4d34c929
    • E
      storage: don't require caller to pre-allocate metadata struct · 1fc95932
      Eric Blake 提交于
      Requiring pre-allocation was an unusual idiom.  It allowed iteration
      over the backing chain to use fewer mallocs, but made one-shot
      clients harder to read.  Also, this makes it easier for a future
      patch to move away from opening fds on every iteration over the chain.
      
      * src/util/storage_file.h (virStorageFileGetMetadataFromFD): Alter
      signature.
      * src/util/storage_file.c (virStorageFileGetMetadataFromFD): Allocate
      return value.
       (virStorageFileGetMetadata): Update clients.
      * src/conf/domain_conf.c (virDomainDiskDefForeachPath): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Likewise.
      * src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
      Likewise.
      1fc95932
    • E
      storage: use enum for snapshot driver type · 1246640b
      Eric Blake 提交于
      This is the last use of raw strings for disk formats throughout
      the src/conf directory.
      
      * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Store enum
      rather than string for disk type.
      * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear)
      (virDomainSnapshotDiskDefParseXML, virDomainSnapshotDefFormat):
      Adjust users.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare)
      (qemuDomainSnapshotCreateSingleDiskActive): Likewise.
      1246640b
    • E
      storage: use enum for disk driver type · e5e8d5d0
      Eric Blake 提交于
      Actually use the enum in the domain conf structure.
      
      * src/conf/domain_conf.h (_virDomainDiskDef): Store enum rather
      than string for disk type.
      * src/conf/domain_conf.c (virDomainDiskDefFree)
      (virDomainDiskDefParseXML, virDomainDiskDefFormat)
      (virDomainDiskDefForeachPath): Adjust users.
      * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenFormatSxprDisk):
      Likewise.
      * src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
      * src/vbox/vbox_tmpl.c (vboxAttachDrives): Likewise.
      * src/libxl/libxl_conf.c (libxlMakeDisk): Likewise.
      e5e8d5d0
    • E
      storage: use enum for default driver type · 09e7fb5e
      Eric Blake 提交于
      Express the default disk type as an enum, for easier handling.
      
      * src/conf/capabilities.h (_virCaps): Store enum rather than
      string for disk type.
      * src/conf/domain_conf.c (virDomainDiskDefParseXML): Adjust
      clients.
      * src/qemu/qemu_driver.c (qemuCreateCapabilities): Likewise.
      09e7fb5e
    • E
      storage: list more file types · f772b3d9
      Eric Blake 提交于
      When an image has no backing file, using VIR_STORAGE_FILE_AUTO
      for its type is a bit confusing.  Additionally, a future patch
      would like to reserve a default value for the case of no file
      type specified in the XML, but different from the current use
      of -1 to imply probing, since probing is not always safe.
      
      Also, a couple of file types were missing compared to supported
      code: libxl supports 'vhd', and qemu supports 'fat' for directories
      passed through as a file system.
      
      * src/util/storage_file.h (virStorageFileFormat): Add
      VIR_STORAGE_FILE_NONE, VIR_STORAGE_FILE_FAT, VIR_STORAGE_FILE_VHD.
      * src/util/storage_file.c (virStorageFileMatchesVersion): Match
      documentation when version probing not supported.
      (cowGetBackingStore, qcowXGetBackingStore, qcow1GetBackingStore)
      (qcow2GetBackingStoreFormat, qedGetBackingStore)
      (virStorageFileGetMetadataFromBuf)
      (virStorageFileGetMetadataFromFD): Take NONE into account.
      * src/conf/domain_conf.c (virDomainDiskDefForeachPath): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Likewise.
      * src/conf/storage_conf.c (virStorageVolumeFormatFromString): New
      function.
      (poolTypeInfo): Use it.
      f772b3d9
  7. 18 10月, 2012 1 次提交
    • J
      qemu: Always format CPU topology · f1c70100
      Jiri Denemark 提交于
      When libvirt cannot find a suitable CPU model for host CPU (easily
      reproducible by running libvirt in a guest), it would not provide CPU
      topology in capabilities XML either. Even though CPU topology is known
      and can be queried by virNodeGetInfo. With this patch, CPU topology will
      always be provided in capabilities XML regardless on the presence of CPU
      model.
      f1c70100
  8. 17 10月, 2012 1 次提交
    • M
      qemu: Pin the emulator when only cpuset is specified · ba63d8f7
      Martin Kletzander 提交于
      According to our recent changes (clarifications), we should be pinning
      qemu's emulator processes using the <vcpu> 'cpuset' attribute in case
      there is no <emulatorpin> specified.  This however doesn't work
      entirely as expected and this patch should resolve all the remaining
      issues.
      ba63d8f7
  9. 15 10月, 2012 4 次提交
    • L
      qemu: reorganize qemuDomainChangeNet and qemuDomainChangeNetBridge · 6bde0a1a
      Laine Stump 提交于
      This patch resolves:
      
        https://bugzilla.redhat.com/show_bug.cgi?id=805071
      
      to the extent that it can be resolved with current qemu functionality.
      It attempts to detect as many situations as possible when the simple
      operation of disconnecting an existing tap device from one bridge and
      attaching it to another will satisfy the change requested in
      virDomainUpdateDeviceFlags() for a network device. Before this patch,
      that situation could only be detected if the pre-change interface
      *and* the post-change interface definition were both "type='bridge'".
      After this patch, it can also be detected if the before or after
      interfaces are any combination of type='bridge' and type='network'
      (the networks can be <forward mode='nat|route|bridge'>, as long as
      they use a Linux host bridge and not macvtap connections).
      
      This extra effort is especially useful since the recent discovery that
      a netdev_del+netdev_add combo (to reconnect the network device with
      completely different hostside configuration) doesn't work properly
      with current qemu (1.2) unless it is accompanied by the matching
      device_del+device_add - see this mailing list message for details:
      
        http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02355.html
      
      (A slight modification of the patch referenced there has been prepared
      to apply on top of this patch, but won't be pushed until qemu can be
      made to work with it.)
      
      * qemuDomainChangeNet needs access to the virDomainDeviceDef that
      holds the new netdef (so that it can clear out the virDomainDeviceDef
      if it ends up using the NetDef to replace the original), so the
      virDomainNetDefPtr arg is replaced with a virDomainDeviceDefPtr.
      
      * qemuDomainChangeNet previously checked for *some* changes to the
      interface config, but this check was by no means complete. It was also
      a bit disorganized.
      
      This refactoring of the code is (I believe) complete in its check of
      all NetDef attributes that might be changed, and either returns a
      failure (for changes that are simply impossible), or sets one of three
      flags:
      
        needLinkStateChange - if the device link state needs to go up/down
        needBridgeChange    - if everything else is the same, but it needs
                              to be connected to a difference linux host
                              bridge
        needReconnect       - if the entire host side of the device needs
                              to be torn down and reconstructed (currently
                              non-working, as mentioned above)
      
      Note that this function will refuse to make any change that requires
      the *guest* side of the device to be detached (e.g. changing the PCI
      address or mac address). Those would be disruptive enough to the guest
      that it's reasonable to require an explicit detach/attach sequence
      from the management application.
      
      * As mentioned above, qemuDomainChangeNet also does its best to
      understand when a simple change in attached bridge for the existing
      tap device will work vs. the need to completely tear down/reconstruct
      the host side of the device (including tap device).
      
      This patch *does not* implement the "reconnect" code anyway - there is
      a placeholder that turns that into an error. Rather, the purpose of
      this patch is to replicate existing behavior with code that is ready
      to have that functionality plugged in in a later patch.
      
      * The expanded uses for qemuDomainChangeNetBridge meant that it needed
      to be enhanced as well - it no longer replaces the original brname
      string in olddev with the new brname; instead, it relies on the
      caller to replace the *entire* olddev with newdev (since we've gone
      to great lengths to assure they are functionally identical other
      than the name of the bridge, this is now not only safe, but more
      correct). Additionally, qemuDomainNetChangeBridge can now set the
      bridge for type='network' interfaces as well as plain type='bridge'
      interfaces. (Note that I had to make this change simultaneous to the
      reorganization of qemuDomainChangeNet because the two are too
      closely intertwined to separate).
      6bde0a1a
    • G
      Fix tab vs space · a2b80edb
      Guido Günther 提交于
      that broke "make syntax-check"
      
      found by http://honk.sigxcpu.org:8001/job/libvirt-syntax-check/157/
      
      Pushed under the build breaker rule.
      a2b80edb
    • O
      qemu: Initialize cpuset for hotplugged vcpu as def->cpuset · 0df1a790
      Osier Yang 提交于
      The onlined vcpu pinning policy should inherit def->cpuset if
      it's not specified explicitly, and the affinity should be set
      in this case. Oppositely, the offlined vcpu pinning policy should
      be free()'ed.
      0df1a790
    • O
      qemu: Create or remove cgroup when doing vcpu hotpluging · a9bfe887
      Osier Yang 提交于
      Various APIs use cgroup to either set or get the statistics of
      host or guest. Hotplug or hot unplug new vcpus without creating
      or removing the cgroup for the vcpus could cause problems for
      those APIs. E.g.
      
      % virsh vcpucount dom
      maximum      config        10
      maximum      live          10
      current      config         1
      current      live           1
      
      % virsh setvcpu dom 2
      
      % virsh schedinfo dom --set vcpu_quota=1000
      Scheduler      : posix
      error: Unable to find vcpu cgroup for rhel6.2(vcpu: 1): No such file or
      directory
      
      This patch fixes the problem by creating cgroups for each of the
      onlined vcpus, and destroying cgroups for each of the offlined
      vcpus.
      a9bfe887
  10. 11 10月, 2012 3 次提交
    • J
      qemu: Make save/restore with USB devices usable · bd1282d6
      Jiri Denemark 提交于
      Save/restore with passed through USB devices currently only works if the
      USB device can be found at the same USB address where it used to be
      before saving a domain. This makes sense in case a user explicitly
      configure the USB address in domain XML. However, if the device was
      found automatically by vendor/product identification, we should try to
      search for that device when restoring the domain and use any device we
      find as long as there is only one available. In other words, the USB
      device can now be removed and plugged again or the host can be rebooted
      between saving and restoring the domain.
      bd1282d6
    • J
      Add MIGRATABLE flag for virDomainGetXMLDesc · 28f8dfdc
      Jiri Denemark 提交于
      Using VIR_DOMAIN_XML_MIGRATABLE flag, one can request domain's XML
      configuration that is suitable for migration or save/restore. Such XML
      may contain extra run-time stuff internal to libvirt and some default
      configuration may be removed for better compatibility of the XML with
      older libvirt releases.
      
      This flag may serve as an easy way to get the XML that can be passed
      (after desired modifications) to APIs that accept custom XMLs, such as
      virDomainMigrate{,ToURI}2 or virDomainSaveFlags.
      28f8dfdc
    • J
      locking: Pass hypervisor driver name when acquiring locks · d236f3fc
      Jiri Denemark 提交于
      This is required in case a lock manager needs to contact libvirtd in
      case of an unexpected event.
      d236f3fc
  11. 10 10月, 2012 1 次提交
    • D
      Change qemuSetSchedularParameters to use AFFECT_CURRENT · 4da9b2c1
      Daniel P. Berrange 提交于
      When adding variants of parameter setting APIs which accepted
      flags, the existing APIs were all adapted internally to pass
      VIR_DOMAIN_AFFECT_CURRENT to the new API. The QEMU impl
      qemuSetSchedularParameters was an exception, which instead
      used VIR_DOMAIN_AFFECT_LIVE. Change this to match other
      compatibility scenarios, so that calling
      
         virDomainSetSchedularParameters(dom, params, nparams);
      
      Has the same semantics as
      
         virDomainSetSchedularParametersFlags(dom, params, nparams, 0);
      
      And
      
         virDomainSetSchedularParametersFlags(dom, params, nparams, VIR_DOMAIN_AFFECT_CURRENT);
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      4da9b2c1
  12. 02 10月, 2012 2 次提交
    • J
      qemu: Kill processes used for QMP caps probing · 0caccb58
      Jiri Denemark 提交于
      Since libvirt switched to QMP capabilities probing recently, it starts
      QEMU process used for this probing with -daemonize, which means
      virCommandAbort can no longer reach these processes. As a result of
      that, restarting libvirtd will leave several new QEMU processes behind.
      Let's use QEMU's -pidfile and use it to kill the process when QMP caps
      probing is done.
      0caccb58
    • P
      qemu: Use proper agent entering function when freezing filesystems · e0316b5e
      Peter Krempa 提交于
      When doing snapshots, the filesystem freeze function used the agent
      entering function that expects the qemud_driver unlocked. This might
      cause a deadlock of the qemu driver if the agent does not respond.
      
      The only call path of this function has the qemud_driver locked, so this
      patch changes the entering functions to those expecting the driver
      locked.
      e0316b5e
  13. 28 9月, 2012 1 次提交