[PATCH 3/5] Correctly handle toggle of encryption state for devices. (#873445)

David Lehman dlehman at redhat.com
Tue Nov 6 17:23:01 UTC 2012


Don't even allow toggling of encryption for existing devices that have
their encryption applied at some lower level (eg: what our autopart
produces).

If the encryption is applied to container members (lvm, btrfs), let
Storage.setContainerMembers handle the changes. If toggling encryption
for an existing device or for any device for which we apply encryption
to the leaves (md, partition), handle the change of state directly in
_save_right_side.
---
 pyanaconda/ui/gui/spokes/custom.py |   70 ++++++++++++++++++++++--------------
 1 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 6f00864..d4bb0a4 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -965,6 +965,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         if encryption_checkbox.get_sensitive():
             encrypted = encryption_checkbox.get_active()
 
+        changed_encryption = (prev_encrypted != encrypted)
         log.debug("new encryption setting: %s" % encrypted)
 
         label_entry = self.builder.get_object("labelEntry")
@@ -1160,7 +1161,9 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         ##
         # new size means resize for existing devices and adjust for new ones
         changed_size = (int(size) != int(device.size))
-        if changed_size or changed_disk_set:
+        if changed_size or changed_disk_set or \
+           (changed_encryption and factory.encrypt_members and
+            not device.exists):
             self.clear_errors()
             old_size = device.size
             if changed_size and device.exists and device.resizable:
@@ -1190,6 +1193,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                         self.__storage.newDevice(device_type, size,
                                                  device=device,
                                                  disks=self._device_disks[:],
+                                                 encrypted=encrypted,
                                                  raid_level=raid_level)
                     except ErrorRecoveryFailure as e:
                         self._error = e
@@ -1221,34 +1225,39 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             ##
             ## ENCRYPTION
             ##
+
+            # for existing devices, we always encrypt the leaf
             old_fs_type = device.format.type
             old_device = device
-            if prev_encrypted and not encrypted:
-                log.info("removing encryption from %s" % device.name)
-                with ui_storage_logger():
-                    self.__storage.destroyDevice(device)
-                    self._devices.remove(device)
-                    old_device = device
-                    device = device.slave
-                    selector._device = device
-                    for s in self._accordion.allSelectors:
-                        if s._device == old_device:
-                            s._device = device
-            elif encrypted and not prev_encrypted:
-                log.info("applying encryption to %s" % device.name)
-                with ui_storage_logger():
-                    old_device = device
-                    new_fmt = getFormat("luks", device=device.path)
-                    self.__storage.formatDevice(device, new_fmt)
-                    luks_dev = LUKSDevice("luks-" + device.name,
-                                          parents=[device])
-                    self.__storage.createDevice(luks_dev)
-                    self._devices.append(luks_dev)
-                    device = luks_dev
-                    selector._device = device
-                    for s in self._accordion.allSelectors:
-                        if s._device == old_device:
-                            s._device = device
+
+            # if the encryption is on member devices it was handled above
+            if device.exists or factory.encrypt_leaves:
+                if prev_encrypted and not encrypted:
+                    log.info("removing encryption from %s" % device.name)
+                    with ui_storage_logger():
+                        self.__storage.destroyDevice(device)
+                        self._devices.remove(device)
+                        old_device = device
+                        device = device.slave
+                        selector._device = device
+                        for s in self._accordion.allSelectors:
+                            if s._device == old_device:
+                                s._device = device
+                elif encrypted and not prev_encrypted:
+                    log.info("applying encryption to %s" % device.name)
+                    with ui_storage_logger():
+                        old_device = device
+                        new_fmt = getFormat("luks", device=device.path)
+                        self.__storage.formatDevice(device, new_fmt)
+                        luks_dev = LUKSDevice("luks-" + device.name,
+                                              parents=[device])
+                        self.__storage.createDevice(luks_dev)
+                        self._devices.append(luks_dev)
+                        device = luks_dev
+                        selector._device = device
+                        for s in self._accordion.allSelectors:
+                            if s._device == old_device:
+                                s._device = device
 
             ##
             ## FORMATTING
@@ -1298,9 +1307,11 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                             new_selector.props.mountpoint = mountpoint or ""
                             new_selector.props.name = (self._mountpointName(mountpoint)
                                                        or device.format.name)
+                            new_selector._device = device
                         else:
                             self.add_new_selector(device)
 
+                self._populate_right_side(selector)
                 return
 
         ##
@@ -1546,8 +1557,13 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
 
         reformatCheckbox.set_active(not device.format.exists)
         reformatCheckbox.set_sensitive(use_dev.exists)
+
         encryptCheckbox.set_active(device.encrypted)
         encryptCheckbox.set_sensitive(reformatCheckbox.get_active())
+        if device.encrypted and device.exists:
+            # For existing devices, the encryption checkbutton should not be
+            # sensitive if the encryption is below the leaf layer.
+            encryptCheckbox.set_sensitive(use_dev.format.type == "luks")
 
         ##
         ## Set up the filesystem type combo.
-- 
1.7.7.6



More information about the anaconda-patches mailing list