snapshot: Rework parse logic during libvirt startup
snapshot: Rework parse logic during libvirt startup

Rework the logic in qemuDomainSnapshotLoad() to set
vm->current_snapshot only once at the end of the loop, rather than
repeatedly querying it during the loop, to make it easier for the next
patch to use accessor functions rather than direct manipulation of
vm->current_snapshot.  When encountering multiple snapshots claiming
to be current (based on the presence of an <active>1</active> element
in the XML, which libvirt only outputs for internal use and not for
any public API), this changes behavior from warning only once and
running with no current snapshot, to instead warning on each duplicate
and selecting the last one encountered (which is arbitrary based on
readdir() ordering, but actually stands a fair chance of being the
most-recently created snapshot whether by timestamp or by the
propensity of humans to name things in ascending order).

Note that the code in question is only run by libvirtd when it first
starts, reading state from disk from the previous run into memory for
this run. Since the data resides somewhere that only libvirt should be
touching (typically /var/lib/libvirt/qemu/snapshot/*), it should be
clean.  So in the common case, the code touched here is unreachable.
But if someone is actually messing with files behind libvirt's back,
they deserve the change in behavior.

Signed-off-by: Eric Blake <a9da18479c871fe903d9590822cfe2629c6a4d11@redhat.com>
Reviewed-by: John Ferlan <87558058f6f829e5ec976c8ef960720af4ff9c7d@redhat.com>

eskultety/libvirt,olafhering/libvirt,crobinso/libvirt,libvirt/libvirt,andreabolognani/libvirt,nertpinx/libvirt,nertpinx/libvirt,jfehlig/libvirt,jardasgit/libvirt,jfehlig/libvirt,andreabolognani/libvirt,libvirt/libvirt,crobinso/libvirt,fabianfreyer/libvirt,fabianfreyer/libvirt,andreabolognani/libvirt,crobinso/libvirt,eskultety/libvirt,olafhering/libvirt,zippy2/libvirt,eskultety/libvirt,nertpinx/libvirt,nertpinx/libvirt,fabianfreyer/libvirt,zippy2/libvirt,jardasgit/libvirt,olafhering/libvirt,libvirt/libvirt,olafhering/libvirt,andreabolognani/libvirt,nertpinx/libvirt,zippy2/libvirt,eskultety/libvirt,fabianfreyer/libvirt,crobinso/libvirt,fabianfreyer/libvirt,jardasgit/libvirt,libvirt/libvirt,andreabolognani/libvirt,jfehlig/libvirt,jfehlig/libvirt,jardasgit/libvirt,eskultety/libvirt,zippy2/libvirt,jardasgit/libvirt