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

Stratis support v2 #952

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1ff7146
safe_dbus: Add function to get all properties for an interface
vojtechtrefny Dec 8, 2020
a94e180
Ignore all "private" devices during populate
vojtechtrefny Dec 8, 2020
3a9c437
Add basic support for Stratis devices
vojtechtrefny Dec 8, 2020
30f14fd
Add support for removing Stratis devices using DBus API
vojtechtrefny Dec 8, 2020
44c4798
Add dracut setup args for Stratis devices
vojtechtrefny Jan 14, 2021
4cb3903
Avoid circular depency when in static_data/stratis_info.py
vojtechtrefny Jan 28, 2021
8bbe581
Add a special "XFS Stratis" filesystem for Stratis filesystem devices
vojtechtrefny Feb 8, 2021
bfefdd1
Add basic support for creating Stratis devices
vojtechtrefny Jan 28, 2021
d18d85f
Add simple test case for Stratis
vojtechtrefny Jan 28, 2021
82ae46d
Add Stratis example
vojtechtrefny Jan 28, 2021
418e29f
Mark format on Stratis pool devices as immutable
vojtechtrefny Feb 12, 2021
5e3ea0c
Add Stratis device factory
vojtechtrefny Feb 12, 2021
d6dae9a
Add support for creating encrypted Stratis pools
vojtechtrefny Feb 17, 2021
b001fb8
Add support for working with locked Stratis pools
vojtechtrefny Apr 1, 2021
882dfef
Add support for creating encrypted Stratis devices with DeviceFactory
vojtechtrefny Apr 7, 2021
d4ba563
Add more tests for creating Stratis devices
vojtechtrefny Apr 7, 2021
f174cc6
Set the StratisBlockdev format status based on whether it has a pool or
vojtechtrefny Apr 8, 2021
fda1750
Set pool info on the block devices when adding/removing Stratis pool
vojtechtrefny Apr 8, 2021
cc17684
Add property with list of Stratis block devices to StratisPoolDevice
vojtechtrefny Apr 8, 2021
07c8b01
Hide the private LUKS device for unlockded Stratis pools
vojtechtrefny Apr 23, 2021
017d83b
Add Stratis devices and formats to the public API documentation
vojtechtrefny May 3, 2021
6c3958c
Add MountClass for StratisXFS filesystem
vojtechtrefny May 12, 2021
6dc9b6b
Add fstab options for Stratis Filesystem devices
vojtechtrefny May 14, 2021
f3bbdd7
Fix/unify importing mock module in stratis tests
vojtechtrefny Sep 1, 2021
3b64205
Fix parameters differ from overridden in StratisPoolDevice
vojtechtrefny Sep 1, 2021
4a0ed7b
Add stratis filesystem metadata size and pool free space
vojtechtrefny Sep 2, 2021
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
114 changes: 106 additions & 8 deletions blivet/blivet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from .devices import BTRFSSubVolumeDevice, BTRFSVolumeDevice
from .devices import LVMLogicalVolumeDevice, LVMVolumeGroupDevice
from .devices import MDRaidArrayDevice, PartitionDevice, TmpFSDevice, device_path_to_name
from .devices import StratisPoolDevice, StratisFilesystemDevice
from .deviceaction import ActionCreateDevice, ActionCreateFormat, ActionDestroyDevice
from .deviceaction import ActionDestroyFormat, ActionResizeDevice, ActionResizeFormat
from .devicelibs.edd import get_edd_dict
Expand Down Expand Up @@ -313,6 +314,17 @@ def btrfs_volumes(self):
return sorted((d for d in self.devices if d.type == "btrfs volume"),
key=lambda d: d.name)

@property
def stratis_pools(self):
""" A list of the Stratis pools in the device tree.

This is based on the current state of the device tree and
does not necessarily reflect the actual on-disk state of the
system's disks.
"""
return sorted((d for d in self.devices if d.type == "stratis pool"),
key=lambda d: d.name)

@property
def swaps(self):
""" A list of the swap devices in the device tree.
Expand Down Expand Up @@ -770,6 +782,77 @@ def new_btrfs_sub_volume(self, *args, **kwargs):
kwargs["subvol"] = True
return self.new_btrfs(*args, **kwargs)

def new_stratis_pool(self, *args, **kwargs):
""" Return a new StratisPoolDevice instance.

:returns: the new Stratis pool device
:rtype: :class:`~.devices.StratisPoolDevice`

All arguments are passed on to the
:class:`~.devices.StratisPoolDevice` constructor.

