1. 13 3月, 2019 5 次提交
    • E
      virsh: Add snapshot-list --topological · c615c142
      Eric Blake 提交于
      For snapshots, virsh already has a (shockingly naive [1]) client-side
      topological sorter with the --tree option. But as a series of REDEFINE
      calls must be presented in topological order, it's worth letting the
      server do the work for us, especially since the server can give us a
      topological sorting with less effort than our naive client
      reconstruction.
      
      [1] The XXX comment in virshSnapshotListCollect() about --tree being
      O(n^3) is telling; https://en.wikipedia.org/wiki/Topological_sorting
      is an interesting resource describing Kahn's algorithm and other
      approaches for O(n) topological sorting for anyone motivated to use a
      more elegant algorithm than brute force - but that doesn't affect this
      patch.
      
      For now, I am purposefully NOT implementing virsh fallback code to
      provide a topological sort when the flag was rejected as unsupported;
      we can worry about that down the road if users actually demonstrate
      that they use new virsh but old libvirt to even need the fallback.
      (The code we use for --tree could be repurposed to be such a fallback,
      whether or not we keep it naive or improve it to be faster - but
      again, no one should spend time on a fallback without evidence that we
      need it.)
      
      The test driver makes it easy to test:
      $ virsh -c test:///default '
      snapshot-create-as test a
      snapshot-create-as test c
      snapshot-create-as test b
      snapshot-list test
      snapshot-list test --topological
      snapshot-list test --descendants a
      snapshot-list test --descendants a --topological
      snapshot-list test --tree
      snapshot-list test --tree --topological
      '
      
      Without any flags, virsh does client-side sorting alphabetically, and
      lists 'b' before 'c' (even though 'c' is the parent of 'b'); with the
      flag, virsh skips sorting, and you can now see that the server handed
      back data in a correct ordering. As shown here with a simple linear
      chain, there isn't any other possible ordering, so --tree mode doesn't
      seem to care whether --topological is used.  But it is possible to
      compose more complicated DAGs with multiple children to a parent
      (representing reverting back to a snapshot then creating more
      snapshots along those divergent execution timelines), where it is then
      possible (but not guaranteed) that adding the --topological flag
      changes the --tree output (the client-side --tree algorithm breaks
      ties based on alphabetical sorting between two nodes that share the
      same parent, while the --topological sort skips the client-side
      alphabetical sort and ends up exposing the server's internal order for
      siblings, whether that be historical creation order or dependent on a
      random hash seed).  But even if the results differ, they will still be
      topologically correct.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      c615c142
    • E
      qemu: Support topological visits · e3e8fa1f
      Eric Blake 提交于
      snapshot_conf does all the hard work, the qemu driver just has to
      accept the new flag.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      e3e8fa1f
    • E
      test: Support topological visits · 3f91afe0
      Eric Blake 提交于
      snapshot_conf does all the hard work, the test driver just has to
      accept the new flag.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      3f91afe0
    • 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
    • E
      snapshots: Add flag to guarantee topological sort · d16e5b15
      Eric Blake 提交于
      When using virDomainSnapshotCreateXML with the REDEFINE flag on
      multiple snapshot metadata XML descriptions, we require that a child
      cannot be redefined before its parent.  Since libvirt already tracks a
      DAG, it is more convenient if we can ensure that
      virDomainListAllSnapshots() and friends have a way to return data in
      an order that we can directly reuse, rather than having to
      post-process the data ourselves to reconstruct the DAG.
      
      Add VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL as our new guarantee (well, a
      guarantee at the time of the API call conclusion; there's always a
      possible TOCTTOU race where someone redefining snapshots in between
      the API results and the client actually using the list might render
      the list out-of-date). Four listing APIs are directly benefitted by
      the new flag; additionally, since we document that the older racy
      ListNames interfaces should be sized by using the same flags on their
      Num counterparts, the Num interfaces must document when they accept
      (and ignore) the flag.
      
      We could have supported the new flag just for the ListAll APIs (to
      discourage people from using the older racy Num/ListNames APIs), but
      it feels weird to special-case this flag value as being applicable to
      only a subset of the API while all other List-related flags are
      trivially applicable to all 6.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NJán Tomko <jtomko@redhat.com>
      Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
      d16e5b15
  2. 12 3月, 2019 19 次提交
  3. 11 3月, 2019 6 次提交
  4. 08 3月, 2019 10 次提交