mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virsh-snapshot: Refactor some details in virsh snapshot-create-as
This patch simplifies the creation of XML, some error paths and adds correct approach to check for virBuffer errors.
This commit is contained in:
parent
8cdd5faf46
commit
02b0d3f3ac
@ -427,18 +427,15 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptBool(cmd, "live"))
|
||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
||||
|
||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
||||
if (dom == NULL)
|
||||
goto cleanup;
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
|
||||
vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0)
|
||||
goto cleanup;
|
||||
|
||||
virBufferAddLit(&buf, "<domainsnapshot>\n");
|
||||
if (name)
|
||||
virBufferEscapeString(&buf, " <name>%s</name>\n", name);
|
||||
if (desc)
|
||||
virBufferEscapeString(&buf, " <description>%s</description>\n", desc);
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
|
||||
@ -457,12 +454,13 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
virBufferAddLit(&buf, "</domainsnapshot>\n");
|
||||
|
||||
buffer = virBufferContentAndReset(&buf);
|
||||
if (buffer == NULL) {
|
||||
if (virBufferError(&buf)) {
|
||||
vshError(ctl, "%s", _("Out of memory"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
buffer = virBufferContentAndReset(&buf);
|
||||
|
||||
if (vshCommandOptBool(cmd, "print-xml")) {
|
||||
vshPrint(ctl, "%s\n", buffer);
|
||||
ret = true;
|
||||
@ -474,7 +472,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&buf);
|
||||
VIR_FREE(buffer);
|
||||
if (dom)
|
||||
virDomainFree(dom);
|
||||
|
||||
return ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user