On 11/15/12 00:36, Eric Blake wrote:
Now that we can filter on this information, we should also make
it easy to get at.
* tools/virsh-snapshot.c (cmdSnapshotInfo): Add another output
row, and switch to XPath queries rather than strstr.
---
tools/virsh-snapshot.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 49 insertions(+), 8 deletions(-)
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 7cd2966..36f5b46 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -797,7 +797,10 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
virDomainSnapshotPtr snapshot = NULL;
const char *name;
char *doc = NULL;
- char *tmp;
+ xmlDocPtr xmldoc = NULL;
+ xmlXPathContextPtr ctxt = NULL;
+ char *state = NULL;
+ int external;
char *parent = NULL;
bool ret = false;
int count;
@@ -839,18 +842,48 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- tmp = strstr(doc, "<state>");
- if (!tmp) {
+ xmldoc = virXMLParseStringCtxt(doc, _("(domain_snapshot)"), &ctxt);
+ if (!xmldoc)
+ goto cleanup;
+
+ state = virXPathString("string(/domainsnapshot/state)", ctxt);
+ if (!state) {
vshError(ctl, "%s",
_("unexpected problem reading snapshot xml"));
We probably could be a bit more specific about the error here, but
that's not really important.
goto cleanup;
}
- tmp += strlen("<state>");
- vshPrint(ctl, "%-15s %.*s\n", _("State:"),
- (int) (strchr(tmp, '<') - tmp), tmp);
+ vshPrint(ctl, "%-15s %s\n", _("State:"), state);
+
+ /* In addition to state, location is useful. If the snapshot has
+ * a <memory> element, then the existence of snapshot='external'
+ * prior to <domain> is the deciding factor; for snapshots
+ * created prior to 1.0.1, a state of disk-only is the only
+ * external snapshot. */
This looks better than the raw xml magic.
ACK.
Peter