Skip to content

Commit

Permalink
adapted suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Apr 29, 2024
1 parent a3e40b0 commit dc66920
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 94 deletions.
20 changes: 0 additions & 20 deletions src/lib/bootloader/bootloader_base.rb
Expand Up @@ -7,8 +7,6 @@
Yast.import "Linuxrc"
Yast.import "Mode"
Yast.import "Package"
Yast.import "Kernel"
Yast.import "BootStorage"

module Bootloader
# Represents base for all kinds of bootloaders
Expand Down Expand Up @@ -101,24 +99,6 @@ def merge(other)

private

def propose_resume
swap_parts = Yast::BootStorage.available_swap_partitions
largest_swap_name, lagest_swap_size = (swap_parts.max_by { |_part, size| size } || [])

propose = Yast::Kernel.propose_hibernation? && largest_swap_name

return "" unless propose

if lagest_swap_size < Yast::BootStorage.ram_size
log.info "resume parameter is not added because swap (#{largest_swap_name}) is too small"

return ""
end

# try to use label or udev id for device name... FATE #302219
UdevMapping.to_mountby_device(largest_swap_name)
end

# @return [Boolean] true when kexec-tools package should be included; false otherwise
def include_kexec_tools_package?
return false if Yast::Mode.live_installation
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/bootloader_factory.rb
Expand Up @@ -99,7 +99,7 @@ def bootloader_by_name(name)
nil # in other cases it means that read failed
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/CyclomaticComplexity

private

Expand Down
40 changes: 36 additions & 4 deletions src/lib/bootloader/generic_widgets.rb
Expand Up @@ -155,9 +155,21 @@ def help
)
end

def init; end
def init
if Bootloader::BootloaderFactory.current.respond_to?(:cpu_mitigations)
self.value = Bootloader::BootloaderFactory.current.cpu_mitigations.value.to_s
else
disable
end
end


def store; end
def store
if enabled?
Bootloader::BootloaderFactory.current.cpu_mitigations =
::Bootloader::CpuMitigations.new(value.to_sym)
end
end
end

# represents kernel command line
Expand All @@ -179,8 +191,28 @@ def help
)
end

def init; end
def init
current_bl = ::Bootloader::BootloaderFactory.current
if current_bl.is_a?(::Bootloader::SystemdBoot)
self.value = current_bl.kernel_params.serialize.gsub(/mitigations=\S+/, "")
elsif current_bl.is_a?(::Bootloader::Grub2Base)
self.value = current_bl.grub_default.kernel_params.serialize.gsub(/mitigations=\S+/, "")
else
disable
end
end

def store; end
def store
if enabled?
current_bl = ::Bootloader::BootloaderFactory.current
if current_bl.is_a?(::Bootloader::SystemdBoot)
current_bl.kernel_params.replace(value)
elsif
current_bl.grub_default.kernel_params.replace(value)
else
log.error("Bootloader type #{current_bl} not found.")
end
end
end
end
end
34 changes: 1 addition & 33 deletions src/lib/bootloader/grub2_widgets.rb
Expand Up @@ -122,25 +122,6 @@ def store
end
end

# Represents decision if smt is enabled
class GrubCpuMitigationsWidget < CpuMitigationsWidget
include Grub2Helper

def init
if grub2.respond_to?(:cpu_mitigations)
self.value = grub2.cpu_mitigations.value.to_s
else
# do not crash when use no bootloader. This widget is also used in security dialog.
# (bsc#1184968)
disable
end
end

def store
grub2.cpu_mitigations = ::Bootloader::CpuMitigations.new(value.to_sym) if enabled?
end
end

# Represents decision if generic MBR have to be installed on disk
class GenericMBRWidget < CWM::CheckBox
include Grub2Helper
Expand Down Expand Up @@ -227,19 +208,6 @@ def store
end
end

# represents kernel command line
class Grub2KernelAppendWidget < KernelAppendWidget
include Grub2Helper

def init
self.value = grub_default.kernel_params.serialize.gsub(/mitigations=\S+/, "")
end

