Skip to content

Commit

Permalink
WIP: proposal working with allocate_volumes_mode==:single_device
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Jul 4, 2019
1 parent c4ca8c8 commit dd27358
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/lib/y2storage/planned/lvm_lv.rb
Expand Up @@ -55,6 +55,8 @@ class LvmLv < Device
# @return [Integer] Number of stripes
attr_accessor :stripes

attr_accessor :disk

# Builds a new object based on a real LvmLv one
#
# The new instance represents the intention to reuse the real LV, so the
Expand Down Expand Up @@ -150,7 +152,8 @@ def add_thin_lv(lv)
end

def self.to_string_attrs
[:mount_point, :reuse_name, :min_size, :max_size, :logical_volume_name, :subvolumes]
[:mount_point, :reuse_name, :min_size, :max_size, :disk,
:logical_volume_name, :subvolumes]
end

protected
Expand Down
6 changes: 6 additions & 0 deletions src/lib/y2storage/planned/lvm_vg.rb
Expand Up @@ -134,6 +134,7 @@ def minimal_pv_partition
res.lvm_volume_group_name = volume_group_name
res.encryption_password = pvs_encryption_password
res.min_size = min_pv_size
res.disk = forced_disk_name
res
end

Expand Down Expand Up @@ -249,6 +250,11 @@ def self.to_string_attrs
[:reuse_name, :volume_group_name]
end

def forced_disk_name
forced_lv = lvs.find(&:disk)
forced_lv ? forced_lv.disk : nil
end

protected

def device_to_reuse(devicegraph)
Expand Down
10 changes: 7 additions & 3 deletions src/lib/y2storage/proposal/devices_planner_strategies/ng.rb
Expand Up @@ -91,8 +91,8 @@ def adjust_to_settings(planned_device, volume)
adjust_encryption(planned_device, volume)
adjust_sizes(planned_device, volume)
adjust_btrfs(planned_device, volume)
adjust_device(planned_device, volume)

adjust_root(planned_device, volume) if planned_device.root?
adjust_swap(planned_device, volume) if planned_device.swap?
end

Expand Down Expand Up @@ -172,8 +172,12 @@ def adjust_btrfs_sizes(planned_device, volume)
#
# @param planned_device [Planned::Device]
# @param _volume [VolumeSpecification]
def adjust_root(planned_device, _volume)
planned_device.disk = settings.root_device if planned_device.is_a?(Planned::Partition)
def adjust_device(planned_device, volume)
if settings.devices_per_volume?
planned_device.disk = volume.device if planned_device.respond_to?(:disk=)
elsif planned_device.root?
planned_device.disk = settings.root_device if planned_device.is_a?(Planned::Partition)
end
end

# Adjusts values when planned device is swap
Expand Down
3 changes: 3 additions & 0 deletions src/lib/y2storage/proposal/lvm_helper.rb
Expand Up @@ -88,6 +88,9 @@ def reusable_volume_groups(devicegraph)
return [] if encrypt?

vgs = devicegraph.lvm_vgs
# TODO: si forced_disk_name, incluir sólo vgs que tengan algún PV en ese
# disco

big_vgs, small_vgs = vgs.partition { |vg| vg.total_size >= volume_group.target_size }
# Use #vg_name to ensure stable sorting
big_vgs.sort_by! { |vg| [vg.total_size, vg.vg_name] }
Expand Down
9 changes: 8 additions & 1 deletion src/lib/y2storage/proposal/phys_vol_calculator.rb
Expand Up @@ -37,7 +37,14 @@ class PhysVolCalculator
# potentially contain physical volumes
# @param planned_vg [Planned::LvmVg] volume group to create the PVs for
def initialize(all_spaces, planned_vg)
@all_spaces = all_spaces
# Is this the right location for this filter?
name = planned_vg.forced_disk_name
@all_spaces =
if name
all_spaces.select { |i| i.disk_name == name }
else
all_spaces
end
@planned_vg = planned_vg

strategy = planned_vg.size_strategy
Expand Down
7 changes: 3 additions & 4 deletions src/lib/y2storage/proposal_settings.rb
Expand Up @@ -157,7 +157,7 @@ def candidate_devices
return nil if volumes.select(&:proposed).any? {|vol| vol.device.nil? }

# TODO: sort?
volumes.flat_map(&:device).compact
volumes.flat_map(&:device).sort.compact.uniq
else
@candidate_devices
end
Expand Down Expand Up @@ -255,8 +255,9 @@ def candidate_devices=(devices)
# explicit_dev_names?, use_volumes_device?, su_madre_calva...
def devices_per_volume?
# There is no chance to specify this using the legacy format
ng_format? ? @devices_per_volume : false
ng_format? ? !!devices_per_volume : false
end
attr_accessor :devices_per_volume

# TODO: so far, this breaks the sorting
def volumes_sets
Expand Down Expand Up @@ -431,8 +432,6 @@ def apply_ng_defaults
self.other_delete_mode ||= :ondemand
self.lvm_vg_strategy ||= :use_available
self.volumes ||= []
# Let's set it to true to have fun
@devices_per_volume = true
end

# FIXME: Improve implementation. Use composition to encapsulate logic for
Expand Down

0 comments on commit dd27358

Please sign in to comment.