Skip to content

Commit

Permalink
Merge branch 'master' into resize-part
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Dec 4, 2017
2 parents 14cb35d + 2f87157 commit b663126
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 74 deletions.
10 changes: 9 additions & 1 deletion package/yast2-storage-ng.changes
@@ -1,8 +1,16 @@
-------------------------------------------------------------------
Fri Dec 1 16:02:09 UTC 2017 - jlopez@suse.com
Fri Dec 1 17:02:09 UTC 2017 - jlopez@suse.com

- Partitoner: added support for resizing partitions (bsc#1057586).
- Part of fate#318196.
- 4.0.48

-------------------------------------------------------------------
Fri Dec 1 16:58:14 UTC 2017 - ancor@suse.com

- Rely on the new improved mechanism of libstorage-ng to sort
devices by name. Preparation for bsc#1049901 and part of
fate#31896.
- 4.0.47

-------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion package/yast2-storage-ng.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-storage-ng
Version: 4.0.47
Version: 4.0.48
Release: 0
BuildArch: noarch

Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2storage/blk_device.rb
Expand Up @@ -22,6 +22,7 @@
require "y2storage/storage_class_wrapper"
require "y2storage/device"
require "y2storage/hwinfo_reader"
require "y2storage/comparable_by_name"

module Y2Storage
# Base class for most devices having a device name, udev path and udev ids.
Expand All @@ -31,6 +32,8 @@ class BlkDevice < Device
wrap_class Storage::BlkDevice,
downcast_to: ["Partitionable", "Partition", "Encryption", "LvmLv"]

include ComparableByName

# @!method self.all(devicegraph)
# @param devicegraph [Devicegraph]
# @return [Array<BlkDevice>] all the block devices in the given devicegraph
Expand Down
80 changes: 80 additions & 0 deletions src/lib/y2storage/comparable_by_name.rb
@@ -0,0 +1,80 @@
# encoding: utf-8

# Copyright (c) [2017] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "y2storage/device"

module Y2Storage
# Mixin for classes supporting to be sorted by name in libstorage-ng, offering
# methods to sort in a Ruby-friendly way and to query the whole sorted
# collection from a devicegraph.
#
# Classes including this mixin should be accepted by {Device.compare_by_name}
# (defined by libstorage-ng) and should implement the class method .all to
# query the whole collection from a devicegraph.
module ComparableByName
# Compare to another device by name, used for sorting sets of
# partitionable devices.
#
# @see Device.compare_by_name to check which types are accepted as argument
# (restricted by libstorage-ng).
#
# @raise [Storage::Exception] if trying to compare with something that is not
# supported by libstorage-ng.
#
# Using this method to compare and sort would result is something similar
# to alphabetical order but with some desired exceptions like:
#
# * /dev/sda, /dev/sdb, ..., /dev/sdaa
# * /dev/md1, /dev/md2, ..., /dev/md10
#
# Unlike the class method {Device.compare_by_name}, which is boolean,
# this method follows the Ruby convention of returning -1 or 1 in the same
# cases than the <=> operator.
#
# @param other [BlkDevice, LvmVg]
# @return [Integer] -1 if this object should appear before the one passed as
# argument (less than). 1 otherwise.
def compare_by_name(other)
# In practice, two devices cannot have the same name. But let's take the
# case in consideration to ensure full compatibility with <=>
return 0 if name == other.name
Device.compare_by_name(self, other) ? -1 : 1
end

# Class methods for the mixin
module ClassMethods
# All the devices of the correspondig class found in the given devicegraph,
# sorted by name
#
# See {#compare_by_name} to know more about the sorting.
#
# @param devicegraph [Devicegraph]
# @return [Array<#compare_by_name>]
def sorted_by_name(devicegraph)
all(devicegraph).sort { |a, b| a.compare_by_name(b) }
end
end

def self.included(base)
base.extend(ClassMethods)
end
end
end
19 changes: 19 additions & 0 deletions src/lib/y2storage/device.rb
Expand Up @@ -135,6 +135,25 @@ class Device
storage_forward :userdata=
protected :userdata, :userdata=

# @!method self.compare_by_name(lhs, rhs)
# Compare two devices by their name, used for sorting sets of
# block devices and/or LVM VGs.
#
# Using this method to compare and sort would result is something similar
# to alphabetical order but with some desired exceptions like:
#
# * /dev/sda, /dev/sdb, ..., /dev/sdaa
# * /dev/md1, /dev/md2, ..., /dev/md10
#
# @raise [Storage::Exception] if trying to compare something that is not
# {BlkDevice} or {LvmVg}
#
# @param lhs [BlkDevice, LvmVg]
# @param rhs [BlkDevice, LvmVg]
# @return [boolean] true if the first argument should appear first in a
# sorted list (less than)
storage_class_forward :compare_by_name

# Ancestors in the devicegraph in no particular order, not including the
# device itself.
#
Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2storage/lvm_vg.rb
Expand Up @@ -21,6 +21,7 @@

require "y2storage/storage_class_wrapper"
require "y2storage/device"
require "y2storage/comparable_by_name"

module Y2Storage
# A Volume Group of the Logical Volume Manager (LVM)
Expand All @@ -29,6 +30,8 @@ module Y2Storage
class LvmVg < Device
wrap_class Storage::LvmVg

include ComparableByName

# @!attribute vg_name
# @return [String] volume group name (e.g."vg0"), not to be confused
# with BlkDevice#name (e.g. "/dev/mapper/vg0")
Expand Down
18 changes: 0 additions & 18 deletions src/lib/y2storage/partition.rb
Expand Up @@ -158,24 +158,6 @@ def self.all(devicegraph)
Partitionable.all(devicegraph).map(&:partitions).flatten
end

# All partitions in the given devicegraph, sorted by name
#
# See {Partitionable#compare_by_name} to know more about the sorting.
#
# @param devicegraph [Devicegraph]
# @return [Array<Partition>]
def self.sorted_by_name(devicegraph)
Partitionable.sorted_by_name(devicegraph).each_with_object([]) do |partitionable, result|
partitions = partitionable.partitions.sort do |a, b|
# Within the same partition table, the equivalent of Partitionable#compare_by_name
# is sorting by name size and then alphabetically
by_size = a.name.size <=> b.name.size
by_size.zero? ? a.name <=> b.name : by_size
end
result.concat(partitions)
end
end

# @return [String]
def inspect
"<Partition #{name} #{size}, #{region.show_range}>"
Expand Down
50 changes: 0 additions & 50 deletions src/lib/y2storage/partitionable.rb
Expand Up @@ -83,56 +83,6 @@ class Partitionable < BlkDevice
# in no particular order
storage_class_forward :all, as: "Partitionable"

# @!method self.compare_by_name(lhs, rhs)
# Compare two devices by their name, used for sorting sets of
# partitionable devices.
#
# Using this method to compare and sort would result is something similar
# to alphabetical order but with some desired exceptions like:
#
# * /dev/sda, /dev/sdb, ..., /dev/sdaa
# * /dev/md1, /dev/md2, ..., /dev/md10
#
# @param lhs [Partitionable]
# @param rhs [Partitionable]
# @return [boolean] true if the first argument should appear first in a
# sorted list (less than)
storage_class_forward :compare_by_name

# Compare to another device by name, used for sorting sets of
# partitionable devices.
#
# Using this method to compare and sort would result is something similar
# to alphabetical order but with some desired exceptions like:
#
# * /dev/sda, /dev/sdb, ..., /dev/sdaa
# * /dev/md1, /dev/md2, ..., /dev/md10
#
# Unlike the class method {Partitionable.compare_by_name}, which is boolean,
# this method follows the Ruby convention of returning -1 or 1 in the same
# cases than the <=> operator.
#
# @param other [Partitionable]
# @return [Integer] -1 if this object should appear before the one passed as
# argument (less than). 1 otherwise.
def compare_by_name(other)
# In practice, two devices cannot have the same name. But let's take the
# case in consideration to ensure full compatibility with <=>
return 0 if name == other.name
Partitionable.compare_by_name(self, other) ? -1 : 1
end

# All the devices of the correspondig class found in the given devicegraph,
# sorted by name
#
# See {Partitionable#compare_by_name} to know more about the sorting.
#
# @param devicegraph [Devicegraph]
# @return [Array<#compare_by_name>]
def self.sorted_by_name(devicegraph)
all(devicegraph).sort { |a, b| a.compare_by_name(b) }
end

# Partitions in the device
#
# @return [Array<Partition>]
Expand Down

0 comments on commit b663126

Please sign in to comment.