virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
unsigned int flags, const char *from)
{
- bool ret = false;
g_autoptr(virshDomainSnapshot) snapshot = NULL;
bool halt = false;
const char *name = NULL;
persistent = virDomainIsPersistent(dom);
if (persistent < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
if (!persistent) {
vshError(ctl, "%s",
_("cannot halt after snapshot of transient domain"));
- goto cleanup;
+ return false;
}
if (virDomainIsActive(dom) == 1)
halt = true;
}
if (snapshot == NULL)
- goto cleanup;
+ return false;
if (halt && virDomainDestroy(dom) < 0) {
vshReportError(ctl);
- goto cleanup;
+ return false;
}
name = virDomainSnapshotGetName(snapshot);
if (!name) {
vshError(ctl, "%s", _("Could not get snapshot name"));
- goto cleanup;
+ return false;
}
if (from)
else
vshPrintExtra(ctl, _("Domain snapshot %s created"), name);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *from = NULL;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
- goto cleanup;
+ return false;
if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
- goto cleanup;
+ return false;
if (!from) {
buffer = g_strdup("<domainsnapshot/>");
} else {
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
- goto cleanup;
+ return false;
}
}
- ret = virshSnapshotCreate(ctl, dom, buffer, flags, from);
-
- cleanup:
- return ret;
+ return virshSnapshotCreate(ctl, dom, buffer, flags, from);
}
/*
cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
g_autofree char *buffer = NULL;
const char *name = NULL;
const char *desc = NULL;
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0)
- goto cleanup;
+ return false;
virBufferAddLit(&buf, "<domainsnapshot>\n");
virBufferAdjustIndent(&buf, 2);
virBufferEscapeString(&buf, "<description>%s</description>\n", desc);
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
- goto cleanup;
+ return false;
if (memspec && virshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "diskspec")) {
virBufferAddLit(&buf, "<disks>\n");
virBufferAdjustIndent(&buf, 2);
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (virshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0)
- goto cleanup;
+ return false;
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</disks>\n");
if (vshCommandOptBool(cmd, "print-xml")) {
vshPrint(ctl, "%s\n", buffer);
- ret = true;
- goto cleanup;
+ return true;
}
- ret = virshSnapshotCreate(ctl, dom, buffer, flags, NULL);
-
- cleanup:
- return ret;
+ return virshSnapshotCreate(ctl, dom, buffer, flags, NULL);
}
/* Helper for resolving {--current | --ARG name} into a snapshot
xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
if (!xml)
- goto cleanup;
+ return -1;
xmldoc = virXMLParseStringCtxt(xml, _("(domain_snapshot)"), &ctxt);
if (!xmldoc)
- goto cleanup;
+ return -1;
/* Libvirt 1.0.1 and newer never call this function, because the
* filtering is already supported by the listing functions. Older
state = virXPathString("string(/domainsnapshot/state)", ctxt);
if (!state) {
vshError(ctl, "%s", _("unable to perform snapshot filtering"));
- goto cleanup;
+ return -1;
}
if (STREQ(state, "disk-snapshot")) {
ret = ((flags & (VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY |
ret = !!(flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE);
}
- cleanup:
return ret;
}
g_autofree char *state = NULL;
int external;
g_autofree char *parent = NULL;
- bool ret = false;
int count;
unsigned int flags;
int current;
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
&snapshot, &name) < 0)
- goto cleanup;
+ return false;
vshPrint(ctl, "%-15s %s\n", _("Name:"), name);
vshPrint(ctl, "%-15s %s\n", _("Domain:"), virDomainGetName(dom));
* state of the machine at the time of the snapshot. */
doc = virDomainSnapshotGetXMLDesc(snapshot, 0);
if (!doc)
- goto cleanup;
+ return false;
xmldoc = virXMLParseStringCtxt(doc, _("(domain_snapshot)"), &ctxt);
if (!xmldoc)
- goto cleanup;
+ return false;
state = virXPathString("string(/domainsnapshot/state)", ctxt);
if (!state) {
vshError(ctl, "%s",
_("unexpected problem reading snapshot xml"));
- goto cleanup;
+ return false;
}
vshPrint(ctl, "%-15s %s\n", _("State:"), state);
if (external < 0) {
vshError(ctl, "%s",
_("unexpected problem reading snapshot xml"));
- goto cleanup;
+ return false;
}
vshPrint(ctl, "%-15s %s\n", _("Location:"),
external ? _("external") : _("internal"));
/* Children, Descendants. After this point, the fallback to
* compute children is too expensive, so we gracefully quit if the
* APIs don't exist. */
- if (priv->useSnapshotOld) {
- ret = true;
- goto cleanup;
- }
+ if (priv->useSnapshotOld)
+ return true;
flags = 0;
count = virDomainSnapshotNumChildren(snapshot, flags);
if (count < 0) {
if (last_error->code == VIR_ERR_NO_SUPPORT) {
vshResetLibvirtError();
- ret = true;
+ return true;
}
- goto cleanup;
+ return false;
}
vshPrint(ctl, "%-15s %d\n", _("Children:"), count);
flags = VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
count = virDomainSnapshotNumChildren(snapshot, flags);
if (count < 0)
- goto cleanup;
+ return false;
vshPrint(ctl, "%-15s %d\n", _("Descendants:"), count);
/* Metadata; the fallback here relies on the fact that metadata
vshPrint(ctl, "%-15s %s\n", _("Metadata:"),
metadata ? _("yes") : _("no"));
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/* Helpers for collecting a list of snapshots. */
cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name = NULL;
g_autoptr(virshDomainSnapshot) snapshot = NULL;
g_autofree char *xml = NULL;
return false;
if (!(snapshot = virDomainSnapshotLookupByName(dom, name, 0)))
- goto cleanup;
+ return false;
if (!(xml = virDomainSnapshotGetXMLDesc(snapshot, flags)))
- goto cleanup;
+ return false;
vshPrint(ctl, "%s", xml);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name = NULL;
g_autoptr(virshDomainSnapshot) snapshot = NULL;
g_autofree char *parent = NULL;
dom = virshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
- goto cleanup;
+ return false;
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
&snapshot, &name) < 0)
- goto cleanup;
+ return false;
if (virshGetSnapshotParent(ctl, snapshot, &parent) < 0)
- goto cleanup;
+ return false;
if (!parent) {
vshError(ctl, _("snapshot '%s' has no parent"), name);
- goto cleanup;
+ return false;
}
vshPrint(ctl, "%s", parent);
- ret = true;
-
- cleanup:
- return ret;
+ return true;
}
/*
cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name = NULL;
g_autoptr(virshDomainSnapshot) snapshot = NULL;
unsigned int flags = 0;
dom = virshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
- goto cleanup;
+ return false;
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
&snapshot, &name) < 0)
- goto cleanup;
+ return false;
result = virDomainRevertToSnapshot(snapshot, flags);
if (result < 0 && force &&
result = virDomainRevertToSnapshot(snapshot, flags);
}
if (result < 0)
- goto cleanup;
-
- ret = true;
-
- cleanup:
+ return false;
- return ret;
+ return true;
}
/*
cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
{
g_autoptr(virshDomain) dom = NULL;
- bool ret = false;
const char *name = NULL;
g_autoptr(virshDomainSnapshot) snapshot = NULL;
unsigned int flags = 0;
dom = virshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
- goto cleanup;
+ return false;
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
&snapshot, &name) < 0)
- goto cleanup;
+ return false;
if (vshCommandOptBool(cmd, "children"))
flags |= VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN;
vshPrintExtra(ctl, _("Domain snapshot %s deleted\n"), name);
} else {
vshError(ctl, _("Failed to delete snapshot %s"), name);
- goto cleanup;
+ return false;
}
- ret = true;
-
- cleanup:
-
- return ret;
+ return true;
}
const vshCmdDef snapshotCmds[] = {