On Wed, Mar 27, 2019 at 05:10:49 -0500, Eric Blake wrote:
A lot of this work heavily copies from the existing snapshot
APIs. The interaction with qemu during create/delete still
needs to be implemented, but this takes care of all the libvirt
metadata (saving and restoring XML, and tracking the relations
between multiple checkpoints).
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/qemu/qemu_block.h | 3 +
src/qemu/qemu_conf.h | 2 +
src/qemu/qemu_domain.h | 15 +
src/qemu/qemu_block.c | 12 +
src/qemu/qemu_conf.c | 5 +
src/qemu/qemu_domain.c | 133 +++++++
src/qemu/qemu_driver.c | 843 +++++++++++++++++++++++++++++++++++++++++
7 files changed, 1013 insertions(+)
[...]
+static char *
+qemuDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint,
+ unsigned int flags)
+{
+ virQEMUDriverPtr driver = checkpoint->domain->conn->privateData;
+ virDomainObjPtr vm = NULL;
+ char *xml = NULL;
+ virDomainMomentObjPtr chk = NULL;
+ qemuDomainObjPrivatePtr priv;
+ int rc;
+ size_t i;
+ virDomainCheckpointDefPtr chkdef;
+
+ virCheckFlags(VIR_DOMAIN_CHECKPOINT_XML_SECURE |
+ VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN |
+ VIR_DOMAIN_CHECKPOINT_XML_SIZE, NULL);
+
+ if (!(vm = qemuDomObjFromCheckpoint(checkpoint)))
+ return NULL;
+
+ if (virDomainCheckpointGetXMLDescEnsureACL(checkpoint->domain->conn,
vm->def, flags) < 0)
+ goto cleanup;
+
+ if (!(chk = qemuCheckObjFromCheckpoint(vm, checkpoint)))
+ goto cleanup;
+ chkdef = virDomainCheckpointObjGetDef(chk);
+
+ if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) {
+ /* TODO: for non-current checkpoint, this requires a QMP sequence per
+ disk, since the stat of one bitmap in isolation is too low,
+ and merely adding bitmap sizes may be too high:
+ block-dirty-bitmap-create tmp
+ for each bitmap from checkpoint to current:
+ add bitmap to src_list
+ block-dirty-bitmap-merge dst=tmp src_list
+ query-block and read tmp size
+ block-dirty-bitmap-remove tmp
+ So for now, go with simpler query-blocks only for current.
+ */
+ if (virDomainCheckpointGetCurrent(vm->checkpoints) != chk) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("cannot compute size for non-current checkpoint
'%s'"),
+ checkpoint->name);
+ goto cleanup;
+ }
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (virDomainObjCheckActive(vm) < 0)
+ goto endjob;
+
+ if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+ goto endjob;
+
+ /* TODO: Shouldn't need to recompute node names. */
+ for (i = 0; i < chkdef->ndisks; i++) {
+ virDomainCheckpointDiskDef *disk = &chkdef->disks[i];
+
+ if (disk->type != VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP)
+ continue;
+
VIR_FREE(chk->def->dom->disks[disk->idx]->src->nodeformat);
+ if
(VIR_STRDUP(chk->def->dom->disks[disk->idx]->src->nodeformat,
+ qemuBlockNodeLookup(vm, disk->name)) < 0)
+ goto endjob;
+ }
+
+ priv = vm->privateData;
+ qemuDomainObjEnterMonitor(driver, vm);
+ rc = qemuMonitorUpdateCheckpointSize(priv->mon, chkdef);
This modifies the checkpoint definition while the domain object is not
locked. Currently it "probably" is okay, but we should definitely not do
that as long as the checkpoint definition shares the domain object lock.
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ goto endjob;