neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone
8b6c54
From 2aba050e74dc5df483da022dcf436b101c7a4301 Mon Sep 17 00:00:00 2001
8b6c54
From: Vojtech Trefny <vtrefny@redhat.com>
8b6c54
Date: Wed, 11 Jan 2023 14:59:24 +0100
8b6c54
Subject: [PATCH] Default to encryption sector size 512 for LUKS devices
8b6c54
8b6c54
We are currently letting cryptsetup decide the optimal encryption
8b6c54
sector size for LUKS. The problem is that for disks with physical
8b6c54
sector size 4096 cryptsetup will default to 4096 encryption sector
8b6c54
size even if the drive logical sector size is 512 which means
8b6c54
these disks cannot be combined with other 512 logical sector size
8b6c54
disks in LVM. This requires a more sophisticated solution in the
8b6c54
future, but for now just default to 512 if not specified by the
8b6c54
user otherwise.
8b6c54
8b6c54
Resolves: rhbz#2103800
8b6c54
---
8b6c54
 blivet/formats/luks.py                      | 10 +++++++---
8b6c54
 tests/unit_tests/formats_tests/luks_test.py |  2 +-
8b6c54
 2 files changed, 8 insertions(+), 4 deletions(-)
8b6c54
8b6c54
diff --git a/blivet/formats/luks.py b/blivet/formats/luks.py
8b6c54
index 8de4911f..2637e0c5 100644
8b6c54
--- a/blivet/formats/luks.py
8b6c54
+++ b/blivet/formats/luks.py
8b6c54
@@ -166,9 +166,13 @@ class LUKS(DeviceFormat):
8b6c54
             if self.pbkdf_args.type == "pbkdf2" and self.pbkdf_args.max_memory_kb:
8b6c54
                 log.warning("Memory limit is not used for pbkdf2 and it will be ignored.")
8b6c54
 
8b6c54
-        self.luks_sector_size = kwargs.get("luks_sector_size") or 0
8b6c54
-        if self.luks_sector_size and self.luks_version != "luks2":
8b6c54
-            raise ValueError("Sector size argument is valid only for LUKS version 2.")
8b6c54
+        self.luks_sector_size = kwargs.get("luks_sector_size")
8b6c54
+        if self.luks_version == "luks2":
8b6c54
+            if self.luks_sector_size is None:
8b6c54
+                self.luks_sector_size = 512  # XXX we don't want cryptsetup choose automatically here so fallback to 512
8b6c54
+        else:
8b6c54
+            if self.luks_sector_size:
8b6c54
+                raise ValueError("Sector size argument is valid only for LUKS version 2.")
8b6c54
 
8b6c54
     def __repr__(self):
8b6c54
         s = DeviceFormat.__repr__(self)
8b6c54
diff --git a/tests/unit_tests/formats_tests/luks_test.py b/tests/unit_tests/formats_tests/luks_test.py
8b6c54
index 5ae6acfe..ec7b7592 100644
8b6c54
--- a/tests/unit_tests/formats_tests/luks_test.py
8b6c54
+++ b/tests/unit_tests/formats_tests/luks_test.py
8b6c54
@@ -53,7 +53,7 @@ class LUKSNodevTestCase(unittest.TestCase):
8b6c54
 
8b6c54
     def test_sector_size(self):
8b6c54
         fmt = LUKS()
8b6c54
-        self.assertEqual(fmt.luks_sector_size, 0)
8b6c54
+        self.assertEqual(fmt.luks_sector_size, 512)
8b6c54
 
8b6c54
         with self.assertRaises(ValueError):
8b6c54
             fmt = LUKS(luks_version="luks1", luks_sector_size=4096)
8b6c54
-- 
8b6c54
2.39.0
8b6c54