From 11326d70b70d5c274e6cd492c8749627a734fa13 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Aug 02 2021 14:15:33 +0000 Subject: Do not set chunk size for RAID 1 Resolves: rhbz#1987176 --- diff --git a/0009-Do-not-set-chunk-size-for-RAID1.patch b/0009-Do-not-set-chunk-size-for-RAID1.patch new file mode 100644 index 0000000..2b40cfa --- /dev/null +++ b/0009-Do-not-set-chunk-size-for-RAID1.patch @@ -0,0 +1,151 @@ +From dc1e2fe7783748528cac2f7aa516c89d1959b052 Mon Sep 17 00:00:00 2001 +From: Vojtech Trefny +Date: Thu, 29 Jul 2021 14:44:22 +0200 +Subject: [PATCH] Do not set chunk size for RAID 1 + +Setting chunk size for RAID 1 doesn't make sense and latest +mdadm started returning error instead of ignoring the --chunk +option when creating an array. + +Resolves: rhbz#1987170 +--- + blivet/devicelibs/raid.py | 12 ++++++++++ + blivet/devices/md.py | 15 ++++++++++--- + tests/devices_test/md_test.py | 41 +++++++++++++++++++++++++++++++++-- + 3 files changed, 63 insertions(+), 5 deletions(-) + +diff --git a/blivet/devicelibs/raid.py b/blivet/devicelibs/raid.py +index 19c3fae98..a9e241c7a 100644 +--- a/blivet/devicelibs/raid.py ++++ b/blivet/devicelibs/raid.py +@@ -462,6 +462,18 @@ def _pad(self, size, chunk_size): + def _get_recommended_stride(self, member_count): + return None + ++ def get_size(self, member_sizes, num_members=None, chunk_size=None, superblock_size_func=None): ++ if not member_sizes: ++ return Size(0) ++ ++ if num_members is None: ++ num_members = len(member_sizes) ++ ++ min_size = min(member_sizes) ++ superblock_size = superblock_size_func(min_size) ++ min_data_size = self._trim(min_size - superblock_size, chunk_size) ++ return self.get_net_array_size(num_members, min_data_size) ++ + + RAID1 = RAID1() + ALL_LEVELS.add_raid_level(RAID1) +diff --git a/blivet/devices/md.py b/blivet/devices/md.py +index 69eee93a5..d1a2faf1f 100644 +--- a/blivet/devices/md.py ++++ b/blivet/devices/md.py +@@ -138,7 +138,7 @@ def __init__(self, name, level=None, major=None, minor=None, size=None, + if self.exists: + self._chunk_size = self.read_chunk_size() + else: +- self._chunk_size = chunk_size or mdraid.MD_CHUNK_SIZE ++ self.chunk_size = chunk_size or Size(0) + + if not self.exists and not isinstance(metadata_version, str): + self.metadata_version = "default" +@@ -208,8 +208,14 @@ def sector_size(self): + + @property + def chunk_size(self): +- if self.exists and self._chunk_size == Size(0): +- self._chunk_size = self.read_chunk_size() ++ if self._chunk_size == Size(0): ++ if self.exists: ++ return self.read_chunk_size() ++ else: ++ if self.level == raid.RAID1: ++ return self._chunk_size ++ else: ++ return mdraid.MD_CHUNK_SIZE + return self._chunk_size + + @chunk_size.setter +@@ -223,6 +229,9 @@ def chunk_size(self, newsize): + if self.exists: + raise ValueError("cannot set chunk size for an existing device") + ++ if self.level == raid.RAID1 and newsize != Size(0): ++ raise ValueError("specifying chunk size is not allowed for raid1") ++ + self._chunk_size = newsize + + def read_chunk_size(self): +diff --git a/tests/devices_test/md_test.py b/tests/devices_test/md_test.py +index 46df76d3d..47a0fa0cc 100644 +--- a/tests/devices_test/md_test.py ++++ b/tests/devices_test/md_test.py +@@ -1,6 +1,11 @@ + import six + import unittest + ++try: ++ from unittest.mock import patch ++except ImportError: ++ from mock import patch ++ + import blivet + + from blivet.devices import StorageDevice +@@ -27,9 +32,27 @@ def test_chunk_size1(self): + raid_array = MDRaidArrayDevice(name="raid", level="raid0", member_devices=2, + total_devices=2, parents=[member1, member2]) + +- # no chunk_size specified -- default value ++ # no chunk_size specified and RAID0 -- default value + self.assertEqual(raid_array.chunk_size, mdraid.MD_CHUNK_SIZE) + ++ with patch("blivet.devices.md.blockdev.md.create") as md_create: ++ raid_array._create() ++ md_create.assert_called_with("/dev/md/raid", "raid0", ["/dev/member1", "/dev/member2"], ++ 0, version="default", bitmap=False, ++ chunk_size=mdraid.MD_CHUNK_SIZE) ++ ++ raid_array = MDRaidArrayDevice(name="raid", level="raid1", member_devices=2, ++ total_devices=2, parents=[member1, member2]) ++ ++ # no chunk_size specified and RAID1 -- no chunk size set (0) ++ self.assertEqual(raid_array.chunk_size, Size(0)) ++ ++ with patch("blivet.devices.md.blockdev.md.create") as md_create: ++ raid_array._create() ++ md_create.assert_called_with("/dev/md/raid", "raid1", ["/dev/member1", "/dev/member2"], ++ 0, version="default", bitmap=True, ++ chunk_size=0) ++ + def test_chunk_size2(self): + + member1 = StorageDevice("member1", fmt=blivet.formats.get_format("mdmember"), +@@ -40,11 +63,25 @@ def test_chunk_size2(self): + raid_array = MDRaidArrayDevice(name="raid", level="raid0", member_devices=2, + total_devices=2, parents=[member1, member2], + chunk_size=Size("1024 KiB")) +- + self.assertEqual(raid_array.chunk_size, Size("1024 KiB")) + ++ # for raid0 setting chunk_size = 0 means "default" ++ raid_array.chunk_size = Size(0) ++ self.assertEqual(raid_array.chunk_size, mdraid.MD_CHUNK_SIZE) ++ + with six.assertRaisesRegex(self, ValueError, "new chunk size must be of type Size"): + raid_array.chunk_size = 1 + + with six.assertRaisesRegex(self, ValueError, "new chunk size must be multiple of 4 KiB"): + raid_array.chunk_size = Size("5 KiB") ++ ++ with six.assertRaisesRegex(self, ValueError, "specifying chunk size is not allowed for raid1"): ++ MDRaidArrayDevice(name="raid", level="raid1", member_devices=2, ++ total_devices=2, parents=[member1, member2], ++ chunk_size=Size("1024 KiB")) ++ ++ raid_array = MDRaidArrayDevice(name="raid", level="raid1", member_devices=2, ++ total_devices=2, parents=[member1, member2]) ++ ++ with six.assertRaisesRegex(self, ValueError, "specifying chunk size is not allowed for raid1"): ++ raid_array.chunk_size = Size("512 KiB") diff --git a/python-blivet.spec b/python-blivet.spec index 953bccf..ab3ba6e 100644 --- a/python-blivet.spec +++ b/python-blivet.spec @@ -23,7 +23,7 @@ Version: 3.4.0 #%%global prerelease .b2 # prerelease, if defined, should be something like .a1, .b1, .b2.dev1, or .c2 -Release: 3%{?prerelease}%{?dist} +Release: 4%{?prerelease}%{?dist} Epoch: 1 License: LGPLv2+ %global realname blivet @@ -38,6 +38,7 @@ Patch4: 0005-Fix-unify-importing-mock-module-in-tests.patch Patch5: 0006-Fix-util.virt_detect-on-Xen.patch Patch6: 0007-Fix-activating-old-style-LVM-snapshots.patch Patch7: 0008-Fix-resolving-devices-with-names-that-look-like-BIOS.patch +Patch8: 0009-Do-not-set-chunk-size-for-RAID1.patch # Versions of required components (done so we make sure the buildrequires # match the requires versions of things). @@ -200,6 +201,10 @@ configuration. %endif %changelog +* Mon Aug 2 2021 Vojtech Trefny - 3.4.0-4 +- Do not set chunk size for RAID 1 + Resolves: rhbz#1987176 + * Sat Jul 17 2021 Neal Gompa - 3.4.0-3 - Fix resolving devices with names that look like BIOS drive number Resolves: rhbz#1983310