char *historyfile; /* readline history file name */
bool useGetInfo; /* must use virDomainGetInfo, since
virDomainGetState is not supported */
- bool useSnapshotGetXML; /* must use virDomainSnapshotGetXMLDesc, since
- virDomainSnapshotGetParent is missing */
+ bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or
+ virDomainSnapshotNumChildren */
} __vshControl;
typedef struct vshCmdGrp {
vshError(ctl, "%s", _("Reconnected to the hypervisor"));
disconnected = 0;
ctl->useGetInfo = false;
- ctl->useSnapshotGetXML = false;
+ ctl->useSnapshotOld = false;
}
/* ---------------
ctl->name = vshStrdup(ctl, name);
ctl->useGetInfo = false;
- ctl->useSnapshotGetXML = false;
+ ctl->useSnapshotOld = false;
ctl->readonly = ro;
ctl->conn = virConnectOpenAuth(ctl->name, virConnectAuthPtrDefault,
*parent_name = NULL;
/* Try new API, since it is faster. */
- if (!ctl->useSnapshotGetXML) {
+ if (!ctl->useSnapshotOld) {
parent = virDomainSnapshotGetParent(snapshot, 0);
if (parent) {
/* API works, and virDomainSnapshotGetName will succeed */
goto cleanup;
}
/* API didn't work, fall back to XML scraping. */
- ctl->useSnapshotGetXML = true;
+ ctl->useSnapshotOld = true;
}
xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
if (vshCommandOptBool(cmd, "descendants") || tree) {
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
}
- numsnaps = virDomainSnapshotNumChildren(start, flags);
- if (numsnaps >= 0 && tree)
- numsnaps++;
- /* XXX Is it worth emulating --from on older servers? */
+ numsnaps = ctl->useSnapshotOld ? -1 :
+ virDomainSnapshotNumChildren(start, flags);
+ /* XXX Is it worth emulating --from without --tree on older servers? */
+ if (tree) {
+ if (numsnaps >= 0) {
+ numsnaps++;
+ } else if (ctl->useSnapshotOld ||
+ last_error->code == VIR_ERR_NO_SUPPORT) {
+ /* We can emulate --tree --from. */
+ virFreeError(last_error);
+ last_error = NULL;
+ ctl->useSnapshotOld = true;
+ flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
+ numsnaps = virDomainSnapshotNum(dom, flags);
+ }
+ }
} else {
numsnaps = virDomainSnapshotNum(dom, flags);
}
}
- if (numsnaps < 0)
+ if (numsnaps < 0) {
+ if (!last_error)
+ vshError(ctl, _("missing support"));
goto cleanup;
+ }
if (!tree) {
if (parent_filter > 0)
if (VIR_ALLOC_N(names, numsnaps) < 0)
goto cleanup;
- if (from) {
+ if (from && !ctl->useSnapshotOld) {
/* When mixing --from and --tree, we want to start the tree at the
* given snapshot. Without --tree, only list the children. */
if (tree) {
if (tree) {
char indentBuf[INDENT_BUFLEN];
char **parents = vshCalloc(ctl, sizeof(char *), actual);
- for (i = (from ? 1 : 0); i < actual; i++) {
+ for (i = (from && !ctl->useSnapshotOld); i < actual; i++) {
/* free up memory from previous iterations of the loop */
if (snapshot)
virDomainSnapshotFree(snapshot);
}
for (i = 0 ; i < actual ; i++) {
memset(indentBuf, '\0', sizeof indentBuf);
- if (parents[i] == NULL)
+ if (ctl->useSnapshotOld ? STREQ(names[i], from) : !parents[i])
cmdNodeListDevicesPrint(ctl,
names,
parents,