[libvirt] [PATCH 1/3] virsh: clarify snapshot vs. save

* tools/virsh.c (info_snapshot_create, info_save): Clarify description. * tools/virsh.pod (save): Likewise. --- tools/virsh.c | 6 +++--- tools/virsh.pod | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 1c0b1dc..6b5f3d9 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1469,7 +1469,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) */ static const vshCmdInfo info_save[] = { {"help", N_("save a domain state to a file")}, - {"desc", N_("Save a running domain.")}, + {"desc", N_("Save the RAM state of a running domain.")}, {NULL, NULL} }; @@ -10947,8 +10947,8 @@ cmdQuit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) * "snapshot-create" command */ static const vshCmdInfo info_snapshot_create[] = { - {"help", N_("Create a snapshot")}, - {"desc", N_("Snapshot create")}, + {"help", N_("Create a snapshot from XML")}, + {"desc", N_("Create a snapshot (disk and RAM) from XML")}, {NULL, NULL} }; diff --git a/tools/virsh.pod b/tools/virsh.pod index c6879cb..33f72ed 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -594,7 +594,8 @@ the state file was created. =item B<save> I<domain-id> I<state-file> -Saves a running domain to a state file so that it can be restored +Saves a running domain (RAM, but not disk state) to a state file so that +it can be restored later. Once saved, the domain will no longer be running on the system, thus the memory allocated for the domain will be free for other domains to use. B<virsh restore> restores from this state file. @@ -603,6 +604,11 @@ This is roughly equivalent to doing a hibernate on a running computer, with all the same limitations. Open network connections may be severed upon restore, as TCP timeouts may have expired. +Domain saved state files assume that disk images will be unchanged +between the creation and restore point. For a more complete system +restore point, where the disk state is saved alongside the memory +state, see the B<snapshot> family of commands. + =item B<schedinfo> optional I<--set> B<parameter=value> I<domain-id> I<--config> I<--live> I<--current> -- 1.7.1

