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,19 +427,16 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "live"))
|
if (vshCommandOptBool(cmd, "live"))
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
||||||
|
|
||||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
if (dom == NULL)
|
return false;
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
|
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
|
||||||
vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0)
|
vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virBufferAddLit(&buf, "<domainsnapshot>\n");
|
virBufferAddLit(&buf, "<domainsnapshot>\n");
|
||||||
if (name)
|
virBufferEscapeString(&buf, " <name>%s</name>\n", name);
|
||||||
virBufferEscapeString(&buf, " <name>%s</name>\n", name);
|
virBufferEscapeString(&buf, " <description>%s</description>\n", desc);
|
||||||
if (desc)
|
|
||||||
virBufferEscapeString(&buf, " <description>%s</description>\n", desc);
|
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -457,12 +454,13 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
virBufferAddLit(&buf, "</domainsnapshot>\n");
|
virBufferAddLit(&buf, "</domainsnapshot>\n");
|
||||||
|
|
||||||
buffer = virBufferContentAndReset(&buf);
|
if (virBufferError(&buf)) {
|
||||||
if (buffer == NULL) {
|
|
||||||
vshError(ctl, "%s", _("Out of memory"));
|
vshError(ctl, "%s", _("Out of memory"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "print-xml")) {
|
if (vshCommandOptBool(cmd, "print-xml")) {
|
||||||
vshPrint(ctl, "%s\n", buffer);
|
vshPrint(ctl, "%s\n", buffer);
|
||||||
ret = true;
|
ret = true;
|
||||||
@ -474,8 +472,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
cleanup:
|
cleanup:
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
if (dom)
|
virDomainFree(dom);
|
||||||
virDomainFree(dom);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user