Skip to content

Commit

Permalink
use directly Device Mapping in code
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Sep 17, 2014
1 parent 97f5bfa commit 5ec6b13
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 53 deletions.
18 changes: 7 additions & 11 deletions src/include/bootloader/routines/misc.rb
Expand Up @@ -18,6 +18,9 @@
#
# $Id$
#

require "bootloader/device_mapping"

module Yast
module BootloaderRoutinesMiscInclude
def initialize_bootloader_routines_misc(include_target)
Expand Down Expand Up @@ -94,25 +97,18 @@ def getAnyTypeAttrib(attrib, defaultv)

def remapGlobals(globals_set)
globals_set = deep_copy(globals_set)
by_mount = nil
if Arch.ppc
by_mount = :id
else
by_mount = Storage.GetDefaultMountBy
end

#by_mount = `id;
return deep_copy(globals_set) if by_mount == :label
return globals_set if by_mount == :label

if Builtins.haskey(globals_set, "boot_custom")
Ops.set(
globals_set,
"boot_custom",
BootStorage.MountByDev2Dev(Ops.get(globals_set, "boot_custom", ""))
)
end
globals_set["boot_custom"] &&=
::Bootloader::DeviceMapping.to_kernel_device(globals_set["boot_custom"])

deep_copy(globals_set)
globals_set
end

# Get bootloader device for specified location
Expand Down
3 changes: 2 additions & 1 deletion src/lib/bootloader/grub2base.rb
@@ -1,6 +1,7 @@
# encoding: utf-8
require "yast"
require "bootloader/grub2pwd"
require "bootloader/device_mapping"

module Yast
class GRUB2Base < Module
Expand Down Expand Up @@ -123,7 +124,7 @@ def Propose
resume = BootArch.ResumeAvailable ? largest_swap_part : ""
# try to use label or udev id for device name... FATE #302219
if resume != "" && resume != nil
resume = BootStorage.Dev2MountByDev(resume)
resume = ::Bootloader::DeviceMapping.to_mountby_device(resume)
end

BootCommon.globals["append"] ||= BootArch.DefaultKernelParams(resume)
Expand Down
13 changes: 7 additions & 6 deletions src/modules/BootCommon.rb
Expand Up @@ -19,6 +19,7 @@
# $Id$
#
require "yast"
require "bootloader/device_mapping"

module Yast
class BootCommonClass < Module
Expand Down Expand Up @@ -196,7 +197,7 @@ def CreateLinuxSection(title)
resume = BootArch.ResumeAvailable ? getLargestSwapPartition : ""
# try to use label or udev id for device name... FATE #302219
if resume != "" && resume != nil
resume = BootStorage.Dev2MountByDev(resume)
resume = ::Bootloader::DeviceMapping.to_mountby_device(resume)
end


Expand Down Expand Up @@ -324,7 +325,7 @@ def CreateLinuxSection(title)
"image" => kernel_fn,
"initrd" => initrd_fn,
# try to use label or udev id for device name... FATE #302219
"root" => BootStorage.Dev2MountByDev(
"root" => ::Bootloader::DeviceMapping.to_mountby_device(
BootStorage.RootPartitionDevice
),
"append" => title == "failsafe" ?
Expand Down Expand Up @@ -409,15 +410,15 @@ def Read(reread, avoid_reading_device_map)

# convert device names in device map to the kernel device names
BootStorage.device_mapping = Builtins.mapmap(BootStorage.device_mapping) do |k, v|
{ BootStorage.Dev2MountByDev(k) => v }
{ ::Bootloader::DeviceMapping.to_mountby_device(k) => v }
end

# convert custom boot device names in globals to the kernel device names
# also, for legacy bootloaders like LILO that still pass device names,
# convert the stage1_dev
@globals = Builtins.mapmap(@globals) do |k, v|
if k == "stage1_dev" || Builtins.regexpmatch(k, "^boot_.*custom$")
next { k => BootStorage.Dev2MountByDev(v) }
next { k => ::Bootloader::DeviceMapping.to_kernel_device(v) }
else
next { k => v }
end
Expand Down Expand Up @@ -478,7 +479,7 @@ def Save(clean, init, flush)
# convert the stage1_dev
my_globals = Builtins.mapmap(@globals) do |k, v|
if k == "stage1_dev" || Builtins.regexpmatch(k, "^boot_.*custom$")
next { k => BootStorage.Dev2MountByDev(v) }
next { k => ::Bootloader::DeviceMapping.to_mountby_device(v) }
else
next { k => v }
end
Expand All @@ -492,7 +493,7 @@ def Save(clean, init, flush)
BootStorage.device_mapping
)
my_device_mapping = Builtins.mapmap(BootStorage.device_mapping) do |k, v|
{ BootStorage.Dev2MountByDev(k) => v }
{ ::Bootloader::DeviceMapping.to_mountby_device(k) => v }
end
Builtins.y2milestone("device map after mapping %1", my_device_mapping)

