Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow creating stratis pools with different sector sizes #1222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blivet/devices/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _add_parent(self, parent):
else:
msg = "Disk %s cannot be added to this volume group. LVM doesn't " \
"allow using physical volumes with inconsistent (logical) sector sizes." % parent.name
raise errors.InconsistentPVSectorSize(msg)
raise errors.InconsistentParentSectorSize(msg)

if (self.exists and parent.format.exists and
len(self.parents) + 1 == self.pv_count):
Expand Down
20 changes: 19 additions & 1 deletion blivet/devices/stratis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import logging
log = logging.getLogger("blivet")

from collections import defaultdict

from .storage import StorageDevice
from ..static_data import stratis_info
from ..storage_log import log_method_call
from ..errors import DeviceError, StratisError
from ..errors import DeviceError, StratisError, InconsistentParentSectorSize
from ..size import Size
from ..tasks import availability
from .. import devicelibs
Expand Down Expand Up @@ -166,6 +168,22 @@ def _post_create(self):
parent.format.pool_name = self.name
parent.format.pool_uuid = self.uuid

def _add_parent(self, parent):
super(StratisPoolDevice, self)._add_parent(parent)

# we are creating new pool
if not self.exists:
sector_sizes = defaultdict(list)
for ss, name in [(p.sector_size, p.name) for p in self.blockdevs + [parent]]: # pylint: disable=no-member
sector_sizes[ss].append(name)
if len(sector_sizes.keys()) != 1:
msg = "Cannot create pool '%s'. "\
"The following disks have inconsistent sector size:\n" % self.name
for sector_size in sector_sizes.keys():
msg += "%s: %d\n" % (", ".join(sector_sizes[sector_size]), sector_size)

raise InconsistentParentSectorSize(msg)

def _destroy(self):
""" Destroy the device. """
log_method_call(self, self.name, status=self.status)
Expand Down
4 changes: 4 additions & 0 deletions blivet/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class DeviceUserDeniedFormatError(DeviceError):
class InconsistentPVSectorSize(DeviceError, ValueError):
pass


class InconsistentParentSectorSize(InconsistentPVSectorSize, DeviceError, ValueError):
pass

# DeviceFormat


Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/devices_test/lvm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def test_lvm_inconsistent_sector_size(self):

with patch("blivet.devices.StorageDevice.sector_size", new_callable=PropertyMock) as mock_property:
mock_property.__get__ = lambda _mock, pv, _class: 512 if pv.name == "pv1" else 4096
with self.assertRaisesRegex(ValueError, "Cannot create volume group"):
with self.assertRaisesRegex(errors.InconsistentParentSectorSize, "Cannot create volume group"):
LVMVolumeGroupDevice("testvg", parents=[pv, pv2])

def test_skip_activate(self):
Expand Down
15 changes: 13 additions & 2 deletions tests/unit_tests/devices_test/stratis_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import unittest
from unittest.mock import patch
from unittest.mock import patch, PropertyMock

import blivet

from blivet.devices import StorageDevice
from blivet.devices import StratisPoolDevice
from blivet.devices import StratisFilesystemDevice
from blivet.errors import StratisError
from blivet.errors import StratisError, InconsistentParentSectorSize
from blivet.size import Size


Expand Down Expand Up @@ -159,3 +159,14 @@ def test_device_id(self):

fs = StratisFilesystemDevice("testfs", parents=[pool], size=Size("1 GiB"))
self.assertEqual(fs.device_id, "STRATIS-testpool/testfs")

def test_pool_inconsistent_sector_size(self):
bd = StorageDevice("bd1", fmt=blivet.formats.get_format("stratis"),
size=Size("2 GiB"), exists=False)
bd2 = StorageDevice("bd2", fmt=blivet.formats.get_format("stratis"),
size=Size("2 GiB"), exists=False)

with patch("blivet.devices.StorageDevice.sector_size", new_callable=PropertyMock) as mock_property:
mock_property.__get__ = lambda _mock, bd, _class: 512 if bd.name == "bd1" else 4096
with self.assertRaisesRegex(InconsistentParentSectorSize, "Cannot create pool"):
StratisPoolDevice("testpool", parents=[bd, bd2])
Loading