[blivet:master 08/11] Add a size() method to the raid classes (#1085474)

Vratislav Podzimek vpodzime at redhat.com
Mon Apr 14 09:13:48 UTC 2014


On Fri, 2014-04-11 at 11:23 -0400, mulhern wrote:
> Related: fed#1085474
> 
> Signed-off-by: mulhern <amulhern at redhat.com>
> ---
>  blivet/devicelibs/mdraid.py        |  3 +++
>  blivet/devicelibs/raid.py          | 39 ++++++++++++++++++++++++++++++++++++++
>  tests/devicelibs_test/raid_test.py | 34 ++++++++++++++++++++++++++++++++-
>  3 files changed, 75 insertions(+), 1 deletion(-)
> 
> diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
> index 1077400..1445167 100644
> --- a/blivet/devicelibs/mdraid.py
> +++ b/blivet/devicelibs/mdraid.py
> @@ -57,6 +57,9 @@ class Container(object):
>          raise MDRaidError("get_size is not defined for level container.")
>      def get_raw_array_size(self, member_count, smallest_member_size):
>          raise MDRaidError("get_raw_array_size is not defined for level container.")
> +    def size(self, member_sizes, num_members=None, chunk_size=None, superblock_size_func=None):
> +        return sum(member_sizes)
> +
>      def __str__(self):
>          return self.name
>  
> diff --git a/blivet/devicelibs/raid.py b/blivet/devicelibs/raid.py
> index e6018bb..36453cd 100644
> --- a/blivet/devicelibs/raid.py
> +++ b/blivet/devicelibs/raid.py
> @@ -212,6 +212,45 @@ class RAIDLevel(object):
>          """Helper function; not to be called directly."""
>          raise NotImplementedError()
>  
> +    def size(self, member_sizes, num_members=None, chunk_size=None, superblock_size_func=None):
> +        """Estimate the amount of data that can be stored on this array.
> +
> +           :param member_size: a list of the sizes of members of this array
> +           :type member_size: list of :class:`~.size.Size`
> +           :param int num_members: the number of members in the array
> +           :param chunk_size: the smallest unit of size for
> +           :type chunk_size: :class:`~.size.Size`
> +           :param superblock_size_func: a function that estimates the
> +              superblock size for this array
> +           :type superblock_size_func: a function from :class:`~.size.Size` to
> +              :class:`~.size.Size`
> +           :returns: an estimate of the amount of data that can be stored on
> +              this array
> +           :rtype: :class:`~.size.Size`
> +
> +           Note that the number of members in the array may not be the same
> +           as the length of member_sizes if the array is still
> +           under construction.
> +        """
> +        if not member_sizes:
> +            return 0
> +
> +        if num_members is None:
> +            num_members = len(member_sizes)
> +
> +        if chunk_size is None or chunk_size == 0:
> +            raise RaidError("chunk_size parameter value %s is not acceptable")
> +
> +        if superblock_size_func is None:
> +            raise RaidError("superblock_size_func value of None is not acceptable")
> +
> +        min_size = min(member_sizes)
> +        total_space = self.get_net_array_size(num_members, min_size)
> +        superblock_size = superblock_size_func(total_space)
> +        min_data_size = min_size - superblock_size
> +        total_data_size = self.get_net_array_size(num_members, min_data_size)
> +        return self._trim(total_data_size, chunk_size)
> +
I think that 'get_size' would be a better name for a method. 'size'
sound more like a property.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list