def store
grub_default.kernel_params.replace(value)
end
end

# Represents Protective MBR action
class PMBRWidget < CWM::ComboBox
include Grub2Helper
Expand Down Expand Up @@ -1012,7 +980,7 @@ def contents
VBox(
VSpacing(1),
MarginBox(1, 0.5, KernelAppendWidget.new),
MarginBox(1, 0.5, Left(GrubCpuMitigationsWidget.new)),
MarginBox(1, 0.5, Left(CpuMitigationsWidget.new)),
MarginBox(1, 0.5, console_widget),
VStretch()
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/grub2base.rb
Expand Up @@ -386,7 +386,7 @@ def propose_encrypted

def propose_grub_default
if grub_default.kernel_params.empty?
kernel_line = Yast::BootArch.DefaultKernelParams(propose_resume)
kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume)
grub_default.kernel_params.replace(kernel_line)
end
grub_default.gfxmode ||= "auto"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bootloader/systemdboot.rb
Expand Up @@ -130,7 +130,7 @@ def propose
super
log.info("Propose settings...")
if @kernel_container.kernel_params.empty?
kernel_line = Yast::BootArch.DefaultKernelParams(propose_resume)
kernel_line = Yast::BootArch.DefaultKernelParams(Yast::BootStorage.propose_resume)
@kernel_container.kernel_params.replace(kernel_line)
end
self.menue_timeout = Yast::ProductFeatures.GetIntegerFeature("globals", "boot_timeout").to_i
Expand Down
36 changes: 2 additions & 34 deletions src/lib/bootloader/systemdboot_widgets.rb
Expand Up @@ -106,38 +106,6 @@ def store
end
end

# Represents decision if smt is enabled
class SdCpuMitigationsWidget < CpuMitigationsWidget
include SystemdBootHelper

def init
if systemdboot.respond_to?(:cpu_mitigations)
self.value = systemdboot.cpu_mitigations.value.to_s
else
# do not crash when use no bootloader. This widget is also used in security dialog.
# (bsc#1184968)
disable
end
end

def store
systemdboot.cpu_mitigations = ::Bootloader::CpuMitigations.new(value.to_sym) if enabled?
end
end

# represents kernel command line
class SdKernelAppendWidget < KernelAppendWidget
include SystemdBootHelper

def init
self.value = systemdboot.kernel_params.serialize.gsub(/mitigations=\S+/, "")
end

def store
systemdboot.kernel_params.replace(value)
end
end

# represents Tab with kernel related configuration
class KernelTab < CWM::Tab
def label
Expand All @@ -149,8 +117,8 @@ def label
def contents
VBox(
VSpacing(1),
MarginBox(1, 0.5, SdKernelAppendWidget.new),
MarginBox(1, 0.5, Left(SdCpuMitigationsWidget.new)),
MarginBox(1, 0.5, KernelAppendWidget.new),
MarginBox(1, 0.5, Left(CpuMitigationsWidget.new)),
VStretch()
)
end
Expand Down
19 changes: 19 additions & 0 deletions src/modules/BootStorage.rb
Expand Up @@ -48,6 +48,7 @@ def main

Yast.import "Arch"
Yast.import "Mode"
Yast.import "Kernel"

# FATE#305008: Failover boot configurations for md arrays with redundancy
# list <string> includes physical disks used for md raid
Expand Down Expand Up @@ -254,6 +255,24 @@ def root_partitions
stage1_partitions_for(root_filesystem)
end

def propose_resume
swap_parts = Yast::BootStorage.available_swap_partitions
largest_swap_name, largest_swap_size = (swap_parts.max_by { |_part, size| size } || [])

propose = Yast::Kernel.propose_hibernation? && largest_swap_name

return "" unless propose

if largest_swap_size < Yast::BootStorage.ram_size
log.info "resume parameter is not added because swap (#{largest_swap_name}) is too small"

return ""
end

# try to use label or udev id for device name... FATE #302219
UdevMapping.to_mountby_device(largest_swap_name)
end

private

def detect_disks
Expand Down

0 comments on commit dc66920

Please sign in to comment.