Refuse to restore a non-running state from snapshot while there is saved memory state in order to avoid filesystem corruption. Present a message to the user to that effect and let them choose to either abort the operation or drop the saved state before restoring the snapshot. Signed-off-by: Michael Weiser <michael.weiser@xxxxxx> Suggested-by: Cole Robinson <crobinso@xxxxxxxxxx> --- virtManager/details/snapshots.py | 14 ++++++++++++++ virtManager/object/domain.py | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/virtManager/details/snapshots.py b/virtManager/details/snapshots.py index 65d014a5..bc5b915a 100644 --- a/virtManager/details/snapshots.py +++ b/virtManager/details/snapshots.py @@ -656,6 +656,20 @@ class vmmSnapshotPage(vmmGObjectUI): if not result: return + if self.vm.has_managed_save() and not snap.has_run_state(): + result = self.err.ok_cancel( + _("Saved state will be removed to avoid filesystem corruption"), + _("Snapshot '%s' contains only disk and no memory state. " + "Restoring the snapshot would leave the existing saved state " + "in place, effectively switching a disk underneath a running " + "system. Running the domain afterwards would likely result in " + "extensive filesystem corruption. Therefore the saved state " + "will be removed before restoring the snapshot." + ) % snap.get_name()) + if not result: + return + self.vm.remove_saved_image() + log.debug("Running snapshot '%s'", snap.get_name()) vmmAsyncJob.simple_async(self.vm.revert_to_snapshot, [snap], self, diff --git a/virtManager/object/domain.py b/virtManager/object/domain.py index bad7108e..7fa85d32 100644 --- a/virtManager/object/domain.py +++ b/virtManager/object/domain.py @@ -161,6 +161,12 @@ class vmmDomainSnapshot(vmmLibvirtObject): Captured state is a running domain. """ return self._state_str_to_int() in [libvirt.VIR_DOMAIN_RUNNING] + def has_run_state(self): + """ + Captured state contains run state in addition to disk state. + """ + return self._state_str_to_int() in [libvirt.VIR_DOMAIN_RUNNING, + libvirt.VIR_DOMAIN_PAUSED] def is_current(self): return self._backend.isCurrent() -- 2.24.1 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list