Skip to content

Commit

Permalink
Merge 160daf6 into 63bb64a
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Sep 17, 2018
2 parents 63bb64a + 160daf6 commit 1a79c73
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/lib/y2storage/planned/has_size.rb
Expand Up @@ -89,7 +89,11 @@ module ClassMethods
# @return [Array] list containing devices with an adjusted value
# for Planned::HasSize#size
def distribute_space(devices, space_size, rounding: nil, align_grain: nil, end_alignment: false)
raise RuntimeError if space_size < DiskSize.sum(devices.map(&:min))
needed_size = DiskSize.sum(devices.map(&:min))
if space_size < needed_size
log.error "not enough space: needed #{needed_size}, available #{space_size}"
raise RuntimeError
end

rounding ||= align_grain
rounding ||= DiskSize.new(1)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/y2storage/planned/stray_blk_device.rb
Expand Up @@ -34,6 +34,7 @@ class StrayBlkDevice < Device
include Planned::CanBeFormatted
include Planned::CanBeMounted
include Planned::CanBeEncrypted
include Planned::CanBePv
include MatchVolumeSpec

# Constructor.
Expand All @@ -42,6 +43,7 @@ def initialize
initialize_can_be_formatted
initialize_can_be_mounted
initialize_can_be_encrypted
initialize_can_be_pv
end

# @see Device.to_string_attrs
Expand Down
19 changes: 16 additions & 3 deletions src/lib/y2storage/proposal/autoinst_devices_creator.rb
Expand Up @@ -75,15 +75,20 @@ def initialize(original_graph)
# @param planned_devices [Array<Planned::Device>] Devices to create/reuse
# @param disk_names [Array<String>] Disks to consider
# @return [Devicegraph] New devicegraph in which all the planned devices have been allocated
# rubocop:disable Metrics/AbcSize
def populated_devicegraph(planned_devices, disk_names)
# Process planned partitions
log.info "planned devices = #{planned_devices.inspect}"
log.info "disk names = #{disk_names.inspect}"

planned_partitions = planned_devices.select { |d| d.is_a?(Planned::Partition) }
parts_to_reuse, parts_to_create = planned_partitions.partition(&:reuse?)
creator_result = create_partitions(parts_to_create, disk_names)
reuse_devices(parts_to_reuse, creator_result.devicegraph)

# Process planned stray block devices (Xen virtual partitions)
process_stray_devs(planned_devices, creator_result.devicegraph)
# Add them to reuse list so they can be considered for lvm later on
parts_to_reuse += process_stray_devs(planned_devices, creator_result.devicegraph)

# Process planned MD arrays
planned_mds = planned_devices.select { |d| d.is_a?(Planned::Md) }
Expand All @@ -101,6 +106,7 @@ def populated_devicegraph(planned_devices, disk_names)
creator_result, parts_to_create + mds_to_create + planned_vgs
)
end
# rubocop:enable Metrics/AbcSize

protected

Expand Down Expand Up @@ -150,7 +156,10 @@ def create_partitions(new_partitions, disk_names)
# @param parts_to_reuse [Array<Planned::Partition>] List of partitions to reuse
# @return [Proposal::CreatorResult] Result containing the specified volume groups
def set_up_lvm(vgs, previous_result, parts_to_reuse)
log.info "BEGIN: set_up_lvm: vgs=#{vgs.inspect} previous_result=#{previous_result.inspect}"
# log separately to be more readable
log.info "BEGIN: set_up_lvm: vgs=#{vgs.inspect}"
log.info "BEGIN: set_up_lvm: previous_result=#{previous_result.inspect}"
log.info "BEGIN: set_up_lvm: parts_to_reuse=#{parts_to_reuse.inspect}"
vgs.reduce(previous_result) do |result, vg|
pvs = previous_result.created_names { |d| d.pv_for?(vg.volume_group_name) }
pvs += parts_to_reuse.select { |d| d.pv_for?(vg.volume_group_name) }.map(&:reuse_name)
Expand Down Expand Up @@ -229,11 +238,15 @@ def flexible_devices(devices)
# Formats and/or mounts the stray block devices (Xen virtual partitions)
#
# @param planned_devices [Array<Planned::Device>] all planned devices
# @param devicegraph [Devicegraph] devicegraph containing the Xen
# @param devicegraph [Devicegraph] devicegraph containing the Xen
# partitions to be processed. It will be modified.
# @return [Array<Planned::StrayBlkDevice>] all stray block
# devices
def process_stray_devs(planned_devices, devicegraph)
planned_stray_devs = planned_devices.select { |d| d.is_a?(Planned::StrayBlkDevice) }
planned_stray_devs.each { |d| d.reuse!(devicegraph) }

planned_stray_devs
end
end
end
Expand Down
47 changes: 46 additions & 1 deletion src/lib/y2storage/proposal/autoinst_devices_planner.rb
Expand Up @@ -89,14 +89,59 @@ def planned_devices(drives_map)
# @return [AutoinstIssues::List] List of AutoYaST issues to register them
attr_reader :issues_list

# Returns an array of planned partitions for a given disk or the disk
# itself if there are no partitions planned
#
# @param disk [Disk,Dasd] Disk to place the partitions on
# @param drive [AutoinstProfile::DriveSection] drive section describing
# the layout for the disk
# @return [Array<Planned::Partition, Planned::StrayBlkDevice>] List of planned partitions or disks
def planned_for_disk(disk, drive)
# partition 0: use the entire device
partition_zero = drive.partitions.find { |p| p.partition_nr == 0 }
result = if partition_zero
planned_for_full_disk(drive, partition_zero)
else
planned_for_partitions(disk, drive)
end

result
end

# Returns disk to be used without partitions.
#
# @note This is not quite what #planned_for_stray_devices is for:
# #planned_for_full_disk creates a single entry for the full disk while
# #planned_for_stray_devices creates full disk entries for each
# partition.
#
# @param drive [AutoinstProfile::DriveSection] drive section describing
# the layout for the disk
# @param part [AutoinstProfile::PartitionSection] partition section with
# elements to apply to the full disk
# @return [Array<Planned::StrayBlkDevice>] List containing planned disk
#
# @note The part argument is used when we emulate the sle12 behavior to
# have partition 0 mean the full disk.
def planned_for_full_disk(drive, part = nil)
planned = Y2Storage::Planned::StrayBlkDevice.new
part ||= Y2Storage::AutoinstProfile::PartitionSection.new
device_config(planned, part, drive)
planned.lvm_volume_group_name = part.lvm_group
add_device_reuse(planned, drive.device, part)

[planned]
end

# Returns an array of planned partitions for a given disk
#
# @param disk [Disk,Dasd] Disk to place the partitions on
# @param drive [AutoinstProfile::DriveSection] drive section describing
# the layout for the disk
# @return [Array<Planned::Partition>] List of planned partitions
def planned_for_disk(disk, drive)
def planned_for_partitions(disk, drive)
result = []

drive.partitions.each_with_index do |section|
# TODO: fix Planned::Partition.initialize
partition = Y2Storage::Planned::Partition.new(nil, nil)
Expand Down

0 comments on commit 1a79c73

Please sign in to comment.