1. 22 3月, 2019 4 次提交
    • E
      snapshot: Track current snapshot in virDomainSnapshotObjList · 4819f54b
      Eric Blake 提交于
      It is easier to track the current snapshot as part of the list of
      snapshots. In particular, doing so lets us guarantee that the current
      snapshot is cleared if that snapshot is removed from the list (rather
      than depending on the caller to do so, and risking a use-after-free
      problem, such as the one recently patched in 1db9d0ef).  This
      requires the addition of several new accessor functions, as well as a
      useful return type for virDomainSnapshotObjListRemove().  A few error
      handling sites that were previously setting vm->current_snapshot =
      NULL can now be dropped, because the previous function call has now
      done it already.  Also, qemuDomainRevertToSnapshot() was setting the
      current vm twice, so keep only the one used on the success path.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      4819f54b
    • E
      snapshot: Drop virDomainSnapshotDef.current · f1056279
      Eric Blake 提交于
      The only use for the 'current' member of virDomainSnapshotDef was with
      the PARSE/FORMAT_INTERNAL flag for controlling an internal-use
      <active> element marking whether a particular snapshot definition was
      current, and even then, only by the qemu driver on output, and by qemu
      and test driver on input. But this duplicates vm->snapshot_current,
      and gets in the way of potential simplifications to have qemu store a
      single file for all snapshots rather than one file per snapshot.  Get
      rid of the member by adding a bool* parameter during parse (ignored if
      the PARSE_INTERNAL flag is not set), and by adding a new flag during
      format (if FORMAT_INTERNAL is set, the value printed in <active>
      depends on the new FORMAT_CURRENT).
      
      Then update the qemu driver accordingly, which involves hoisting
      assignments to vm->current_snapshot to occur prior to any point where
      a snapshot XML file is written (although qemu kept
      vm->current_snapshot and snapshot->def_current in sync by the end of
      the function, they were not always identical in the middle of
      functions, so the shuffling gets a bit interesting). Later patches
      will clean up some of that confusing churn to vm->current_snapshot.
      
      Note: even if later patches refactor qemu to no longer use
      FORMAT_INTERNAL for output (by storing bulk snapshot XML instead), we
      will always need PARSE_INTERNAL for input (because on upgrade, a new
      libvirt still has to parse XML left from a previous libvirt).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      f1056279
    • E
      snapshot: Minor cleanup to virDomainSnapshotAssignDef · 0baf6945
      Eric Blake 提交于
      When a future patch converts virDomainSnapshotDef to be a virObject,
      we need to be careful that converting VIR_FREE() to virObjectUnref()
      does not result in double frees. Reorder the assignment of def into
      the object to the point after object is in the hash table (as
      otherwise the virHashAddEntry() error path would have a shot at
      freeing def prematurely).
      Suggested-by: NJohn Ferlan <ferlan@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      0baf6945
    • E
      snapshot: Tweaks to bulk dumpxml/import internals · 967eef2b
      Eric Blake 提交于
      Change the return value of virDomainSnapshotObjListParse() to return
      the number of snapshots imported, and allow a return of 0 (the
      original proposal of adding a flag to virDomainSnapshotCreateXML
      required returning an arbitrary non-NULL snapshot, but that idea was
      abandoned; and by returning a count, we are no longer constrained to a
      non-empty list).
      
      Document which flags are supported (namely, just SECURE) in
      virDomainSnapshotObjListFormat().
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      967eef2b
  2. 20 3月, 2019 9 次提交
  3. 19 3月, 2019 1 次提交
    • J
      storage: optional 'refresh' elemement on pool · 669018bc
      Jason Dillaman 提交于
      The new 'refresh' element can override the default refresh operations
      for a storage pool. The only currently supported override is to set
      the volume allocation size to the volume capacity. This can be specified
      by adding the following snippet:
      
      <pool>
      ...
        <refresh>
          <volume allocation='capacity'/>
        </refresh>
      ...
      </pool>
      
      This is useful for certain backends where computing the actual allocation
      of a volume might be an expensive operation.
      Signed-off-by: NJason Dillaman <dillaman@redhat.com>
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      669018bc
  4. 18 3月, 2019 7 次提交
  5. 16 3月, 2019 6 次提交
    • E
      snapshot: Break out virDomainSnapshotObjList into its own file · 9b75154c
      Eric Blake 提交于
      snapshot_conf.h was mixing three separate types: the snapshot
      definition, the snapshot object, and the snapshot object list.
      Separate out the snapshot object list code into its own file, and
      update includes for affected clients.
      
      This is just code motion, but done in preparation of sharing a lot of
      the object list code with checkpoints.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      9b75154c
    • E
      snapshot: Export two functions prior to file split · 21b2651e
      Eric Blake 提交于
      The next patch will require access to the helper functions
      virDomainSnapshotDefFormatInternal and
      virDomainSnapshotRedefineValidate from two different files; make the
      file split easier by exporting these functions.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      21b2651e
    • E
      snapshot: Break out virDomainSnapshotObj into its own file · ca20690e
      Eric Blake 提交于
      snapshot_conf.h was mixing three separate types: the snapshot
      definition, the snapshot object, and the snapshot object list.
      Separate out the snapshot object code into its own file, which
      includes moving a typedef to avoid circular inclusions.
      
      Mostly straight code motion, although I fixed a comment along
      the way, now that virDomainSnapshotForEachDescendent now
      guarantees a topological visit (missed in b647d219).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      ca20690e
    • E
      snapshot: Sort virconftypes.h · 41e3d35e
      Eric Blake 提交于
      It's easier to locate a typedef if they are stored in sorted order;
      do so mechanically via:
      
      $ sed -i '/typedef struct/ {N; N; s/\n//g}' src/conf/virconftypes.h
      $ # sorting the lines
      $ sed -i '/typedef struct/ s/;/;\n/g' src/conf/virconftypes.h
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      41e3d35e
    • E
      conf: Split capabilities forward typedefs into virconftypes.h · 23c15e34
      Eric Blake 提交于
      As explained in the previous patch, collecting pointer typedefs into a
      common header makes it easier to avoid circular inclusions.  Continue
      the efforts by pulling the appropriate typedefs from capabilities.h
      into the new header.
      
      This patch is just straight code motion (all typedefs are listed in
      the same order before and after the patch); a later patch will sort
      things for legibility.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      23c15e34
    • E
      conf: Split domain forward typedefs into virconftypes.h · c555ec24
      Eric Blake 提交于
      Right now, snapshot_conf.h is rather large - it deals with three
      separate types: virDomainSnapshotDef (the snapshot definition as it
      maps to XML), virDomainSnapshotObj (an object containing a def and the
      relationship to other snapshots), and virDomainSnapshotObjList (a list
      of snapshot objects), where two of the three types are currently
      public rather than opaque.  What's more, the types are circular: a
      snapshot def includes a virDomainPtr, which contains a snapshot list,
      which includes a snapshot object, which includes a snapshot def.
      
      In order to split the three objects into separate files, while still
      allowing each header to use sane typedefs to incomplete pointers, the
      obvious solution is to lift the typedefs into yet another header, with
      no other dependencies.  Start the split by factoring out all struct
      typedefs from domain_conf.h (enum typedefs don't get used in function
      signatures, and function typedefs tend not to suffer from circular
      referencing, so those stay put).  The only other exception is
      virDomainStateReason, which is only ever used directly rather than via
      a pointer.
      
      This patch is just straight code motion (all typedefs are listed in
      the same order before and after the patch); a later patch will sort
      things for legibility.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      c555ec24
  6. 14 3月, 2019 4 次提交
  7. 13 3月, 2019 2 次提交
    • S
      util: Introduce virStringParseYesNo helper · 612c0d4b
      Shotaro Gotanda 提交于
      This helper performs a conversion from a "yes|no" string to a
      corresponding boolean. This allows us to drop several repetitive
      if-then-else string->bool conversion blocks.
      Signed-off-by: NShotaro Gotanda <g.sho1500@gmail.com>
      Reviewed-by: NErik Skultety <eskultet@redhat.com>
      612c0d4b
    • E
      snapshots: Support topological visits · b647d219
      Eric Blake 提交于
      Wire up support for VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL in the
      domain-agnostic support code.
      
      Clients of snapshot_conf using virDomainSnapshotForEachDescendant()
      are using a depth-first visit but with postfix visits of a given
      node. Changing this to a prefix visit of the given node instantly
      turns this into a topologically-ordered visit.  (A prefix
      breadth-first visit would also be topologically sorted, but that
      requires a queue while our recursion naturally has a stack).
      
      With that change, we now always have a topological sort for
      virDomainSnapshotListAllChildren() regardless of the new public API
      flag. Then with one more tweak, we can also get a topological rather
      than a faster random hash visit for virDomainListAllSnapshots(), by
      doing a descendent walk from our internal metaroot (there, we let the
      public API flag control behavior, because a topological sort DOES
      require more stack and slightly more time).
      
      Note that virDomainSnapshotForEach() still uses a random hash visit;
      we could change that signature to take a tri-state for random, prefix,
      or postfix visit if we ever had clients that cared about the
      distinctions, but for now, none of the drivers seem to care.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      b647d219
  8. 12 3月, 2019 3 次提交
  9. 08 3月, 2019 4 次提交
    • P
      conf: fix title and description for virDomainSetMetadata API · e387afeb
      Pavel Hrdina 提交于
      If we pass XML to virDomainDefineXML API with these two elements:
      
          ...
          <title></title>
          <description></description>
          ...
      
      libvirt correctly ignores these two elements and they will not appear
      in the parsed XML.
      
      However, if we use virDomainSetMetadata API and with "" as value for
      title or description we will end up with the parsed XML that contains
      these empty elements.
      
      Let's fix the behavior of this API to behave the same as
      virDomainDefineXML.
      
      Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1518042Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
      e387afeb
    • E
      snapshot: Add virDomainSnapshotObjListParse · 1b57269c
      Eric Blake 提交于
      Add a new function to make it possible to parse a list of snapshots
      at once.  This is a counterpart to an earlier patch making it
      possible to produce all snapshots in a single XML string, and
      intentionally parses the same top-level element <snapshots> with
      an optional attribute current='name'.
      
      Note that since we know we started with no relations at all, and
      since checking parent relationships per-snapshot is not viable as
      we don't control which order the snapshots appear in, that we are
      fine with doing a final pass to update all parent/child
      relationships among the definitions.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      1b57269c
    • E
      snapshot: Split out virDomainSnapshotRedefineValidate helper · 1e90fa89
      Eric Blake 提交于
      Pull out the portion of virDomainSnapshotRefinePrep() that deals
      with definition sanity into a separate helper routine that can
      be reused with bulk redefine, leaving behind only the code
      specific to loop checking and in-place updates that are only
      needed in single-definition handling.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      1e90fa89
    • E
      snapshot: Avoid latent use-after-free when cleaning snapshots · 44a9b872
      Eric Blake 提交于
      Right now, the only callers of qemuDomainSnapshotDiscardAllMetadata()
      are right before freeing the virDomainSnapshotObjList, so it did not
      matter if the list's metaroot (which points to all the defined root
      snapshots) is left inconsistent. But an upcoming patch will want to
      clear all snapshots if a bulk redefine fails partway through, in
      which case things must be reset.  Make this work by teaching the
      existing virDomainSnapshotUpdateRelations() to be safe regardless of
      the incoming state of the metaroot (since we don't want to leak that
      internal detail into qemu code), then fixing the qemu code to use
      it after deleting all snapshots. Additionally, the qemu code must
      reset vm->current_snapshot if the current snapshot was removed,
      regardless of whether the overall removal succeeded or failed later.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
      44a9b872