mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
qemu_snapshot: refactor qemuSnapshotDeleteExternalPrepare
When user creates external snapshot with making only memory snapshot without any disks deleting that snapshot failed without reporting any meaningful error. The issue is that the qemuSnapshotDeleteExternalPrepare function returns NULL because the returned list is empty. This will not change so to make it clear if the function fails or not return int instead and have another parameter where we can pass the list. With the fixed memory snapshot deletion it will now correctly delete memory only snapshot as well. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2170826 Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
356e227208
commit
e3957c2246
@ -2301,9 +2301,10 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj *snap,
|
||||
}
|
||||
|
||||
|
||||
static GSList*
|
||||
static int
|
||||
qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
virDomainMomentObj *snap)
|
||||
virDomainMomentObj *snap,
|
||||
GSList **externalData)
|
||||
{
|
||||
ssize_t i;
|
||||
virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
|
||||
@ -2320,7 +2321,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("snapshot disk '%s' was target of not completed snapshot delete"),
|
||||
snapDisk->name);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
data = g_new0(qemuSnapshotDeleteExternalData, 1);
|
||||
@ -2328,18 +2329,18 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
|
||||
data->domDisk = qemuDomainDiskByName(vm->def, snapDisk->name);
|
||||
if (!data->domDisk)
|
||||
return NULL;
|
||||
return -1;
|
||||
|
||||
data->diskSrc = virStorageSourceChainLookupBySource(data->domDisk->src,
|
||||
data->snapDisk->src,
|
||||
&data->prevDiskSrc);
|
||||
if (!data->diskSrc)
|
||||
return NULL;
|
||||
return -1;
|
||||
|
||||
if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapDisk->src)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("VM disk source and snapshot disk source are not the same"));
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
data->parentDomDisk = virDomainDiskByTarget(snapdef->parent.dom,
|
||||
@ -2348,7 +2349,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("failed to find disk '%s' in snapshot VM XML"),
|
||||
snapDisk->name);
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virDomainObjIsActive(vm)) {
|
||||
@ -2356,13 +2357,13 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
if (!virStorageSourceIsBacking(data->parentDiskSrc)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("failed to find parent disk source in backing chain"));
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!virStorageSourceIsSameLocation(data->parentDiskSrc, data->parentDomDisk->src)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
||||
_("snapshot VM disk source and parent disk source are not the same"));
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2371,15 +2372,16 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
|
||||
if (data->parentSnap && !virDomainSnapshotIsExternal(data->parentSnap)) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("deleting external snapshot that has internal snapshot as parent not supported"));
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = g_slist_prepend(ret, g_steal_pointer(&data));
|
||||
}
|
||||
|
||||
ret = g_slist_reverse(ret);
|
||||
*externalData = g_steal_pointer(&ret);
|
||||
|
||||
return g_steal_pointer(&ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3159,7 +3161,7 @@ qemuSnapshotDelete(virDomainObj *vm,
|
||||
g_autoslist(qemuSnapshotDeleteExternalData) tmpData = NULL;
|
||||
|
||||
/* this also serves as validation whether the snapshot can be deleted */
|
||||
if (!(tmpData = qemuSnapshotDeleteExternalPrepare(vm, snap)))
|
||||
if (qemuSnapshotDeleteExternalPrepare(vm, snap, &tmpData) < 0)
|
||||
goto endjob;
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
@ -3174,7 +3176,7 @@ qemuSnapshotDelete(virDomainObj *vm,
|
||||
|
||||
/* Call the prepare again as some data require that the VM is
|
||||
* running to get everything we need. */
|
||||
if (!(externalData = qemuSnapshotDeleteExternalPrepare(vm, snap)))
|
||||
if (qemuSnapshotDeleteExternalPrepare(vm, snap, &externalData) < 0)
|
||||
goto endjob;
|
||||
} else {
|
||||
qemuDomainJobPrivate *jobPriv = vm->job->privateData;
|
||||
|
Loading…
Reference in New Issue
Block a user