Re: [libvirt] [PATCH 7/7] snapshot: Add VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST flag

2019-02-20 Thread Eric Blake
On 2/20/19 9:53 AM, Eric Blake wrote:
> Continue the work of the previous patch in making it possible
> to copy the state of a transient domain with snapshots from one
> host to another, by allowing the destination to perform bulk
> redefines.  Note that the destination still has to do separate
> calls for creating/defining the domain first, and then redefining
> the snapshots (that is, there is intentional asymmetry between
> dumping the list in virDomainGetXMLDesc() but redefining it via
> virDomainSnapshotCreateXML()), but this is better than the
> previous state of having to make multiple REDEFINE calls.  The
> bulk flag requires no pre-existing snapshot metadata (as that
> makes life much easier if there is a failure encountered partway
> through the list processing - simply remove all other snapshot
> metadatas), and makes no guarantees on which snapshot (when there
> are multiple) will actually be returned.
> 
> Wire up the virsh snapshot-create command to support the new flag.
> 
> Actual driver implementations will be in later patches.
> 
> Signed-off-by: Eric Blake 
> ---
>  include/libvirt/libvirt-domain-snapshot.h |  3 +++
>  src/libvirt-domain-snapshot.c | 21 ++---
>  tools/virsh-snapshot.c| 13 +
>  3 files changed, 34 insertions(+), 3 deletions(-)
> 

For convenience, I'll probably squash this in (while the API requires
both REDEFINE and REDEFINE_LIST flags, the virsh tooling can imply one
from the other):

diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index f6efadde2d..a58731c46e 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -131,7 +131,7 @@ static const vshCmdOptDef opts_snapshot_create[] = {
 VIRSH_COMMON_OPT_CURRENT(N_("with redefine, set current snapshot")),
 {.name = "redefine-list",
  .type = VSH_OT_BOOL,
- .help = N_("with redefine, bulk define a set of snapshots"),
+ .help = N_("bulk define a set of snapshots, implies --redefine"),
 },
 {.name = "no-metadata",
  .type = VSH_OT_BOOL,
@@ -189,7 +189,8 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
 if (vshCommandOptBool(cmd, "live"))
 flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
 if (vshCommandOptBool(cmd, "redefine-list"))
-flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST;
+flags |= VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
+VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST;

 if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
 goto cleanup;


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 7/7] snapshot: Add VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST flag

2019-02-20 Thread Eric Blake
Continue the work of the previous patch in making it possible
to copy the state of a transient domain with snapshots from one
host to another, by allowing the destination to perform bulk
redefines.  Note that the destination still has to do separate
calls for creating/defining the domain first, and then redefining
the snapshots (that is, there is intentional asymmetry between
dumping the list in virDomainGetXMLDesc() but redefining it via
virDomainSnapshotCreateXML()), but this is better than the
previous state of having to make multiple REDEFINE calls.  The
bulk flag requires no pre-existing snapshot metadata (as that
makes life much easier if there is a failure encountered partway
through the list processing - simply remove all other snapshot
metadatas), and makes no guarantees on which snapshot (when there
are multiple) will actually be returned.

Wire up the virsh snapshot-create command to support the new flag.

Actual driver implementations will be in later patches.

Signed-off-by: Eric Blake 
---
 include/libvirt/libvirt-domain-snapshot.h |  3 +++
 src/libvirt-domain-snapshot.c | 21 ++---
 tools/virsh-snapshot.c| 13 +
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/include/libvirt/libvirt-domain-snapshot.h 
b/include/libvirt/libvirt-domain-snapshot.h
index 2532b99c58..113fe4a18b 100644
--- a/include/libvirt/libvirt-domain-snapshot.h
+++ b/include/libvirt/libvirt-domain-snapshot.h
@@ -71,6 +71,9 @@ typedef enum {
 VIR_DOMAIN_SNAPSHOT_CREATE_LIVE= (1 << 8), /* create the snapshot
   while the guest is
   running */
+VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST = (1 << 9), /* parse multiple
+snapshots in one
+API call */
 } virDomainSnapshotCreateFlags;

 /* Take a snapshot of the current VM state */
diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c
index 4e46f0876b..a661bcbff9 100644
--- a/src/libvirt-domain-snapshot.c
+++ b/src/libvirt-domain-snapshot.c
@@ -102,7 +102,7 @@ virDomainSnapshotGetConnect(virDomainSnapshotPtr snapshot)
  * @flags: bitwise-OR of virDomainSnapshotCreateFlags
  *
  * Creates a new snapshot of a domain based on the snapshot xml
- * contained in xmlDesc.
+ * contained in xmlDesc, with a top-level  element.
  *
  * If @flags is 0, the domain can be active, in which case the
  * snapshot will be a system checkpoint (both disk state and runtime
@@ -131,8 +131,17 @@ virDomainSnapshotGetConnect(virDomainSnapshotPtr snapshot)
  * guest-visible layout.  When redefining a snapshot name that does
  * not exist, the hypervisor may validate that reverting to the
  * snapshot appears to be possible (for example, disk images have
- * snapshot contents by the requested name).  Not all hypervisors
- * support these flags.
+ * snapshot contents by the requested name).  Alternatively, if @flags
+ * includes VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST (which requires
+ * VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE and is incompatible with
+ * VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT), and the domain has no existing
+ * snapshot metadata, then @xmlDesc is parsed as a top-level
+ *  element with an optional current='name' attribute, and
+ * containing one or more  children (as produced by
+ * virDomainGetXMLDesc() with the flag VIR_DOMAIN_XML_SNAPSHOTS), to
+ * do a bulk redefine of all snapshots at once (it is unspecified
+ * which of the redefined snapshots will be used as the return value
+ * on success).  Not all hypervisors support these flags.
  *
  * If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA, then the
  * domain's disk images are modified according to @xmlDesc, but then
@@ -218,6 +227,9 @@ virDomainSnapshotCreateXML(virDomainPtr domain,
 VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT,
   VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
   error);
+VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST,
+  VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
+  error);

 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
  VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA,
@@ -225,6 +237,9 @@ virDomainSnapshotCreateXML(virDomainPtr domain,
 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
  VIR_DOMAIN_SNAPSHOT_CREATE_HALT,
  error);
+VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE_LIST,
+ VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT,
+ error);

 if (conn->driver->domainSnapshotCreateXML) {
 virDomainSnapshotPtr ret;
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index