[PATCH 1/2] Properly revert changes when cancelling Partition destruction
David Lehman
dlehman at redhat.com
Mon Sep 15 18:02:18 UTC 2014
On 09/11/2014 09:09 AM, Vratislav Podzimek wrote:
> When a partition is scheduled to be destroyed, the action removes it's device
> from the devicetree and from its parent's format. While the former change is
> reverted in the devicetree's action cancelling, the latter one is ignored and
> needs this fix.
I think I fixed the same problem here with my patch adding add/remove
hooks to device classes. I also changed ActionDestroyFormat and
ActionCreateFormat to save a deep copy of the format instead of just
saving a reference to the same instance. I'm not totally certain, but I
think my patches will provide a more general solution to this problem.
David
>
> Related: rhbz#1085201
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
> blivet/deviceaction.py | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
> index db4c7a7..fb11f8e 100644
> --- a/blivet/deviceaction.py
> +++ b/blivet/deviceaction.py
> @@ -336,6 +336,14 @@ class ActionDestroyDevice(DeviceAction):
> def __init__(self, device):
> # XXX should we insist that device.fs be None?
> DeviceAction.__init__(self, device)
> + self._origPartition = None
> + self._origDiskFormat = None
> +
> + if isinstance(device, PartitionDevice) and device.disk is not None:
> + # removing partition, save it and its format in case we have to
> + # revert changes when canceling this action
> + self._origPartition = device.partedPartition
> + self._origDiskFormat = device.disk.format
>
> def execute(self):
> super(ActionDestroyDevice, self).execute()
> @@ -349,6 +357,13 @@ class ActionDestroyDevice(DeviceAction):
> except Exception: # pylint: disable=broad-except
> log_exception_info(fmt_str="failed to remove info for device %s from libparted cache", fmt_args=[self.device])
>
> + def cancel(self):
> + super(ActionDestroyDevice, self).cancel()
> +
> + # canceling partition removal, add the partition back to its disk format
> + if self._origDiskFormat and self._origPartition:
> + self._origDiskFormat.addPartition(self._origPartition)
> +
> def requires(self, action):
> """ Return True if self requires action.
>
>
More information about the anaconda-patches
mailing list