[blivet:master] Use _resizefsUnit in resizeArgs() method.

mulhern amulhern at redhat.com
Thu Dec 18 15:03:34 UTC 2014


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.

Also, get rid of realistic FS.resizeArgs() implementation and make clear
that it needs to be overridden for subclasses that have resize functionality.

Add a resizefsUnit to ReiserFS and use it appropriately. ReiserFS._resizable
is False, so this makes no difference in operation.

This patch doesn't change behavior, it mostly replaces a literal with an
already defined constant in appropriate places.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/formats/fs.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 07a383a..73a7d59 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -431,8 +431,14 @@ class FS(DeviceFormat):
 
     @property
     def resizeArgs(self):
-        argv = [self.device, "%d" % (self.targetSize.convertTo("MiB"),)]
-        return argv
+        """ Returns the arguments for resizing the filesystem.
+
+            Must be overridden by every class that has non-None _resizefs.
+
+            :returns: arguments for resizing a filesystem.
+            :rtype: list of str
+        """
+        return []
 
     def doResize(self):
         """ Resize this filesystem based on this instance's targetSize attr.
@@ -1041,7 +1047,7 @@ class Ext2FS(FS):
 
     @property
     def resizeArgs(self):
-        argv = ["-p", self.device, "%dM" % (self.targetSize.convertTo("MiB"))]
+        argv = ["-p", self.device, "%dM" % (self.targetSize.convertTo(self._resizefsUnit))]
         return argv
 
 register_device_format(Ext2FS)
@@ -1239,6 +1245,7 @@ class ReiserFS(FS):
     _type = "reiserfs"
     _mkfs = "mkreiserfs"
     _resizefs = "resize_reiserfs"
+    _resizefsUnit = "MiB"
     _labelfs = fslabeling.ReiserFSLabeling()
     _modules = ["reiserfs"]
     _defaultFormatOptions = ["-f", "-f"]
@@ -1263,7 +1270,7 @@ class ReiserFS(FS):
 
     @property
     def resizeArgs(self):
-        argv = ["-s", "%dM" % (self.targetSize.convertTo(spec="MiB"),), self.device]
+        argv = ["-s", "%dM" % (self.targetSize.convertTo(spec=self._resizefsUnit),), self.device]
         return argv
 
 register_device_format(ReiserFS)
@@ -1446,7 +1453,7 @@ class NTFS(FS):
     def resizeArgs(self):
         # 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(spec="b"),
+        argv = ["-ff", "-s", "%d" % self.targetSize.convertTo(spec=self._resizefsUnit),
                 self.device]
         return argv
 
@@ -1556,6 +1563,7 @@ class TmpFS(NoDevFS):
     # remounting can be used to change
     # the size of a live tmpfs mount
     _resizefs = "mount"
+    _resizefsUnit = "MiB"
     # as tmpfs is part of the Linux kernel,
     # it is Linux-native
     _linuxNative = True
@@ -1593,7 +1601,7 @@ class TmpFS(NoDevFS):
             self._options = fsoptions
         if self._size:
             # absolute size for the tmpfs mount has been specified
-            self._size_option = "size=%dm" % self._size.convertTo(spec="MiB")
+            self._size_option = "size=%dm" % self._size.convertTo(spec=self._resizefsUnit)
         else:
             # if no size option is specified, the tmpfs mount size will be 50%
             # of system RAM by default
@@ -1675,7 +1683,7 @@ class TmpFS(NoDevFS):
         # the mount command
 
         # add the remount flag, size and any options
-        remount_options = 'remount,size=%dm' % self.targetSize.convertTo(spec="MiB")
+        remount_options = 'remount,size=%dm' % self.targetSize.convertTo(spec=self._resizefsUnit)
         # if any mount options are defined, append them
         if self._options:
             remount_options = "%s,%s" % (remount_options, self._options)
@@ -1695,7 +1703,7 @@ class TmpFS(NoDevFS):
             # update the size option string
             # -> please note that resizing always sets the
             # size of this tmpfs mount to an absolute value
-            self._size_option = "size=%dm" % self._size.convertTo(spec="MiB")
+            self._size_option = "size=%dm" % self._size.convertTo(spec=self._resizefsUnit)
 
 register_device_format(TmpFS)
 
-- 
1.9.3



More information about the anaconda-patches mailing list