Expand Down
39 changes: 4 additions & 35 deletions src/modules/BootStorage.rb
Expand Up @@ -72,35 +72,6 @@ def main
@md_physical_disks = []
end

# FATE #302219 - Use and choose persistent device names for disk devices
# Converts a "/dev/disk/by-" device name to the corresponding kernel
# device name, if a mapping for this name can be found in the map from
# yast2-storage. If the given device name is not a "/dev/disk/by-" device
# name, it is left unchanged. Also, if the information about the device
# name cannot be found in the target map from yast2-storage, the device
# name is left unchanged.
#
# @param [String] dev string device name
# @return [String] kernel device name

def MountByDev2Dev(dev)
::Bootloader::DeviceMapping.to_kernel_device(dev)
end

# FATE #302219 - Use and choose persistent device names for disk devices
# Converts a device name to the corresponding device name it should be
# mounted by, according to the "mountby" setting for the device from
# yast2-storage. As a safeguard against problems, if the "mountby" device
# name does not exist in the information from yast2-storage, it will
# fallback to the "kernel name" ("/dev/sdXY").
#
# @param [String] dev string device name
# @return [String] device name according to "mountby"
def Dev2MountByDev(dev)
::Bootloader::DeviceMapping.to_mountby_device(dev)
end


# bnc #447591, 438243, 448110 multipath wrong device map
# Function maps real devices to multipath e.g.
# "/dev/sda/" : "/dev/mapper/SATA_ST3120813AS_3LS0CD7M"
Expand Down Expand Up @@ -245,7 +216,7 @@ def InitDiskInfo
# adding moundby (by-id) via user preference
Builtins.foreach(@partinfo) do |partition|
tmp = []
mount_by = Dev2MountByDev(
mount_by = ::Bootloader::DeviceMapping.to_mountby_device(
Builtins.tostring(Ops.get_string(partition, 0, ""))
)
if mount_by != Builtins.tostring(Ops.get_string(partition, 0, ""))
Expand Down Expand Up @@ -610,7 +581,7 @@ def remapDeviceMap(device_map)
ret = {}
# convert device names in device map to the device names by device or label
ret = Builtins.mapmap(@device_mapping) do |k, v|
{ MountByDev2Dev(k) => v }
{ ::Bootloader::DeviceMapping.to_kernel_device(k) => v }
end

deep_copy(ret)
Expand Down Expand Up @@ -638,7 +609,7 @@ def getPartitionList(type, bl)
if type == :boot && bl == "grub"
# check if device is in device map
if Builtins.haskey(@device_mapping, k) ||
Builtins.haskey(@device_mapping, Dev2MountByDev(k))
Builtins.haskey(@device_mapping, ::Bootloader::DeviceMapping.to_mountby_device(k))
partitions = Convert.convert(
Builtins.merge(partitions, Ops.get_list(v, "partitions", [])),
:from => "list",
Expand Down Expand Up @@ -688,7 +659,7 @@ def getPartitionList(type, bl)
# filter out disk which are not in device map
all_disks = Builtins.filter(all_disks) do |k|
if Builtins.haskey(@device_mapping, k) ||
Builtins.haskey(@device_mapping, Dev2MountByDev(k))
Builtins.haskey(@device_mapping, ::Bootloader::DeviceMapping.to_mountby_device(k))
next true
else
next false
Expand Down Expand Up @@ -1006,8 +977,6 @@ def real_disks_for_partition(partition)
publish :variable => :BootPartitionDevice, :type => "string"
publish :variable => :RootPartitionDevice, :type => "string"
publish :variable => :ExtendedPartitionDevice, :type => "string"
publish :function => :MountByDev2Dev, :type => "string (string)"
publish :function => :Dev2MountByDev, :type => "string (string)"
publish :function => :InitDiskInfo, :type => "void ()"
publish :function => :ProposeDeviceMap, :type => "void ()"
publish :function => :DisksOrder, :type => "list <string> ()"
Expand Down

0 comments on commit 5ec6b13

Please sign in to comment.