[blivet:master 17/21] Rewrite TmpFS class definition.
David Lehman
dlehman at redhat.com
Tue Jan 20 18:28:36 UTC 2015
On 01/15/2015 12:39 PM, mulhern wrote:
> Principle changes are:
>
> * Abstract calculating the format for the size mount option into
> _sizeOption method.
>
> * Substitute FS.mountopts for TmpFS._options instance variable.
>
> * Whether mounting or remounting always use default options if no
> special options set and always use size mount option if required.
>
> * do not set size to what the tmpfs default usually is. When it is
> necessary to get the actual size, TmpFS._getExistingSize() will be used.
> ---
> blivet/formats/fs.py | 63 +++++++++++++++++++---------------------------------
> 1 file changed, 23 insertions(+), 40 deletions(-)
>
> diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
> index c1bc3ed..b1172d1 100644
> --- a/blivet/formats/fs.py
> +++ b/blivet/formats/fs.py
> @@ -1550,22 +1550,9 @@ class TmpFS(NoDevFS):
> # just use the default maxsize, which is 0, this disables
> # resizing but other operations such as mounting should work fine
>
> - # check if fixed filesystem size has been specified,
> - # if no size is specified, tmpfs will by default
> - # be limited to half of the system RAM
> - # (sizes of all tmpfs mounts are independent)
> - fsoptions = kwargs.get("mountopts")
> - self._size_option = ""
> - if fsoptions:
> - # some mount options were specified, replace the default value
> - self._options = fsoptions
> - if self._size:
> - # absolute size for the tmpfs mount has been specified
> - self._size_option = "size=%dm" % self._size.convertTo(MiB)
> - else:
> - # if no size option is specified, the tmpfs mount size will be 50%
> - # of system RAM by default
> - self._size = util.total_memory()/2
> + # if the size is 0, which is probably not set, accept the default
> + # size when mounting.
> + self._accept_default_size = not(self._size)
>
> def create(self, **kwargs):
> """ A filesystem is created automatically once tmpfs is mounted. """
> @@ -1606,6 +1593,15 @@ class TmpFS(NoDevFS):
> def mountable(self):
> return True
>
> + def _sizeOption(self, size):
> + """ Returns a size option string appropriate for mounting tmpfs.
> +
> + :param Size size: any size
> + :returns: size option
> + :rtype: str
> + """
> + return "size=%dm" % size.convertTo(MiB)
> +
> def _getOptions(self):
> # if the size option string is defined,
> # append it to options
> @@ -1614,11 +1610,12 @@ class TmpFS(NoDevFS):
> # when the filesystem is resized;
> # replacing the size option in the otherwise free-form
> # options string would get messy fast)
> - opts = ",".join([o for o in [self._options, self._size_option] if o])
> - return opts or "defaults"
> -
> - def _setOptions(self, options):
> - self._options = options
> + opts = super(TmpFS, self)._getOptions()
> + if self._accept_default_size:
> + size_opt = None
> + else:
> + size_opt = self._sizeOption(self._size)
> + return ",".join(o for o in (opts, size_opt) if o)
>
> @property
> def free(self):
> @@ -1643,29 +1640,15 @@ class TmpFS(NoDevFS):
> def resizeArgs(self):
> # a live tmpfs mount can be resized by remounting it with
> # the mount command
> -
> - # add the remount flag, size and any options
> - remount_options = 'remount,size=%dm' % self.targetSize.convertTo(MiB)
> - # if any mount options are defined, append them
> - if self._options:
> - remount_options = "%s,%s" % (remount_options, self._options)
> - return ['-o', remount_options, self._type, self._mountpoint]
> + options = ("remount", self._sizeOption(self.targetSize), self.mountopts or ",".join(self.defaultMountOptions))
> + return ['-o', ",".join(options), self._type, self._mountpoint]
>
> def doResize(self):
> - # we need to override doResize, because the
> - # self._size_option string needs to be updated in case
> - # the tmpfs mount is successfully resized, using the new
> - # self._size value
> + # Override superclass method to record whether mount options
> + # should include an explicit size specification.
> original_size = self._size
> FS.doResize(self)
> - # after a successful resize, self._size
> - # is set to be equal to self.targetSize,
> - # so it can be used to check if resize took place
> - if original_size != self._size:
> - # 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(MiB)
> + self._accept_default_size = self._accept_default_size and original_size == self._size
>
> register_device_format(TmpFS)
>
>
All these tmpfs changes are taking way more time/effort than is called
for. The main thing you need to do is make sure that the supported
anaconda/kickstart functionality still works with your changes.
David
More information about the anaconda-patches
mailing list