From cbaee2199b0c15d3ace6ee0b488b79a7bd6719b3 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 3 Oct 2019 14:35:58 +0200 Subject: [PATCH] qemu: checkpoint: Extract finalizing steps of checkpoint creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the linking and saving bits of checkpoint creation into qemuCheckpointCreateFinalize so that qemuCheckpointCreateXML is a bit simpler and also makes it reusable in the backup code. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_checkpoint.c | 44 +++++++++++++++++++++++++------------- src/qemu/qemu_checkpoint.h | 7 ++++++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 5d1d982f52..6c3099ef76 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -429,6 +429,34 @@ qemuCheckpointCreate(virQEMUDriverPtr driver, } +int +qemuCheckpointCreateFinalize(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virQEMUDriverConfigPtr cfg, + virDomainMomentObjPtr chk, + bool update_current) +{ + if (update_current) + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + + if (qemuCheckpointWriteMetadata(vm, chk, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) { + /* if writing of metadata fails, error out rather than trying + * to silently carry on without completing the checkpoint */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to save metadata for checkpoint %s"), + chk->def->name); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + return -1; + } + + virDomainCheckpointLinkParent(vm->checkpoints, chk); + + return 0; +} + + virDomainCheckpointPtr qemuCheckpointCreateXML(virDomainPtr domain, virDomainObjPtr vm, @@ -486,22 +514,8 @@ qemuCheckpointCreateXML(virDomainPtr domain, if (!chk) goto endjob; - if (update_current) - virDomainCheckpointSetCurrent(vm->checkpoints, chk); - - if (qemuCheckpointWriteMetadata(vm, chk, driver->caps, - driver->xmlopt, - cfg->checkpointDir) < 0) { - /* if writing of metadata fails, error out rather than trying - * to silently carry on without completing the checkpoint */ - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to save metadata for checkpoint %s"), - chk->def->name); - virDomainCheckpointObjListRemove(vm->checkpoints, chk); + if (qemuCheckpointCreateFinalize(driver, vm, cfg, chk, update_current) < 0) goto endjob; - } - - virDomainCheckpointLinkParent(vm->checkpoints, chk); /* If we fail after this point, there's not a whole lot we can do; * we've successfully created the checkpoint, so we have to go diff --git a/src/qemu/qemu_checkpoint.h b/src/qemu/qemu_checkpoint.h index 7fcbc99541..d0ea8f000f 100644 --- a/src/qemu/qemu_checkpoint.h +++ b/src/qemu/qemu_checkpoint.h @@ -61,3 +61,10 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver, virDomainCheckpointDefPtr *def, virJSONValuePtr *actions, virDomainMomentObjPtr *chk); + +int +qemuCheckpointCreateFinalize(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virQEMUDriverConfigPtr cfg, + virDomainMomentObjPtr chk, + bool update_current);