An upcoming commit will add support for creating a disks-only snapshot using internal disk snapshots. Deleting or reverting to these will not be supported, at least not for now. This commit adds a validation for this. Signed-off-by: Or Ozeri <oro@xxxxxxxxxx> --- src/conf/snapshot_conf.c | 29 +++++++++++++++++++++++++++++ src/conf/snapshot_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_snapshot.c | 12 ++++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 58a6afa26d..879fe4c7a1 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -945,6 +945,35 @@ virDomainSnapshotIsExternal(virDomainMomentObj *snap) return virDomainSnapshotDefIsExternal(def); } +bool +virDomainSnapshotDefIsNonFullInternal(virDomainSnapshotDef *def) +{ + bool has_internal = false; + bool is_full = true; + size_t i; + + for (i = 0; i < def->ndisks; i++) { + if (def->disks[i].snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL) { + has_internal = true; + } else { + is_full = false; + } + } + + if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL) + return !is_full; + + return has_internal; +} + +bool +virDomainSnapshotIsNonFullInternal(virDomainMomentObj *snap) +{ + virDomainSnapshotDef *def = virDomainSnapshotObjGetDef(snap); + + return virDomainSnapshotDefIsNonFullInternal(def); +} + int virDomainSnapshotRedefinePrep(virDomainObj *vm, virDomainSnapshotDef *snapdef, diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index c133c105c7..8f40748602 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -125,6 +125,9 @@ int virDomainSnapshotAlignDisks(virDomainSnapshotDef *snapshot, bool virDomainSnapshotDefIsExternal(virDomainSnapshotDef *def); bool virDomainSnapshotIsExternal(virDomainMomentObj *snap); +bool virDomainSnapshotDefIsNonFullInternal(virDomainSnapshotDef *def); +bool virDomainSnapshotIsNonFullInternal(virDomainMomentObj *snap); + int virDomainSnapshotRedefinePrep(virDomainObj *vm, virDomainSnapshotDef *snapdef, virDomainMomentObj **snap, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 576ec8f95f..0d38e86936 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1027,6 +1027,7 @@ virDomainSnapshotDiskDefFree; virDomainSnapshotDiskDefParseXML; virDomainSnapshotFormatConvertXMLFlags; virDomainSnapshotIsExternal; +virDomainSnapshotIsNonFullInternal; virDomainSnapshotRedefinePrep; virDomainSnapshotStateTypeFromString; virDomainSnapshotStateTypeToString; diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1aa2f05300..c1855b3028 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1828,6 +1828,12 @@ qemuSnapshotRevertValidate(virDomainObj *vm, return -1; } + if (virDomainSnapshotIsNonFullInternal(snap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("revert to a non-full internal snapshot not supported yet")); + return -1; + } + if (!snap->def->dom) { virReportError(VIR_ERR_SNAPSHOT_REVERT_RISKY, _("snapshot '%s' lacks domain '%s' rollback info"), @@ -3061,6 +3067,12 @@ qemuSnapshotDeleteValidate(virDomainObj *vm, virDomainMomentObj *snap, unsigned int flags) { + if (virDomainSnapshotIsNonFullInternal(snap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of a non-full internal snapshot not supported yet")); + return -1; + } + if (!virDomainSnapshotIsExternal(snap) && virDomainObjIsActive(vm)) { ssize_t i; -- 2.25.1