@@ -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))
Yeah you doing it the same way how I did it in start and why I can't finish my
computation right. For true this solution was find by vtrefny not me :) .
The problem is this:
``10 GiB * (1 - 0.8) = 2 GiB``
when you try to get usable size:
``(10 GiB + 2 GiB) * 0.8 = 9.6 GiB``
So you don't get same value as:
``10 GiB / 0.8 = 12.5 GiB``
which is equal to usable size we want
``12.5 GiB * 0.8 = 10 GiB``
And for the returning only metadata, I see no problem with it but it seems to me the same.
You only do ``result - usable_size`` and this can be done by a caller of this method if
he/she wants to. This seems more logical to me but as I said no problem to change it.
--
To view this pull request on github, visit
https://github.com/rhinstaller/blivet/pull/265#discussion_r43479660