1. 05 9月, 2011 6 次提交
    • E
      snapshot: wire up live qemu disk snapshots · 9c21b441
      Eric Blake 提交于
      Lots of earlier patches led up to this point - the qemu snapshot_blkdev
      monitor command can now be controlled by libvirt!  Well, insofar as
      SELinux doesn't prevent qemu from open(O_CREAT) on the files.  There's
      still some followup work before things work with SELinux enforcing,
      but this patch is big enough to post now.
      
      There's still room for other improvements, too (for example, taking a
      disk snapshot of an inactive domain, by using qemu-img for both internal
      and external snapshots; wiring up delete and revert control, including
      additional flags from my RFC; supporting active QED disk snapshots;
      supporting per-storage-volume snapshots such as LVM or btrfs snapshots;
      etc.).  But this patch is the one that proves the new XML works!
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Wire in
      active disk snapshots.
      (qemuDomainSnapshotDiskPrepare)
      (qemuDomainSnapshotCreateDiskActive)
      (qemuDomainSnapshotCreateSingleDiskActive): New functions.
      9c21b441
    • E
      snapshot: reject unimplemented disk snapshot features · 7807e05d
      Eric Blake 提交于
      My RFC for snapshot support [1] proposes several rules for when it is
      safe to delete or revert to an external snapshot, predicated on
      the existence of new API flags.  These will be incrementally added
      in future patches, but until then, blindly mishandling a disk
      snapshot risks corrupting internal state, so it is better to
      outright reject the attempts until the other pieces are in place,
      thus incrementally relaxing the restrictions added in this patch.
      
      [1] https://www.redhat.com/archives/libvir-list/2011-August/msg00361.html
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCountExternal): New
      function.
      (qemuDomainUndefineFlags, qemuDomainSnapshotDelete): Use it to add
      safety valve.
      (qemuDomainRevertToSnapshot, qemuDomainSnapshotCreateXML): Add safety
      valve.
      7807e05d
    • E
      snapshot: add flag for requesting disk snapshot · e03a62b4
      Eric Blake 提交于
      Prior to this patch, <domainsnapshot>/<disks> was ignored.  This
      changes it to be an error unless an explicit disk snapshot is
      requested (a future patch may relax things if it turns out to
      be useful to have a <disks> specification alongside a system
      checkpoint).
      
      * include/libvirt/libvirt.h.in
      (VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY): New flag.
      * src/libvirt.c (virDomainSnapshotCreateXML): Document it.
      * src/esx/esx_driver.c (esxDomainSnapshotCreateXML): Disk
      snapshots not supported yet.
      * src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Likewise.
      e03a62b4
    • E
      snapshot: also support disks by path · 89b6284f
      Eric Blake 提交于
      I got confused when 'virsh domblkinfo dom disk' required the
      path to a disk (which can be ambiguous, since a single file
      can back multiple disks), rather than the unambiguous target
      device name that I was using in disk snapshots.  So, in true
      developer fashion, I went for the best of both worlds - all
      interfaces that operate on a disk (aka block) now accept
      either the target name or the unambiguous path to the backing
      file used by the disk.
      
      * src/conf/domain_conf.h (virDomainDiskIndexByName): Add
      parameter.
      (virDomainDiskPathByName): New prototype.
      * src/libvirt_private.syms (domain_conf.h): Export it.
      * src/conf/domain_conf.c (virDomainDiskIndexByName): Also allow
      searching by path, and decide whether ambiguity is okay.
      (virDomainDiskPathByName): New function.
      (virDomainDiskRemoveByName, virDomainSnapshotAlignDisks): Update
      callers.
      * src/qemu/qemu_driver.c (qemudDomainBlockPeek)
      (qemuDomainAttachDeviceConfig, qemuDomainUpdateDeviceConfig)
      (qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.
      * src/qemu/qemu_process.c (qemuProcessFindDomainDiskByPath):
      Likewise.
      * src/libxl/libxl_driver.c (libxlDomainAttachDeviceDiskLive)
      (libxlDomainDetachDeviceDiskLive, libxlDomainAttachDeviceConfig)
      (libxlDomainUpdateDeviceConfig): Likewise.
      * src/uml/uml_driver.c (umlDomainBlockPeek): Likewise.
      * src/xen/xend_internal.c (xenDaemonDomainBlockPeek): Likewise.
      * docs/formatsnapshot.html.in: Update documentation.
      * tools/virsh.pod (domblkstat, domblkinfo): Likewise.
      * docs/schemas/domaincommon.rng (diskTarget): Tighten pattern on
      disk targets.
      * docs/schemas/domainsnapshot.rng (disksnapshot): Update to match.
      * tests/domainsnapshotxml2xmlin/disk_snapshot.xml: Update test.
      89b6284f
    • E
      snapshot: allow halting after snapshot · 6f66423e
      Eric Blake 提交于
      Since a snapshot is fully recoverable, it is useful to have a
      snapshot as a means of hibernating a guest, then reverting to
      the snapshot to wake the guest up.  This mode of usage is
      similar to 'virsh save/virsh restore', except that virsh
      save uses an external file while virsh snapshot keeps the
      vm state internal to a qcow2 file.  However, it only works on
      persistent domains.
      
      In the usage pattern of snapshot/revert for hibernating a guest,
      there is no need to keep the guest running between the two points
      in time, especially since that would generate runtime state that
      would just be discarded.  Add a flag to make it possible to
      stop the domain after the snapshot has completed.
      
      * include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_CREATE_HALT):
      New flag.
      * src/libvirt.c (virDomainSnapshotCreateXML): Document it.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML)
      (qemuDomainSnapshotCreateActive): Implement it.
      6f66423e
    • E
      snapshot: introduce new deletion flag · 3d77d0a6
      Eric Blake 提交于
      Reverting to a state prior to an external snapshot risks
      corrupting any other branches in the snapshot hierarchy that
      were using the snapshot as a read-only backing file.  So
      disk snapshot code will default to preventing reverting to
      a snapshot that has any children, meaning that deleting just
      the children of a snapshot becomes a useful operation in
      preparing that snapshot for being a future reversion target.
      The code for the new flag is simple - it's one less deletion,
      plus a tweak to keep the current snapshot correct.
      
      * include/libvirt/libvirt.h.in
      (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY): New flag.
      * src/libvirt.c (virDomainSnapshotDelete): Document it, and
      enforce mutual exclusion.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotDelete): Implement
      it.
      3d77d0a6
  2. 03 9月, 2011 19 次提交
    • E
      snapshot: store qemu domain details in xml · 973fcd8f
      Eric Blake 提交于
      When reverting to a snapshot, the inactive domain configuration
      has to be rolled back to what it was at the time of the snapshot.
      Additionally, if the VM is active and the snapshot was active,
      this now adds a failure if the two configurations are ABI
      incompatible, rather than risking qemu confusion.
      
      A future patch will add a VIR_DOMAIN_SNAPSHOT_FORCE flag, which
      will be required for two risky code paths - reverting to an
      older snapshot that lacked full domain information, and reverting
      from running to a live snapshot that requires starting a new qemu
      process.  Any reverting that stops a running vm is also a form
      of data loss (discarding the current running state to go back in
      time), but as that is what reversion usually implies, it is
      probably not worth requiring a force flag.
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Copy out
      domain.
      (qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot): Perform
      ABI compatibility checks.
      973fcd8f
    • E
      snapshot: allow full domain xml in snapshot · f609cb85
      Eric Blake 提交于
      Just like VM saved state images (virsh save), snapshots MUST
      track the inactive domain xml to detect any ABI incompatibilities.
      
      The indentation is not perfect, but functionality comes before form.
      
      Later patches will actually supply a full domain; for now, this
      wires up the storage to support one, but doesn't ever generate one
      in dumpxml output.
      
      Happily, libvirt.c was already rejecting use of VIR_DOMAIN_XML_SECURE
      from read-only connections, even though before this patch, there was
      no information to be secured by the use of that flag.
      
      And while we're at it, mark the libvirt snapshot metadata files
      as internal-use only.
      
      * src/libvirt.c (virDomainSnapshotGetXMLDesc): Document flag.
      * src/conf/domain_conf.h (_virDomainSnapshotDef): Add member.
      (virDomainSnapshotDefParseString, virDomainSnapshotDefFormat):
      Update signature.
      * src/conf/domain_conf.c (virDomainSnapshotDefFree): Clean up.
      (virDomainSnapshotDefParseString): Optionally parse domain.
      (virDomainSnapshotDefFormat): Output full domain.
      * src/esx/esx_driver.c (esxDomainSnapshotCreateXML)
      (esxDomainSnapshotGetXMLDesc): Update callers.
      * src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML)
      (vboxDomainSnapshotGetXMLDesc): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML)
      (qemuDomainSnapshotLoad, qemuDomainSnapshotGetXMLDesc)
      (qemuDomainSnapshotWriteMetadata): Likewise.
      * docs/formatsnapshot.html.in: Rework doc example.
      Based on a patch by Philipp Hahn.
      f609cb85
    • E
      snapshot: support new undefine flags in qemu · 19f8c980
      Eric Blake 提交于
      A nice benefit of deleting all snapshots at undefine time is that
      you don't have to do any reparenting or subtree identification - since
      everything goes, this is an O(n) process, whereas using multiple
      virDomainSnapshotDelete calls would be O(n^2) or worse.  But it is
      only doable for snapshot metadata, where we are in control of the
      data being deleted; for the actual snapshots, there's too much
      likelihood of something going wrong, and requiring even more API
      calls to figure out what failed in the meantime, so callers are
      better off deleting the snapshot data themselves one snapshot at
      a time where they can deal with failures as they happen.
      
      * src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Honor new flags.
      19f8c980
    • E
      snapshot: cache qemu-img location · 3881a470
      Eric Blake 提交于
      As more clients start to want to know this information, doing
      a PATH stat walk and malloc for every client adds up.
      
      We are only caching the location, not the capabilities, so even
      if qemu-img is updated in the meantime, it will still probably
      live in the same location.  So there is no need to worry about
      clearing this particular cache.
      
      * src/qemu/qemu_conf.h (qemud_driver): Add member.
      * src/qemu/qemu_driver.c (qemudShutdown): Cleanup.
      (qemuFindQemuImgBinary): Add an argument, and cache result.
      (qemuDomainSnapshotForEachQcow2, qemuDomainSnapshotDiscard)
      (qemuDomainSnapshotCreateInactive, qemuDomainSnapshotRevertInactive)
      (qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot): Update
      callers.
      3881a470
    • E
      snapshot: refactor some qemu code · 8055e5af
      Eric Blake 提交于
      Prepare for code sharing.  No semantic change.
      
      * src/qemu/qemu_driver.c (qemuFindQemuImgBinary)
      (qemuDomainSnapshotWriteMetadata)
      (qemuDomainSnapshotDiscard)
      (qemuDomainSnapshotForEachQcow2): Float up.
      (qemuDomainSnapshotDiscardDescendant): Likewise, and rename...
      (qemuDomainSnapshotDiscardAll): ...for generic use.
      (qemuDomainSnapshotDelete): Update caller.
      8055e5af
    • E
      snapshot: prevent stranding snapshot data on domain destruction · 282fe1f0
      Eric Blake 提交于
      Just as leaving managed save metadata behind can cause problems
      when creating a new domain that happens to collide with the name
      of the just-deleted domain, the same is true of leaving any
      snapshot metadata behind.  For safety sake, extend the semantic
      change of commit b26a9fa9 to also cover snapshot metadata as a
      reason to reject undefining an inactive domain.  A future patch
      will make sure that shutdown of a transient domain automatically
      deletes snapshot metadata (whether by destroy, shutdown, or
      guest-initiated action).  Management apps of transient domains
      should take care to capture xml of snapshots, if it is necessary
      to recreate the snapshot metadata on a later transient domain
      with the same name and uuid.
      
      This also documents a new flag that hypervisors can choose to
      support as a shortcut for taking care of the metadata as part of
      the undefine process; however, nontrivial driver support for these
      flags will be deferred to future patches.
      
      Note that ESX and VBox can never be transient; therefore, they
      do not have to worry about automatic cleanup after shutdown
      (the persistent domain still remains); likewise they never
      store snapshot metadata, so the undefine flag is trivial.
      The nontrivial work remaining is thus in the qemu driver.
      
      * include/libvirt/libvirt.h.in
      (VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA): New flag.
      * src/libvirt.c (virDomainUndefine, virDomainUndefineFlags):
      Document new limitations and flag.
      * src/esx/esx_driver.c (esxDomainUndefineFlags): Trivial
      implementation.
      * src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Enforce
      the limitations.
      282fe1f0
    • E
      snapshot: add qemu snapshot redefine support · bd18b967
      Eric Blake 提交于
      Redefining a qemu snapshot requires a bit of a tweak to the common
      snapshot parsing code, but the end result is quite nice.
      
      Be careful that redefinitions do not introduce circular parent
      chains.  Also, we don't want to allow conversion between online
      and offline existing snapshots.  We could probably do some more
      validation for snapshots that don't already exist to make sure
      they are even feasible, by parsing qemu-img output, but that
      can come later.
      
      * src/conf/domain_conf.h (virDomainSnapshotParseFlags): New
      internal flags.
      * src/conf/domain_conf.c (virDomainSnapshotDefParseString): Alter
      signature to take internal flags.
      * src/esx/esx_driver.c (esxDomainSnapshotCreateXML): Update caller.
      * src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Support
      new public flags.
      bd18b967
    • E
      snapshot: add qemu snapshot creation without metadata · ece197e9
      Eric Blake 提交于
      Supporting NO_METADATA on snapshot creation is interesting - we must
      still return a valid opaque snapshot object, but the user can't get
      anything out of it (unless we add a virDomainSnapshotGetName()),
      since it is no longer registered with the domain.
      
      Also, virsh now tries to query for secure xml, in anticipation of
      when we store <domain> xml inside <domainsnapshot>; for now, we
      can trivially support it, since we have nothing secure.
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Support
      new flag.
      (qemuDomainSnapshotGetXMLDesc): Trivially support VIR_DOMAIN_XML_SECURE.
      ece197e9
    • E
      snapshot: identify qemu snapshot roots · 6b3801b0
      Eric Blake 提交于
      Filtering for roots is pretty easy to do.
      
      * src/conf/domain_conf.h (virDomainSnapshotObjListGetNames)
      (virDomainSnapshotObjListNum): Update prototype.
      * src/conf/domain_conf.c (virDomainSnapshotObjListCopyNames)
      (virDomainSnapshotObjListGetNames, virDomainSnapshotObjListCount)
      (virDomainSnapshotObjListNum): Support filtering.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
      (qemuDomainSnapshotListNames): Update callers.
      6b3801b0
    • E
      snapshot: identify which snapshots have metadata · 9f5e53e2
      Eric Blake 提交于
      To make it easier to know when undefine will fail because of existing
      snapshot metadata, we need to know how many snapshots have metadata.
      
      Also, it is handy to filter the list of snapshots to just those that
      have no parents; document that flag now, but implement it in later patches.
      
      * include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)
      (VIR_DOMAIN_SNAPSHOT_LIST_METADATA): New flags.
      * src/libvirt.c (virDomainSnapshotNum)
      (virDomainSnapshotListNames): Document them.
      * src/esx/esx_driver.c (esxDomainSnapshotNum)
      (esxDomainSnapshotListNames): Implement trivial flag.
      * src/vbox/vbox_tmpl.c (vboxDomainSnapshotNum)
      (vboxDomainSnapshotListNames): Likewise.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
      (qemuDomainSnapshotListNames): Likewise.
      9f5e53e2
    • E
      snapshot: let qemu discard only snapshot metadata · 7afa6b41
      Eric Blake 提交于
      Adding this was trivial compared to the previous patch for fixing
      qemu snapshot deletion in the first place.
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotDiscard): Add
      parameter.
      (qemuDomainSnapshotDiscardDescendant, qemuDomainSnapshotDelete):
      Update callers.
      7afa6b41
    • E
      snapshot: simplify acting on just children · 67555b24
      Eric Blake 提交于
      Similar to the last patch in isolating the filtering from the
      client actions, so that clients don't have to reinvent the
      filtering.
      
      * src/conf/domain_conf.h (virDomainSnapshotForEachChild): New
      prototype.
      * src/libvirt_private.syms (domain_conf.h): Export it.
      * src/conf/domain_conf.c (virDomainSnapshotActOnChild)
      (virDomainSnapshotForEachChild): New functions.
      (virDomainSnapshotCountChildren): Delete.
      (virDomainSnapshotHasChildren): Simplify.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotReparentChildren)
      (qemuDomainSnapshotDelete): Likewise.
      67555b24
    • E
      snapshot: track current domain across deletion of children · 90ea06b8
      Eric Blake 提交于
      Deleting a snapshot and all its descendants had problems with
      tracking the current snapshot.  The deletion does not necessarily
      proceed in depth-first order, so a parent could be deleted
      before a child, wreaking havoc on passing the notion of the
      current snapshot to the parent.  Furthermore, even if traversal
      were depth-first, doing multiple file writes to pass current up
      the chain one snapshot at a time is wasteful, comparing to a
      single update to the current snapshot at the end of the algorithm.
      
      * src/qemu/qemu_driver.c (snap_remove): Add field.
      (qemuDomainSnapshotDiscard): Add parameter.
      (qemuDomainSnapshotDiscardDescendant): Adjust accordingly.
      (qemuDomainSnapshotDelete): Properly reset current.
      90ea06b8
    • E
      snapshot: avoid crash when deleting qemu snapshots · cb231b4b
      Eric Blake 提交于
      This one's nasty.  Ever since we fixed virHashForEach to prevent
      nested hash iterations for safety reasons (commit fba550f6),
      virDomainSnapshotDelete with VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN
      has been broken for qemu: it deletes children, while leaving
      grandchildren intact but pointing to a no-longer-present parent.
      But even before then, the code would often appear to succeed to
      clean up grandchildren, but risked memory corruption if you have
      a large and deep hierarchy of snapshots.
      
      For acting on just children, a single virHashForEach is sufficient.
      But for acting on an entire subtree, it requires iteration; and
      since we declared recursion as invalid, we have to switch to a
      while loop.  Doing this correctly requires quite a bit of overhaul,
      so I added a new helper function to isolate the algorithm from the
      actions, so that callers do not have to reinvent the iteration.
      
      Note that this _still_ does not handle CHILDREN correctly if one
      of the children is the current snapshot; that will be next.
      
      * src/conf/domain_conf.h (_virDomainSnapshotDef): Add mark.
      (virDomainSnapshotForEachDescendant): New prototype.
      * src/libvirt_private.syms (domain_conf.h): Export it.
      * src/conf/domain_conf.c (virDomainSnapshotMarkDescendant)
      (virDomainSnapshotActOnDescendant)
      (virDomainSnapshotForEachDescendant): New functions.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotDiscardChildren):
      Replace...
      (qemuDomainSnapshotDiscardDescenent): ...with callback that
      doesn't nest hash traversal.
      (qemuDomainSnapshotDelete): Use new function.
      cb231b4b
    • E
      snapshot: fine-tune qemu snapshot revert states · 7dc44eb0
      Eric Blake 提交于
      For a system checkpoint of a running or paused domain, it's fairly
      easy to honor new flags for altering which state to use after the
      revert.  For an inactive snapshot, the revert has to be done while
      there is no qemu process, so do back-to-back transitions; this also
      lets us revert to inactive snapshots even for transient domains.
      
      * src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Support new
      flags.
      7dc44eb0
    • E
      snapshot: properly revert qemu to offline snapshots · 25fb3ef1
      Eric Blake 提交于
      Commit 5e47785b broke reverts to offline system checkpoint snapshots
      with older qemu, since there is no longer any code path to use
      qemu -loadvm on next boot.  Meanwhile, reverts to offline system
      checkpoints have been broken for newer qemu, both before and
      after that commit, since -loadvm no longer works to revert to
      disk state without accompanying vm state.  Fix both of these by
      using qemu-img to revert disk state.
      
      Meanwhile, consolidate the (now 3) clients of a qemu-img iteration
      over all disks of a VM into one function, so that any future
      algorithmic fixes to the FIXMEs in that function after partial
      loop iterations are dealt with at once.  That does mean that this
      patch doesn't handle partial reverts very well, but we're not
      making the situation any worse in this patch.
      
      * src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Use
      qemu-img rather than 'qemu -loadvm' to revert to offline snapshot.
      (qemuDomainSnapshotRevertInactive): New helper.
      (qemuDomainSnapshotCreateInactive): Factor guts...
      (qemuDomainSnapshotForEachQcow2): ...into new helper.
      (qemuDomainSnapshotDiscard): Use it.
      25fb3ef1
    • E
      snapshot: improve reverting to qemu paused snapshots · 88fe7a4b
      Eric Blake 提交于
      If you take a checkpoint snapshot of a running domain, then pause
      qemu, then restore the snapshot, the result should be a running
      domain, but the code was leaving things paused.  Furthermore, if
      you take a checkpoint of a paused domain, then run, then restore,
      there was a brief but non-deterministic window of time where the
      domain was running rather than paused.  Fix both of these
      discrepancies by always pausing before restoring.
      
      Also, check that the VM is active every time lock is dropped
      between two monitor calls.
      
      Finally, straighten out the events that get emitted on each
      transition.
      
      * src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Always
      pause before reversion, and improve events.
      88fe7a4b
    • E
      snapshot: fine-tune qemu saved images starting paused · 7381aaff
      Eric Blake 提交于
      Implement the new running/paused overrides for saved state management.
      
      Unfortunately, for virDomainSaveImageDefineXML, the saved state
      updates are write-only - I don't know of any way to expose a way
      to query the current run/pause setting of an existing save image
      file to the user without adding a new API or modifying the domain
      xml of virDomainSaveImageGetXMLDesc to include a new element to
      reflect the state bit encoded into the save image.  However, I
      don't think this is a show-stopper, since the API is designed to
      leave the state bit alone unless an explicit flag is used to
      change it.
      
      * src/qemu/qemu_driver.c (qemuDomainSaveInternal)
      (qemuDomainSaveImageOpen): Adjust signature.
      (qemuDomainSaveFlags, qemuDomainManagedSave)
      (qemuDomainRestoreFlags, qemuDomainSaveImageGetXMLDesc)
      (qemuDomainSaveImageDefineXML, qemuDomainObjRestore): Adjust
      callers.
      7381aaff
    • E
      snapshot: better events when starting paused · c1ff5dc6
      Eric Blake 提交于
      There are two classes of management apps that track events - one
      that only cares about on/off (and only needs to track EVENT_STARTED
      and EVENT_STOPPED), and one that cares about paused/running (also
      tracks EVENT_SUSPENDED/EVENT_RESUMED).  To keep both classes happy,
      any transition that can go from inactive to paused must emit two
      back-to-back events - one for started and one for suspended (since
      later resuming of the domain will only send RESUMED, but the first
      class isn't tracking that).
      
      This also fixes a bug where virDomainCreateWithFlags with the
      VIR_DOMAIN_START_PAUSED flag failed to start paused when restoring
      from a managed save image.
      
      * include/libvirt/libvirt.h.in (VIR_DOMAIN_EVENT_SUSPENDED_RESTORED)
      (VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT)
      (VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT): New sub-events.
      * src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Use them.
      (qemuDomainSaveImageStartVM): Likewise, and add parameter.
      (qemudDomainCreate, qemuDomainObjStart): Send suspended event when
      starting paused.
      (qemuDomainObjRestore): Add parameter.
      (qemuDomainObjStart, qemuDomainRestoreFlags): Update callers.
      * examples/domain-events/events-c/event-test.c
      (eventDetailToString): Map new detail strings.
      c1ff5dc6
  3. 02 9月, 2011 5 次提交
    • M
      Add "redirdev" redirection device · 162efa1a
      Marc-André Lureau 提交于
      - create a new "redirdev" element for this purpose
      162efa1a
    • E
      snapshot: fix corner case on OOM during creation · c554f6e1
      Eric Blake 提交于
      Commit 6766ff10 introduced a corner case bug with snapshot creation:
      if a snapshot is created, but then we hit OOM while trying to
      create the return value of the function, then we have polluted the
      internal directory with the snapshot metadata with no way to clean
      it up from the running libvirtd.
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Don't
      write metadata file on OOM condition.
      c554f6e1
    • E
      qemu: detect incomplete save files · 55d88def
      Eric Blake 提交于
      Several users have reported problems with 'virsh start' failing because
      it was encountering a managed save situation where the managed save file
      was incomplete.  Be more robust to this by using two different magic
      numbers, so that newer libvirt can gracefully handle an incomplete file
      differently than a complete one, while older libvirt will at least fail
      up front rather than trying to load only to have qemu fail at the end.
      
      Managed save is a convenience - it exists to preserve as much state
      as possible; if the state was not preserved, it is reasonable to just
      log that fact, then proceed with a fresh boot.  On the other hand,
      user saves are under user control, so we must fail, but by making
      the failure message distinct, the user can better decide how to handle
      the situation of an incomplete save file.
      
      * src/qemu/qemu_driver.c (QEMUD_SAVE_PARTIAL): New define.
      (qemuDomainSaveInternal): Use it to mark incomplete images.
      (qemuDomainSaveImageOpen, qemuDomainObjRestore): Add parameter
      that controls what to do with partial images.
      (qemuDomainRestoreFlags, qemuDomainSaveImageGetXMLDesc)
      (qemuDomainSaveImageDefineXML, qemuDomainObjStart): Update callers.
      Based on an initial idea by Osier Yang.
      55d88def
    • E
      qemu: refactor file opening · 449ae9c2
      Eric Blake 提交于
      In a SELinux or root-squashing NFS environment, libvirt has to go
      through some hoops to create a new file that qemu can then open()
      by name.  Snapshots are a case where we want to guarantee an empty
      file that qemu can open; also, reopening a save file to convert it
      from being marked partial to complete requires a reopen to avoid
      O_DIRECT headaches.  Refactor some existing code to make it easier
      to reuse in later patches.
      
      * src/qemu/qemu_migration.h (qemuMigrationToFile): Drop parameter.
      * src/qemu/qemu_migration.c (qemuMigrationToFile): Let cgroup do
      the stat, rather than asking caller to do it and pass info down.
      * src/qemu/qemu_driver.c (qemuOpenFile): New function, pulled from...
      (qemuDomainSaveInternal): ...here.
      (doCoreDump, qemuDomainSaveImageOpen): Use it here as well.
      449ae9c2
    • A
      BlockPull: Set initial bandwidth limit if specified · d4b9e062
      Adam Litke 提交于
      The libvirt BlockPull API supports the use of an initial bandwidth limit but the
      qemu block_stream API does not.  To get the desired behavior we use the two APIs
      strung together: first BlockPull, then BlockJobSetSpeed.  We can do this at the
      driver level to avoid duplicated code in each monitor path.
      Signed-off-by: NAdam Litke <agl@us.ibm.com>
      d4b9e062
  4. 01 9月, 2011 1 次提交
  5. 31 8月, 2011 1 次提交
    • E
      snapshot: forbid snapshot on autodestroy domain · 173015be
      Eric Blake 提交于
      There is no reason to forbid pausing an autodestroy domain
      (not to mention that 'virsh start --paused --autodestroy'
      succeeds in creating a paused autodestroy domain).
      
      Meanwhile, qemu was failing to enforce the API documentation that
      autodestroy domains cannot be saved.  And while the original
      documentation only mentioned save/restore, snapshots are another
      form of saving that are close enough in semantics as to make no
      sense on one-shot domains.
      
      * src/qemu/qemu_driver.c (qemudDomainSuspend): Drop bogus check.
      (qemuDomainSaveInternal, qemuDomainSnapshotCreateXML): Forbid
      saves of autodestroy domains.
      * src/libvirt.c (virDomainCreateWithFlags, virDomainCreateXML):
      Document snapshot interaction.
      173015be
  6. 30 8月, 2011 1 次提交
    • E
      start: allow discarding managed save · 27c85260
      Eric Blake 提交于
      There have been several instances of people having problems with
      a broken managed save file, and not aware that they could use
      'virsh managedsave-remove dom' to fix things.  Making it possible
      to do this as part of starting a domain makes the same functionality
      easier to find, and one less API call.
      
      * include/libvirt/libvirt.h.in (VIR_DOMAIN_START_FORCE_BOOT): New
      flag.
      * src/libvirt.c (virDomainCreateWithFlags): Document it.
      * src/qemu/qemu_driver.c (qemuDomainObjStart): Alter signature.
      (qemuAutostartDomain, qemuDomainStartWithFlags): Update callers.
      * tools/virsh.c (cmdStart): Expose it in virsh.
      * tools/virsh.pod (start): Document it.
      27c85260
  7. 26 8月, 2011 4 次提交
    • D
      Fix keymap used to talk with QEMU · ce93f64b
      Daniel P. Berrange 提交于
      The QEMU 'sendkey' command expects keys to be encoded in the same
      way as the RFB extended keycode set. Specifically it wants extended
      keys to have the high bit of the first byte set, while the Linux
      XT KBD driver codeset uses the low bit of the second byte. To deal
      with this we introduce a new keymap 'RFB' and use that in the QEMU
      driver
      
      * include/libvirt/libvirt.h.in: Add VIR_KEYCODE_SET_RFB
      * src/qemu/qemu_driver.c: Use RFB keycode set instead of XT KBD
      * src/util/virkeycode-mapgen.py: Auto-generate the RFB keycode
        set from the XT KBD set
      * src/util/virkeycode.c: Add RFB keycode entry to table. Add a
        verify check on cardinality of the codeOffset table
      ce93f64b
    • E
      snapshot: track current snapshot across restarts · 6766ff10
      Eric Blake 提交于
      Audit all changes to the qemu vm->current_snapshot, and make them
      update the saved xml file for both the previous and the new
      snapshot, so that there is always at most one snapshot with
      <active>1</active> in the xml, and that snapshot is used as the
      current snapshot even across libvirtd restarts.
      
      This patch does not fix the case of virDomainSnapshotDelete(,CHILDREN)
      where one of the children is the current snapshot; that will be later.
      
      * src/conf/domain_conf.h (_virDomainSnapshotDef): Alter member
      type and name.
      * src/conf/domain_conf.c (virDomainSnapshotDefParseString)
      (virDomainSnapshotDefFormat): Update clients.
      * docs/schemas/domainsnapshot.rng: Tighten rng.
      * src/qemu/qemu_driver.c (qemuDomainSnapshotLoad): Reload current
      snapshot.
      (qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot)
      (qemuDomainSnapshotDiscard): Track current snapshot.
      6766ff10
    • E
      snapshot: only pass snapshot to qemu command line when reverting · 5e47785b
      Eric Blake 提交于
      Changing the current vm, and writing that change to the file
      system, all before a new qemu starts, is risky; it's hard to
      roll back if starting the new qemu fails for some reason.
      Instead of abusing vm->current_snapshot and making the command
      line generator decide whether the current snapshot warrants
      using -loadvm, it is better to just directly pass a snapshot all
      the way through the call chain if it is to be loaded.
      
      This frees up the last use of snapshot->def->active for qemu's
      use, so the next patch can repurpose that field for tracking
      which snapshot is current.
      
      * src/qemu/qemu_command.c (qemuBuildCommandLine): Don't use active
      field of snapshot.
      * src/qemu/qemu_process.c (qemuProcessStart): Add a parameter.
      * src/qemu/qemu_process.h (qemuProcessStart): Update prototype.
      * src/qemu/qemu_migration.c (qemuMigrationPrepareAny): Update
      callers.
      * src/qemu/qemu_driver.c (qemudDomainCreate)
      (qemuDomainSaveImageStartVM, qemuDomainObjStart)
      (qemuDomainRevertToSnapshot): Likewise.
      (qemuDomainSnapshotSetCurrentActive)
      (qemuDomainSnapshotSetCurrentInactive): Delete unused functions.
      5e47785b
    • E
      snapshot: don't leak resources on qemu snapshot failure · 861dc84b
      Eric Blake 提交于
      https://bugzilla.redhat.com/show_bug.cgi?id=727709
      mentions that if qemu fails to create the snapshot (such as what
      happens on Fedora 15 qemu, which has qmp but where savevm is only
      in hmp, and where libvirt is old enough to not try the hmp fallback),
      then 'virsh snapshot-list dom' will show a garbage snapshot entry,
      and the libvirt internal directory for storing snapshot metadata
      will have a bogus file.
      
      This fixes the fallout bug of polluting the snapshot-list with
      garbage on failure (the root cause of the F15 bug of not having
      fallback to hmp has already been fixed in newer libvirt releases).
      
      * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Allocate
      memory before making snapshot, and cleanup on failure.  Don't
      dereference NULL if transient domain exited during snapshot creation.
      861dc84b
  8. 24 8月, 2011 1 次提交
    • E
      maint: fix comment typos · 3a52b864
      Eric Blake 提交于
      * src/qemu/qemu_driver.c (qemuDomainSaveInternal): Fix typo.
      * src/conf/domain_event.c (virDomainEventDispatchMatchCallback):
      Likewise.
      * daemon/libvirtd.c (daemonRunStateInit): Likewise.
      * src/lxc/lxc_container.c (lxcContainerChildMountSort): Likewise.
      * src/util/virterror.c (virCopyError, virRaiseErrorFull): Likewise.
      * src/xenxs/xen_sxpr.c (xenParseSxprSound): Likewise.
      3a52b864
  9. 23 8月, 2011 1 次提交
    • O
      qemu: Cleanup improper VIR_ERR_NO_SUPPORT use · 4340b3ba
      Osier Yang 提交于
      * src/qemu/qemu_command.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_CONFIG_UNSUPPORTED/
      
      * src/qemu/qemu_driver.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_OPERATION_INVALID/
      
      * src/qemu/qemu_process.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_OPERATION_INVALID/
      4340b3ba
  10. 19 8月, 2011 1 次提交