virDomainSnapshotAlignDisks: Allow alternate domain definition when redefining

Due to historical reasons we allow users to redefine an existing
snapshot without providing the domain definition which would correspond
to it. In such case we'd use the domain definition from the snapshot
that is being redefined.

To prevent callers from doing complex moving of the domain definition
object back and forth between the snapshot definitions we can add an
argument to virDomainSnapshotAlignDisks which will allow us to pass in
the alternate definition if the one from the snapshot is missing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-01-12 14:20:04 +01:00
parent 0b97d87a6d
commit ef3f3884a2
4 changed files with 15 additions and 4 deletions

View File

@ -535,7 +535,7 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDef *def,
if (external)
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
if (virDomainSnapshotAlignDisks(def, align_location, true) < 0)
if (virDomainSnapshotAlignDisks(def, NULL, align_location, true) < 0)
return -1;
}
@ -622,16 +622,22 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def)
/**
* virDomainSnapshotAlignDisks:
* @snapdef: Snapshot definition to align
* @existingDomainDef: definition of the domain belonging to a redefined snapshot
* @default_snapshot: snapshot location to assign to disks which don't have any
* @uniform_internal_snapshot: Require that for an internal snapshot all disks
* take part in the internal snapshot
*
* Align snapdef->disks to snapdef->parent.dom, filling in any missing disks or
* Align snapdef->disks to domain definition, filling in any missing disks or
* snapshot state defaults given by the domain, with a fallback to
* @default_snapshot. Ensure that there are no duplicate snapshot disk
* definitions in @snapdef and there are no disks described in @snapdef but
* missing from the domain definition.
*
* By default the domain definition from @snapdef->parent.dom is used, but when
* redefining an existing snapshot the domain definition may be omitted in
* @snapdef. In such case callers must pass in the definition from the snapsot
* being redefined as @existingDomainDef. In all other cases callers pass NULL.
*
* When @uniform_internal_snapshot is true and @default_snapshot is
* VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL, all disks in @snapdef must take part
* in the internal snapshot. This is for hypervisors where granularity of an
@ -643,6 +649,7 @@ virDomainSnapshotDefAssignExternalNames(virDomainSnapshotDef *def)
*/
int
virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapdef,
virDomainDef *existingDomainDef,
virDomainSnapshotLocation default_snapshot,
bool uniform_internal_snapshot)
{
@ -653,6 +660,9 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapdef,
size_t oldndisks;
size_t i;
if (!domdef)
domdef = existingDomainDef;
if (!domdef) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing domain in snapshot"));

View File

@ -126,6 +126,7 @@ char *virDomainSnapshotDefFormat(const char *uuidstr,
virDomainXMLOption *xmlopt,
unsigned int flags);
int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapshot,
virDomainDef *existingDomainDef,
virDomainSnapshotLocation default_snapshot,
bool uniform_internal_snapshot);

View File

@ -1675,7 +1675,7 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
VIR_DOMAIN_SNAPSHOT_LOCATION_NONE :
VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL);
}
if (virDomainSnapshotAlignDisks(def, align_location, true) < 0)
if (virDomainSnapshotAlignDisks(def, NULL, align_location, true) < 0)
return -1;
return 0;

View File

@ -8736,7 +8736,7 @@ testDomainSnapshotAlignDisks(virDomainObj *vm,
VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
}
return virDomainSnapshotAlignDisks(def, align_location, true);
return virDomainSnapshotAlignDisks(def, NULL, align_location, true);
}
static virDomainSnapshotPtr