snapshot: expose location through virsh snapshot-info
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.
This commit is contained in:
parent
62711817db
commit
0f9b6ee42d
@ -793,7 +793,10 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainSnapshotPtr snapshot = NULL;
|
virDomainSnapshotPtr snapshot = NULL;
|
||||||
const char *name;
|
const char *name;
|
||||||
char *doc = NULL;
|
char *doc = NULL;
|
||||||
char *tmp;
|
xmlDocPtr xmldoc = NULL;
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
char *state = NULL;
|
||||||
|
int external;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
int count;
|
int count;
|
||||||
@ -835,18 +838,48 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!doc)
|
if (!doc)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
tmp = strstr(doc, "<state>");
|
xmldoc = virXMLParseStringCtxt(doc, _("(domain_snapshot)"), &ctxt);
|
||||||
if (!tmp) {
|
if (!xmldoc)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
state = virXPathString("string(/domainsnapshot/state)", ctxt);
|
||||||
|
if (!state) {
|
||||||
vshError(ctl, "%s",
|
vshError(ctl, "%s",
|
||||||
_("unexpected problem reading snapshot xml"));
|
_("unexpected problem reading snapshot xml"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
tmp += strlen("<state>");
|
vshPrint(ctl, "%-15s %s\n", _("State:"), state);
|
||||||
vshPrint(ctl, "%-15s %.*s\n", _("State:"),
|
|
||||||
(int) (strchr(tmp, '<') - tmp), tmp);
|
|
||||||
|
|
||||||
if (vshGetSnapshotParent(ctl, snapshot, &parent) < 0)
|
/* 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. */
|
||||||
|
switch (virXPathBoolean("boolean(/domainsnapshot/memory)", ctxt)) {
|
||||||
|
case 1:
|
||||||
|
external = virXPathBoolean("boolean(/domainsnapshot/memory/@snapshot=external "
|
||||||
|
"| /domainsnapshot/disks/disk/@snapshot=external)",
|
||||||
|
ctxt);
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
external = STREQ(state, "disk-snapshot");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
external = -1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (external < 0) {
|
||||||
|
vshError(ctl, "%s",
|
||||||
|
_("unexpected problem reading snapshot xml"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
vshPrint(ctl, "%-15s %s\n", _("Location:"),
|
||||||
|
external ? _("external") : _("internal"));
|
||||||
|
|
||||||
|
/* Since we already have the XML, there's no need to call
|
||||||
|
* virDomainSnapshotGetParent */
|
||||||
|
parent = virXPathString("string(/domainsnapshot/parent/name)", ctxt);
|
||||||
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-");
|
vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-");
|
||||||
|
|
||||||
/* Children, Descendants. After this point, the fallback to
|
/* Children, Descendants. After this point, the fallback to
|
||||||
@ -858,8 +891,13 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
flags = 0;
|
flags = 0;
|
||||||
count = virDomainSnapshotNumChildren(snapshot, flags);
|
count = virDomainSnapshotNumChildren(snapshot, flags);
|
||||||
if (count < 0)
|
if (count < 0) {
|
||||||
|
if (last_error->code == VIR_ERR_NO_SUPPORT) {
|
||||||
|
vshResetLibvirtError();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
vshPrint(ctl, "%-15s %d\n", _("Children:"), count);
|
vshPrint(ctl, "%-15s %d\n", _("Children:"), count);
|
||||||
flags = VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
flags = VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||||
count = virDomainSnapshotNumChildren(snapshot, flags);
|
count = virDomainSnapshotNumChildren(snapshot, flags);
|
||||||
@ -882,6 +920,9 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(state);
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
xmlFreeDoc(xmldoc);
|
||||||
VIR_FREE(doc);
|
VIR_FREE(doc);
|
||||||
VIR_FREE(parent);
|
VIR_FREE(parent);
|
||||||
if (snapshot)
|
if (snapshot)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user