From: Jiri Konecny <jkonecny(a)redhat.com>
Add 3 new class methods:
1) addMetadataToUsableSpace(cls, usable_size) - takes how much space we
need and returns this space + metadata of this FS.
2) hungriestFS(cls, fs_list) - Return FS from the list which takes most
of the space by metadata. Input list is useful to filter only the
required FSs.
3) hungriestFSFromAll(cls) - Same as hungriestFS but with all
filesystems in the blivet.
---
blivet/formats/fs.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 955a613..cf2b986 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -179,12 +179,64 @@ def freeSpaceEstimate(cls, device_size):
with size ``device_size``.
This is more guess then precise number.
+ .. note::
+
+ This is more guess then precise number. To get precise
+ space taken the FS must provide this number to us.
+
:param device_size: original device size
- :type device_size: ``Size`` object
+ :type device_size: :class:`~.size.Size` object
:return: estimated free size after format
+ :rtype: :class:`~.size.Size`
"""
return device_size * cls._MetadataSizeFactor
+ @classmethod
+ def deviceSizeWithUsableSpace(cls, usable_size):
+ """ Get device size we need to get ``usable_size`` on the device.
+ This calculation will add metadata to usable device on the FS.
+
+ .. note::
+
+ This is more guess then precise number. To get precise
+ space taken the FS must provide this number to us.
+
+ :param usable_size: how much usable size we want on newly created device
+ :type usable_size: :class:`~.size.Size` object
+ :return: estimated size of the device which will have given amount of
+ ``usable_size``
+ :rtype: :class:`~.size.Size`
+ """
+ # to get usable size without metadata we will use
+ # usable_size = device_size * _MetadataSizeFactor
+ # we can change this to get device size with required usable_size
+ # device_size = usable_size / _MetadataSizeFactor
+ return Size(Decimal(usable_size) / Decimal(cls._MetadataSizeFactor))
+
+ @classmethod
+ def hungriestFS(cls, fs_list):
+ """ Get format class from list of format classes with largest
space taken
+ by metadata.
+
+ :param fs_list: list of input filesystems
+ :type fs_list: list of classes with parent :class:`~.FS`
+ :return: FS which takes most space by metadata
+ """
+ for fs_class in fs_list:
+ if not issubclass(fs_class, FS):
+ raise ValueError("You can provide only Filesystem classes!")
+
+ return min(fs_list, key=lambda x: x._MetadataSizeFactor)
+
+ @classmethod
+ def hungriestFSFromAll(cls):
+ """ Get format class from all format classes with largets space
taken
+ by metadata.
+
+ :return: FS which takes most space by metadata
+ """
+ return cls.mostHungryFS(cls.__subclasses__())
+
def labeling(self):
"""Returns True if this filesystem uses labels, otherwise False.
@@ -747,6 +799,7 @@ def mount(self, **kwargs):
:raises: FSError
.. note::
+
When mounted multiple times the unmount method needs to be called with
a specific mountpoint to unmount, otherwise it will try to unmount the most
recent one listed by the system.
--
To view this commit on github, visit
https://github.com/rhinstaller/blivet/commit/0c69bd5c0ee782f37c3282789385...