Mostly the same as before except:
I ended up combining the revised version of Do not compare the same two values twice with Do not calculate Sizes unless they are needed.
I dropped: Add a new way of specifying Sizes(). Use tuples to construct Sizes() wherever units are known. since there is a better way of handling how we construct Sizes.
I dropped: Add _resizefsUnit to TmpFS and use in appropriate places and I'll be adding it to my other patches related to TmpFS in due course.
The only changed patch is: Use _resizefsUnit in resizeArgs() method implementations.
so that's the only one I'm sending.
mulhern (16): Get rid of unnecessary use of long. Make possiblePhysicalExtents() a bit more direct. Do not compare the same two values twice. Avoid using Size constant in FileDevice._create(). Eliminate redundant test. Comment _prefixTestHelper() and eliminate some redundancies. Hoist _BINARY_FACTOR * min_value calculation out of loop. Make _Prefix entries named constants. Add unitStr() method. Make _parseUnits() return a unit constant, rather than a number. Get whole unit tuple in loop when searching for correct units. Do not even pretend that ReiserFS is resizable. Change convertTo() and roundToNearest() so each takes a units specifier. Use convertTo in humanReadable(). Do not supply a default implementation for the resizeArgs() method. Use _resizefsUnit in resizeArgs() method implementations.
blivet/devicelibs/lvm.py | 29 ++++----- blivet/devicelibs/swap.py | 19 +++--- blivet/devices/file.py | 9 ++- blivet/devices/lvm.py | 16 ++--- blivet/devices/partition.py | 8 +-- blivet/formats/fs.py | 44 +++++++------ blivet/size.py | 130 +++++++++++++++++++------------------- tests/devicelibs_test/lvm_test.py | 5 -- tests/size_test.py | 92 ++++++++++++--------------- tests/storagetestcase.py | 4 +- 10 files changed, 173 insertions(+), 183 deletions(-)
The reason it is used elsewhere, i.e., when calculating minimum size is because of the constraint on the resizeArgs() method to use the units defined by _resizefsUnit. This patch makes that explicit.
The appropriate format string for the size specification for the particular resizing application and resizefsUnit combination is looked up dynamically during execution of resizeArgs(). Ideally, it would be calculated when the class is read, rather than at every invocation. However, due to the fact that the format string is a function of the class's resizefsUnit that is tricky. The only principled way to do it is to construct the class dynamically, passing the resizefsUnit value as an argument. This is definite overkill for this particular problem, so it seems better to accept this slightly wasteful dynamic calculation.
There is no try/except KeyError block surrounding the FMT calculations. Since the key is known statically and does not change between one invocation and the next, this would be overkill.
Signed-off-by: mulhern amulhern@redhat.com --- blivet/formats/fs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py index 17faf5b..ad2542a 100644 --- a/blivet/formats/fs.py +++ b/blivet/formats/fs.py @@ -35,7 +35,8 @@ from ..flags import flags from parted import fileSystemType from ..storage_log import log_exception_info, log_method_call from .. import arch -from ..size import Size, ROUND_UP, ROUND_DOWN, MiB, B, unitStr +from ..size import Size, ROUND_UP, ROUND_DOWN, unitStr +from ..size import B, KiB, MiB, GiB, KB, MB, GB from ..i18n import _, N_ from .. import udev
@@ -1030,8 +1031,10 @@ class Ext2FS(FS):
@property def resizeArgs(self): - argv = ["-p", self.device, "%dM" % (self.targetSize.convertTo(MiB))] - return argv + # No unit specifier is interpreted not as bytes, but block size. + FMT = {KiB: "%dK", MiB: "%dM", GiB: "%dG"}[self._resizefsUnit] + size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit) + return ["-p", self.device, size_spec]
register_device_format(Ext2FS)
@@ -1423,11 +1426,12 @@ class NTFS(FS):
@property def resizeArgs(self): + FMT = {B: "%d", KB: "%dK", MB: "%dM", GB: "%dG"}[self._resizefsUnit] + size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit) + # You must supply at least two '-f' options to ntfsresize or # the proceed question will be presented to you. - argv = ["-ff", "-s", "%d" % self.targetSize.convertTo(B), - self.device] - return argv + return ["-ff", "-s", size_spec, self.device]
register_device_format(NTFS)
On Thu, 2015-01-08 at 12:45 -0500, mulhern wrote:
The reason it is used elsewhere, i.e., when calculating minimum size is because of the constraint on the resizeArgs() method to use the units defined by _resizefsUnit. This patch makes that explicit.
The appropriate format string for the size specification for the particular resizing application and resizefsUnit combination is looked up dynamically during execution of resizeArgs(). Ideally, it would be calculated when the class is read, rather than at every invocation. However, due to the fact that the format string is a function of the class's resizefsUnit that is tricky. The only principled way to do it is to construct the class dynamically, passing the resizefsUnit value as an argument. This is definite overkill for this particular problem, so it seems better to accept this slightly wasteful dynamic calculation.
There is no try/except KeyError block surrounding the FMT calculations. Since the key is known statically and does not change between one invocation and the next, this would be overkill.
Signed-off-by: mulhern amulhern@redhat.com
blivet/formats/fs.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py index 17faf5b..ad2542a 100644 --- a/blivet/formats/fs.py +++ b/blivet/formats/fs.py @@ -35,7 +35,8 @@ from ..flags import flags from parted import fileSystemType from ..storage_log import log_exception_info, log_method_call from .. import arch -from ..size import Size, ROUND_UP, ROUND_DOWN, MiB, B, unitStr +from ..size import Size, ROUND_UP, ROUND_DOWN, unitStr +from ..size import B, KiB, MiB, GiB, KB, MB, GB from ..i18n import _, N_ from .. import udev
@@ -1030,8 +1031,10 @@ class Ext2FS(FS):
@property def resizeArgs(self):
argv = ["-p", self.device, "%dM" % (self.targetSize.convertTo(MiB))]return argv
# No unit specifier is interpreted not as bytes, but block size.FMT = {KiB: "%dK", MiB: "%dM", GiB: "%dG"}[self._resizefsUnit]size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit)return ["-p", self.device, size_spec]register_device_format(Ext2FS)
@@ -1423,11 +1426,12 @@ class NTFS(FS):
@property def resizeArgs(self):
FMT = {B: "%d", KB: "%dK", MB: "%dM", GB: "%dG"}[self._resizefsUnit]size_spec = FMT % self.targetSize.convertTo(self._resizefsUnit)# You must supply at least two '-f' options to ntfsresize or # the proceed question will be presented to you.
argv = ["-ff", "-s", "%d" % self.targetSize.convertTo(B),self.device]return argv
return ["-ff", "-s", size_spec, self.device]
Looks good to me.
anaconda-patches@lists.fedorahosted.org