[libvirt] [PATCH 1/2] snapshots: allow create --redefine to force a new configuration

Christian Ehrhardt christian.ehrhardt at canonical.com
Mon Mar 18 15:21:18 UTC 2019


Currently there is no means to permanently modify the metadata stored
within a snapshot if it does not pass the ABI compat checker.
That is pretty much intentional but there are use cases where users
verified that the change will work according to their needs and
don't want to: snapshot-revert -> edit -> start, but instead store
the modified domain definition within the metadata.

To achive that this adds a --force argument to snapshot-create
--redefine which will make it skip the check.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt at canonical.com>
---
 include/libvirt/libvirt-domain-snapshot.h | 3 +++
 src/conf/snapshot_conf.c                  | 3 ++-
 src/qemu/qemu_driver.c                    | 7 ++++++-
 tools/virsh-snapshot.c                    | 6 ++++++
 tools/virsh.pod                           | 8 +++++++-
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/include/libvirt/libvirt-domain-snapshot.h b/include/libvirt/libvirt-domain-snapshot.h
index 602e5def59..dc8ba2b4a9 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_NOCHECK     = (1 << 9), /* take definition as
+                                                          provided without
+                                                          ABI compat check */
 } virDomainSnapshotCreateFlags;
 
 /* Take a snapshot of the current VM state */
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index ffb1313c89..f95b104ad5 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -474,7 +474,8 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDefPtr def,
 
         if (other->def->dom) {
             if (def->dom) {
-                if (!virDomainDefCheckABIStability(other->def->dom,
+                if (!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NOCHECK) &&
+                    !virDomainDefCheckABIStability(other->def->dom,
                                                    def->dom, xmlopt))
                     return -1;
             } else {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a16eab5467..f3d032f633 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15680,7 +15680,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
                   VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT |
                   VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE |
                   VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC |
-                  VIR_DOMAIN_SNAPSHOT_CREATE_LIVE, NULL);
+                  VIR_DOMAIN_SNAPSHOT_CREATE_LIVE |
+                  VIR_DOMAIN_SNAPSHOT_CREATE_NOCHECK, NULL);
 
     VIR_REQUIRE_FLAG_RET(VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE,
                          VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY,
@@ -15689,6 +15690,10 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
                             VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
                             NULL);
 
+    VIR_REQUIRE_FLAG_RET(VIR_DOMAIN_SNAPSHOT_CREATE_NOCHECK,
+                         VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE,
+                         NULL);
+
     if ((redefine && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) ||
         (flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA))
         update_current = false;
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 6ea6e2744a..a680d2b410 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -146,6 +146,10 @@ static const vshCmdOptDef opts_snapshot_create[] = {
      .type = VSH_OT_BOOL,
      .help = N_("require atomic operation")
     },
+    {.name = "force",
+     .type = VSH_OT_BOOL,
+     .help = N_("do not check XML for ABI compatibility")
+    },
     VIRSH_COMMON_OPT_LIVE(N_("take a live snapshot")),
     {.name = NULL}
 };
@@ -177,6 +181,8 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC;
     if (vshCommandOptBool(cmd, "live"))
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
+    if (vshCommandOptBool(cmd, "force"))
+        flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NOCHECK;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         goto cleanup;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index db72343159..a8cd15bad2 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -4570,7 +4570,7 @@ used to represent properties of snapshots.
 
 =item B<snapshot-create> I<domain> [I<xmlfile>] {[I<--redefine> [I<--current>]]
 | [I<--no-metadata>] [I<--halt>] [I<--disk-only>] [I<--reuse-external>]
-[I<--quiesce>] [I<--atomic>] [I<--live>]}
+[I<--quiesce>] [I<--atomic>] [I<--live>] [I<--force>]}
 
 Create a snapshot for domain I<domain> with the properties specified in
 I<xmlfile>.  Normally, the only properties settable for a domain snapshot
@@ -4629,6 +4629,12 @@ the guest is running. Both disk snapshot and domain memory snapshot are
 taken. This increases the size of the memory image of the external
 snapshot. This is currently supported only for full system external snapshots.
 
+If I<--force> is specified, then the usual ABI compatibility check that
+would be done on I<--redefine> will be skipped allowing to update the
+domain definition stored in the snapshot metadata arbitrarily.
+Note: this obviously involves extra risk, supplying I<--force> assures
+libvirt that the snapshot will be compatible with the new configuration.
+
 Existence of snapshot metadata will prevent attempts to B<undefine>
 a persistent domain.  However, for transient domains, snapshot
 metadata is silently lost when the domain quits running (whether
-- 
2.17.1




More information about the libvir-list mailing list