Producing an xml file just for name and description fields is overkill; this makes life easier from virsh. * tools/virsh.c (cmdSnapshotCreateAs): New command. (snapshotCmds): Install it. * tools/virsh.pod: Document it. --- tools/virsh.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 8 ++++- 2 files changed, 109 insertions(+), 1 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 6b5f3d9..3a59acd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -11042,6 +11042,106 @@ cleanup: } /* + * "snapshot-create-as" command + */ +static const vshCmdInfo info_snapshot_create_as[] = { + {"help", N_("Create a snapshot from a set of args")}, + {"desc", N_("Create a snapshot (disk and RAM) from arguments")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_snapshot_create_as[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {"name", VSH_OT_DATA, 0, N_("name of snapshot")}, + {"description", VSH_OT_DATA, 0, N_("description of snapshot")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom = NULL; + bool ret = false; + char *buffer = NULL; + virDomainSnapshotPtr snapshot = NULL; + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + char *doc = NULL; + const char *name = NULL; + const char *desc = NULL; + char *parsed_name = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto cleanup; + + dom = vshCommandOptDomain(ctl, cmd, NULL); + if (dom == NULL) + goto cleanup; + + if (vshCommandOptString(cmd, "name", &name) < 0 || + vshCommandOptString(cmd, "description", &desc) < 0) { + vshError(ctl, _("argument must not be argument")); + goto cleanup; + } + + virBufferAddLit(&buf, "<domainsnapshot>\n"); + if (name) + virBufferAsprintf(&buf, " <name>%s</name>\n", name); + if (desc) + virBufferAsprintf(&buf, " <description>%s</description>\n", desc); + virBufferAddLit(&buf, "</domainsnapshot>\n"); + + buffer = virBufferContentAndReset(&buf); + if (buffer == NULL) { + vshError(ctl, "%s", _("Out of memory")); + goto cleanup; + } + + snapshot = virDomainSnapshotCreateXML(dom, buffer, 0); + if (snapshot == NULL) + goto cleanup; + + doc = virDomainSnapshotGetXMLDesc(snapshot, 0); + if (!doc) + goto cleanup; + + xml = xmlReadDoc((const xmlChar *) doc, "domainsnapshot.xml", NULL, + XML_PARSE_NOENT | XML_PARSE_NONET | + XML_PARSE_NOWARNING); + if (!xml) + goto cleanup; + ctxt = xmlXPathNewContext(xml); + if (!ctxt) + goto cleanup; + + parsed_name = virXPathString("string(/domainsnapshot/name)", ctxt); + if (!parsed_name) { + vshError(ctl, "%s", + _("Could not find 'name' element in domain snapshot XML")); + goto cleanup; + } + + vshPrint(ctl, _("Domain snapshot %s created\n"), name ? name : parsed_name); + + ret = true; + +cleanup: + VIR_FREE(parsed_name); + xmlXPathFreeContext(ctxt); + if (xml) + xmlFreeDoc(xml); + if (snapshot) + virDomainSnapshotFree(snapshot); + VIR_FREE(doc); + VIR_FREE(buffer); + if (dom) + virDomainFree(dom); + + return ret; +} + +/* * "snapshot-current" command */ static const vshCmdInfo info_snapshot_current[] = { @@ -11679,6 +11779,8 @@ static const vshCmdDef virshCmds[] = { static const vshCmdDef snapshotCmds[] = { {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create, info_snapshot_create, 0}, + {"snapshot-create-as", cmdSnapshotCreateAs, opts_snapshot_create_as, + info_snapshot_create_as, 0}, {"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current, info_snapshot_current, 0}, {"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete, diff --git a/tools/virsh.pod b/tools/virsh.pod index 33f72ed..44f2e25 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1394,7 +1394,7 @@ used to represent properties of snapshots. =over 4 -=item B<snapshot-create> I<domain> I<xmlfile> +=item B<snapshot-create> I<domain> optional I<xmlfile> Create a snapshot for domain I<domain> with the properties specified in I<xmlfile>. The only properties settable for a domain snapshot are the @@ -1402,6 +1402,12 @@ I<xmlfile>. The only properties settable for a domain snapshot are the automatically filled in by libvirt. If I<xmlfile> is completely omitted, then libvirt will choose a value for all fields. +=item B<snapshot-create-as> I<domain> optional I<name> I<description> + +Create a snapshot for domain I<domain> with the given <name> and +<description>; if either value is omitted, libvirt will choose a +value. + =item B<snapshot-current> I<domain> Output the snapshot XML for the domain's current snapshot (if any). -- 1.7.1

On Wed, Jun 15, 2011 at 04:26:25PM -0600, Eric Blake wrote:
Producing an xml file just for name and description fields is overkill; this makes life easier from virsh.
* tools/virsh.c (cmdSnapshotCreateAs): New command. (snapshotCmds): Install it. * tools/virsh.pod: Document it. --- tools/virsh.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 8 ++++- 2 files changed, 109 insertions(+), 1 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 6b5f3d9..3a59acd 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -11042,6 +11042,106 @@ cleanup: }
/* + * "snapshot-create-as" command + */ +static const vshCmdInfo info_snapshot_create_as[] = { + {"help", N_("Create a snapshot from a set of args")}, + {"desc", N_("Create a snapshot (disk and RAM) from arguments")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_snapshot_create_as[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {"name", VSH_OT_DATA, 0, N_("name of snapshot")}, + {"description", VSH_OT_DATA, 0, N_("description of snapshot")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom = NULL; + bool ret = false; + char *buffer = NULL; + virDomainSnapshotPtr snapshot = NULL; + xmlDocPtr xml = NULL; + xmlXPathContextPtr ctxt = NULL; + char *doc = NULL; + const char *name = NULL; + const char *desc = NULL; + char *parsed_name = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto cleanup; + + dom = vshCommandOptDomain(ctl, cmd, NULL); + if (dom == NULL) + goto cleanup; + + if (vshCommandOptString(cmd, "name", &name) < 0 || + vshCommandOptString(cmd, "description", &desc) < 0) { + vshError(ctl, _("argument must not be argument"));
??? if that's right that's a very cryptic one :-)
+ goto cleanup; + } + + virBufferAddLit(&buf, "<domainsnapshot>\n"); + if (name) + virBufferAsprintf(&buf, " <name>%s</name>\n", name); + if (desc) + virBufferAsprintf(&buf, " <description>%s</description>\n", desc); + virBufferAddLit(&buf, "</domainsnapshot>\n");
ACK with this fixed :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 06/16/2011 02:00 AM, Daniel Veillard wrote:
+ if (vshCommandOptString(cmd, "name", &name) < 0 || + vshCommandOptString(cmd, "description", &desc) < 0) { + vshError(ctl, _("argument must not be argument"));
??? if that's right that's a very cryptic one :-)
Argument must not be empty. virsh snapshot-create-as domain --name '' doesn't work. (Don't know what I was thinking as I typed yesterday :) -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/6/16 Eric Blake <eblake@redhat.com>:
Producing an xml file just for name and description fields is overkill; this makes life easier from virsh.
* tools/virsh.c (cmdSnapshotCreateAs): New command. (snapshotCmds): Install it. * tools/virsh.pod: Document it. --- tools/virsh.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 8 ++++- 2 files changed, 109 insertions(+), 1 deletions(-)
I have posted a similar addition a while ago, but directly for the snapshot-create command. That was rejected in favor of a new snapshot-create-as command. Now I can remove this one from my todo list :) ACK. -- Matthias Bolte http://photron.blogspot.com

Similar to pool-create-as. * tools/virsh.c (cmdSnapshotCreateAs): Add --print-xml. * tools/virsh.pod: Document it. --- tools/virsh.c | 7 +++++++ tools/virsh.pod | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 3a59acd..97f7cf8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -11054,6 +11054,7 @@ static const vshCmdOptDef opts_snapshot_create_as[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"name", VSH_OT_DATA, 0, N_("name of snapshot")}, {"description", VSH_OT_DATA, 0, N_("description of snapshot")}, + {"print-xml", VSH_OT_BOOL, 0, N_("print XML document rather than create")}, {NULL, 0, 0, NULL} }; @@ -11098,6 +11099,12 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; } + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s\n", buffer); + ret = true; + goto cleanup; + } + snapshot = virDomainSnapshotCreateXML(dom, buffer, 0); if (snapshot == NULL) goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index 44f2e25..567e7de 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1402,11 +1402,13 @@ I<xmlfile>. The only properties settable for a domain snapshot are the automatically filled in by libvirt. If I<xmlfile> is completely omitted, then libvirt will choose a value for all fields. -=item B<snapshot-create-as> I<domain> optional I<name> I<description> +=item B<snapshot-create-as> I<domain> optional I<--print-xml> +I<name> I<description> Create a snapshot for domain I<domain> with the given <name> and <description>; if either value is omitted, libvirt will choose a -value. +value. If I<--print-xml> is specified, then XML appropriate for +I<snapshot-create> is output, rather than actually creating a snapshot. =item B<snapshot-current> I<domain> -- 1.7.1

On Wed, Jun 15, 2011 at 04:26:26PM -0600, Eric Blake wrote:
Similar to pool-create-as.
* tools/virsh.c (cmdSnapshotCreateAs): Add --print-xml. * tools/virsh.pod: Document it. --- tools/virsh.c | 7 +++++++ tools/virsh.pod | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 3a59acd..97f7cf8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -11054,6 +11054,7 @@ static const vshCmdOptDef opts_snapshot_create_as[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"name", VSH_OT_DATA, 0, N_("name of snapshot")}, {"description", VSH_OT_DATA, 0, N_("description of snapshot")}, + {"print-xml", VSH_OT_BOOL, 0, N_("print XML document rather than create")}, {NULL, 0, 0, NULL} };
@@ -11098,6 +11099,12 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; }
+ if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s\n", buffer); + ret = true; + goto cleanup; + } + snapshot = virDomainSnapshotCreateXML(dom, buffer, 0); if (snapshot == NULL) goto cleanup; diff --git a/tools/virsh.pod b/tools/virsh.pod index 44f2e25..567e7de 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1402,11 +1402,13 @@ I<xmlfile>. The only properties settable for a domain snapshot are the automatically filled in by libvirt. If I<xmlfile> is completely omitted, then libvirt will choose a value for all fields.
-=item B<snapshot-create-as> I<domain> optional I<name> I<description> +=item B<snapshot-create-as> I<domain> optional I<--print-xml> +I<name> I<description>
Create a snapshot for domain I<domain> with the given <name> and <description>; if either value is omitted, libvirt will choose a -value. +value. If I<--print-xml> is specified, then XML appropriate for +I<snapshot-create> is output, rather than actually creating a snapshot.
=item B<snapshot-current> I<domain>
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

2011/6/16 Eric Blake <eblake@redhat.com>:
Similar to pool-create-as.
* tools/virsh.c (cmdSnapshotCreateAs): Add --print-xml. * tools/virsh.pod: Document it. --- tools/virsh.c | 7 +++++++ tools/virsh.pod | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

On 06/16/2011 02:02 AM, Matthias Bolte wrote:
2011/6/16 Eric Blake <eblake@redhat.com>:
Similar to pool-create-as.
* tools/virsh.c (cmdSnapshotCreateAs): Add --print-xml. * tools/virsh.pod: Document it. --- tools/virsh.c | 7 +++++++ tools/virsh.pod | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
ACK.
Thanks; series pushed, including the error message fix in 2/3 pointed out by DV. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/6/16 Eric Blake <eblake@redhat.com>:
* tools/virsh.c (info_snapshot_create, info_save): Clarify description. * tools/virsh.pod (save): Likewise. --- tools/virsh.c | 6 +++--- tools/virsh.pod | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-)
ACK. -- Matthias Bolte http://photron.blogspot.com

On Wed, Jun 15, 2011 at 04:26:24PM -0600, Eric Blake wrote:
* tools/virsh.c (info_snapshot_create, info_save): Clarify description. * tools/virsh.pod (save): Likewise. --- tools/virsh.c | 6 +++--- tools/virsh.pod | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-)
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Matthias Bolte