qemu: checkpoint: split out checkpoint deletion bitmaps

qemuCheckpointDiscard is a massive function that can be separated into
smaller bits. Extract the part that actually modifies the disk from the
metadata handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2020-01-07 15:15:38 +01:00
parent 606dc66b09
commit 44e1b85717

View File

@ -105,41 +105,24 @@ qemuCheckpointWriteMetadata(virDomainObjPtr vm,
static int static int
qemuCheckpointDiscard(virQEMUDriverPtr driver, qemuCheckpointDiscardBitmaps(virDomainObjPtr vm,
virDomainObjPtr vm, virDomainCheckpointDefPtr chkdef,
virDomainMomentObjPtr chk, bool chkcurrent,
bool update_parent, virDomainMomentObjPtr parent)
bool metadata_only)
{ {
virDomainMomentObjPtr parent = NULL; qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverPtr driver = priv->driver;
virDomainMomentObjPtr moment; virDomainMomentObjPtr moment;
virDomainCheckpointDefPtr parentdef = NULL; virDomainCheckpointDefPtr parentdef = NULL;
size_t i, j;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autofree char *chkFile = NULL;
bool chkcurrent = chk == virDomainCheckpointGetCurrent(vm->checkpoints);
if (!metadata_only && !virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot remove checkpoint from inactive domain"));
return -1;
}
chkFile = g_strdup_printf("%s/%s/%s.xml", cfg->checkpointDir, vm->def->name,
chk->def->name);
if (!metadata_only) {
qemuDomainObjPrivatePtr priv = vm->privateData;
bool search_parents; bool search_parents;
virDomainCheckpointDefPtr chkdef = virDomainCheckpointObjGetDef(chk);
int rc; int rc;
g_autoptr(virJSONValue) actions = NULL; g_autoptr(virJSONValue) actions = NULL;
size_t i;
size_t j;
if (!(actions = virJSONValueNewArray())) if (!(actions = virJSONValueNewArray()))
return -1; return -1;
parent = virDomainCheckpointFindByName(vm->checkpoints,
chk->def->parent_name);
for (i = 0; i < chkdef->ndisks; i++) { for (i = 0; i < chkdef->ndisks; i++) {
virDomainCheckpointDiskDef *disk = &chkdef->disks[i]; virDomainCheckpointDiskDef *disk = &chkdef->disks[i];
const char *node; const char *node;
@ -191,6 +174,38 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver,
rc = qemuMonitorTransaction(priv->mon, &actions); rc = qemuMonitorTransaction(priv->mon, &actions);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
return -1; return -1;
return 0;
}
static int
qemuCheckpointDiscard(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMomentObjPtr chk,
bool update_parent,
bool metadata_only)
{
virDomainMomentObjPtr parent = NULL;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autofree char *chkFile = NULL;
bool chkcurrent = chk == virDomainCheckpointGetCurrent(vm->checkpoints);
if (!metadata_only && !virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot remove checkpoint from inactive domain"));
return -1;
}
chkFile = g_strdup_printf("%s/%s/%s.xml", cfg->checkpointDir, vm->def->name,
chk->def->name);
if (!metadata_only) {
virDomainCheckpointDefPtr chkdef = virDomainCheckpointObjGetDef(chk);
parent = virDomainCheckpointFindByName(vm->checkpoints,
chk->def->parent_name);
if (qemuCheckpointDiscardBitmaps(vm, chkdef, chkcurrent, parent) < 0)
return -1;
} }
if (chkcurrent) { if (chkcurrent) {