[libvirt] [PATCH 1/2] snapshot: let virsh edit disk snapshots

Eric Blake eblake at redhat.com
Thu Oct 6 23:18:33 UTC 2011


It was impossible for 'virsh snapshot-current dom name' to set name
as the current snapshot, if name is a disk-only snapshot.

Using strstr rather than full-blown xml parsing is safe, since the
xml is assumed to be well-formed coming from libvirtd rather than
arbitrary text coming from the user.

* tools/virsh.c (cmdSnapshotCurrent, cmdSnapshotEdit): Pass
disk_only flag when redefining a disk snapshot.
---
 tools/virsh.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 48f2b8a..70a4078 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12869,6 +12869,9 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
     virDomainSnapshotFree(snapshot);
     snapshot = NULL;

+    if (strstr(doc, "<state>disk-snapshot</state>"))
+        define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY;
+
     /* Create and open the temporary file.  */
     tmp = editWriteToTempFile(ctl, doc);
     if (!tmp)
@@ -12978,6 +12981,8 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
         xml = virDomainSnapshotGetXMLDesc(snapshot, VIR_DOMAIN_XML_SECURE);
         if (!xml)
             goto cleanup;
+        if (strstr(xml, "<state>disk-snapshot</state>"))
+            flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY;
         snapshot2 = virDomainSnapshotCreateXML(dom, xml, flags);
         if (snapshot2 == NULL)
             goto cleanup;
-- 
1.7.4.4




More information about the libvir-list mailing list