If a name is not specified, one will be generated based on the
hostname, and/or product name.
"""
blockdevs = kwargs.pop("parents", [])

name = kwargs.pop("name", None)
if name:
safe_name = self.safe_device_name(name, devicefactory.DEVICE_TYPE_STRATIS)
if safe_name != name:
log.warning("using '%s' instead of specified name '%s'",
safe_name, name)
name = safe_name
else:
name = self.suggest_container_name(container_type=devicefactory.DEVICE_TYPE_STRATIS)

if name in self.names:
raise ValueError("name '%s' is already in use" % name)

return StratisPoolDevice(name, parents=blockdevs, *args, **kwargs)

def new_stratis_filesystem(self, *args, **kwargs):
""" Return a new StratisFilesystemDevice instance.

:keyword mountpoint: mountpoint for filesystem
:type mountpoint: str
:returns: the new device
:rtype: :class:`~.devices.StratisFilesystemDevice`

All other arguments are passed on to the appropriate
:class:`~.devices.StratisFilesystemDevice` constructor.

If a name is not specified, one will be generated based on the
format type and/or mountpoint.
"""
pool = kwargs.get("parents", [None])[0]
dwlehman marked this conversation as resolved.
Show resolved Hide resolved

mountpoint = kwargs.pop("mountpoint", None)
name = kwargs.pop("name", None)
if name:
# make sure the specified name is sensible
full_name = "%s/%s" % (pool.name, name)
safe_name = self.safe_device_name(full_name, devicefactory.DEVICE_TYPE_STRATIS)
if safe_name != full_name:
new_name = safe_name[len(pool.name) + 1:]
log.warning("using '%s' instead of specified name '%s'",
new_name, name)
name = new_name
else:
name = self.suggest_device_name(parent=pool,
mountpoint=mountpoint,
device_type=devicefactory.DEVICE_TYPE_STRATIS)

if "%s/%s" % (pool.name, name) in self.names:
raise ValueError("name '%s' is already in use" % name)

device = StratisFilesystemDevice(name, *args, **kwargs)

# XFS will be created automatically on the device so lets just add it here
device.format = get_format("stratis xfs", mountpoint=mountpoint)

return device

def new_tmp_fs(self, *args, **kwargs):
""" Return a new TmpFSDevice. """
return TmpFSDevice(*args, **kwargs)
Expand Down Expand Up @@ -917,6 +1000,8 @@ def safe_device_name(self, name, device_type=None):
allowed = devicelibs.mdraid.safe_name_characters
elif device_type == devicefactory.DEVICE_TYPE_BTRFS:
allowed = devicelibs.btrfs.safe_name_characters
elif device_type == devicefactory.DEVICE_TYPE_STRATIS:
allowed = devicelibs.stratis.safe_name_characters
else:
allowed = "0-9a-zA-Z._-"

Expand All @@ -940,17 +1025,23 @@ def safe_device_name(self, name, device_type=None):

return tmp

def unique_device_name(self, name, parent=None, name_set=True):
def unique_device_name(self, name, parent=None, name_set=True, device_type=None):
""" Turn given name into a unique one by adding numeric suffix to it """

if device_type == devicefactory.DEVICE_TYPE_STRATIS:
parent_separator = "/"
else:
parent_separator = "-"

if name_set:
if parent and "%s-%s" % (parent.name, name) not in self.names:
if parent and "%s%s%s" % (parent.name, parent_separator, name) not in self.names:
return name
elif not parent and name not in self.names:
return name

for suffix in range(100):
if parent:
if "%s-%s%02d" % (parent.name, name, suffix) not in self.names:
if "%s%s%s%02d" % (parent.name, parent_separator, name, suffix) not in self.names:
return "%s%02d" % (name, suffix)
else:
if "%s%02d" % (name, suffix) not in self.names:
Expand All @@ -974,15 +1065,16 @@ def suggest_container_name(self, prefix="", container_type=None):
name = self._get_container_name_template(prefix=prefix)
if name in self.names:
try:
name = self.unique_device_name(name)
name = self.unique_device_name(name, device_type=container_type)
except RuntimeError:
log.error("failed to create device name based on template '%s'", name)
raise

return name

def suggest_device_name(self, parent=None, swap=None,
mountpoint=None, prefix=""):
mountpoint=None, prefix="",
device_type=None):
""" Return a suitable, unused name for a new device.

:keyword parent: the parent device
Expand All @@ -1008,12 +1100,18 @@ def suggest_device_name(self, parent=None, swap=None,
if prefix and body:
body = "_" + body

name = self.safe_device_name(prefix + body)
full_name = "%s-%s" % (parent.name, name) if parent else name
name = self.safe_device_name(prefix + body, device_type)

if device_type == devicefactory.DEVICE_TYPE_STRATIS:
parent_separator = "/"
else:
parent_separator = "-"

full_name = "%s%s%s" % (parent.name, parent_separator, name) if parent else name

if full_name in self.names or not body:
try:
name = self.unique_device_name(name, parent, bool(body))
name = self.unique_device_name(name, parent, bool(body), device_type)
except RuntimeError:
log.error("failed to create device name based on parent '%s', "
"prefix '%s', mountpoint '%s', swap '%s'",
Expand Down
Loading