Skip to content

Commit

Permalink
Merge 939f6b8 into 5d9fc8d
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Mar 7, 2019
2 parents 5d9fc8d + 939f6b8 commit 6c05209
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -31,7 +31,7 @@ Metrics/ClassLength:

# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 200
Max: 220
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Expand Down
7 changes: 7 additions & 0 deletions package/yast2-bootloader.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Mar 7 13:36:20 UTC 2019 - jreidinger@suse.com

- Add option to Disable Simultaneous Multithreading (bsc#1098559)
- Allow to modify bootloader configuration during upgrade
- 4.1.21

-------------------------------------------------------------------
Fri Mar 1 06:16:50 UTC 2019 - jreidinger@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 4.1.20
Version: 4.1.21
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 2 additions & 0 deletions src/autoyast-rnc/bootloader.rnc
Expand Up @@ -71,6 +71,7 @@ bl_global =
boot_extended? &
boot_mbr? &
stage1_dev? &
smt? &
element vgamode { text }?
}

Expand All @@ -85,6 +86,7 @@ boot_root = element boot_root { "true" | "false" }
boot_boot = element boot_boot { "true" | "false" }
boot_extended = element boot_extended { "true" | "false" }
boot_mbr = element boot_mbr { "true" | "false" }
smt = element smt { "true" | "false" }

sections =
element sections {
Expand Down
27 changes: 15 additions & 12 deletions src/lib/bootloader/autoyast_converter.rb
Expand Up @@ -37,6 +37,7 @@ def import(data)
# always nil pmbr as autoyast does not support it yet,
# so use nil to always use proposed value (bsc#1081967)
bootloader.pmbr_action = nil
bootloader.smt = data["global"]["smt"] == "true" unless data["global"]["smt"].nil?
# TODO: import Initrd

log.warn "autoyast profile contain sections which won't be processed" if data["sections"]
Expand All @@ -56,6 +57,7 @@ def export(config)
global = res["global"]
export_grub2(global, config) if config.name == "grub2"
export_default(global, config.grub_default)
res["global"]["smt"] = config.smt ? "true" : "false"
# Do not export device map as device name are very unpredictable and is used only as
# work-around when automatic ones do not work for what-ever reasons ( it can really safe
# your day in L3 )
Expand All @@ -77,6 +79,14 @@ def import_grub2(data, bootloader)
end

def import_default(data, default)
# import first kernel params as smt can later modify it
DEFAULT_KERNEL_PARAMS_MAPPING.each do |key, method|
val = data["global"][key]
next unless val

default.public_send(method).replace(val)
end

DEFAULT_BOOLEAN_MAPPING.each do |key, method|
val = data["global"][key]
next unless val
Expand All @@ -98,13 +108,6 @@ def import_default(data, default)
default.public_send(:"#{method}=", val.split.map { |v| v.to_sym })
end

DEFAULT_KERNEL_PARAMS_MAPPING.each do |key, method|
val = data["global"][key]
next unless val

default.public_send(method).replace(val)
end

import_timeout(data, default)
end

Expand Down Expand Up @@ -235,6 +238,11 @@ def export_default(res, default)
res[key] = val.enabled? ? "true" : "false" if val.defined?
end

DEFAULT_KERNEL_PARAMS_MAPPING.each do |key, method|
val = default.public_send(method)
res[key] = val.serialize unless val.empty?
end

DEFAULT_STRING_MAPPING.each do |key, method|
val = default.public_send(method)
res[key] = val.to_s if val
Expand All @@ -245,11 +253,6 @@ def export_default(res, default)
res[key] = val.join(" ") if val
end

DEFAULT_KERNEL_PARAMS_MAPPING.each do |key, method|
val = default.public_send(method)
res[key] = val.serialize unless val.empty?
end

export_timeout(res, default)
end

Expand Down
32 changes: 31 additions & 1 deletion src/lib/bootloader/grub2_widgets.rb
Expand Up @@ -112,6 +112,34 @@ def store
end
end

# Represents decision if smt is enabled
class Smt < CWM::CheckBox
include Grub2Widget

def initialize
textdomain "bootloader"
end

def label
_("Disable Simultaneous &Multithreading")
end

def help
_(
"<p><b>Disable Simultaneous Multithreading</b><br>\n" \
"To disable sharing physical cores by more virtual ones."
)
end

def init
self.value = !grub2.smt
end

def store
grub2.smt = !value
end
end

# Represents decision if generic MBR have to be installed on disk
class GenericMBRWidget < CWM::CheckBox
include Grub2Widget
Expand Down Expand Up @@ -212,7 +240,7 @@ def help
end

def init
self.value = grub_default.kernel_params.serialize
self.value = grub_default.kernel_params.serialize.gsub(/nosmt/, "")
end

def store
Expand Down Expand Up @@ -844,9 +872,11 @@ def label

def contents
console_widget = Yast::Arch.s390 ? CWM::Empty.new("console") : ConsoleWidget.new
smt_widget = Yast::Arch.x86_64 ? MarginBox(1, 0.5, Smt.new) : CWM::Empty.new("smt")
VBox(
VSpacing(1),
MarginBox(1, 0.5, KernelAppendWidget.new),
Left(smt_widget),
MarginBox(1, 0.5, console_widget),
VStretch()
)
Expand Down
33 changes: 29 additions & 4 deletions src/lib/bootloader/grub2base.rb
Expand Up @@ -54,6 +54,7 @@ def initialize
@grub_default = ::CFA::Grub2::Default.new
@sections = ::Bootloader::Sections.new
@pmbr_action = :nothing
@smt = nil # nil means not set explicitly, otherwise boolean
end

# general functions
Expand All @@ -74,6 +75,26 @@ def pmbr_setup(*devices)
end
end

def smt
!grub_default.kernel_params.parameter("nosmt")
end

def explicit_smt
@smt
end

def smt=(value)
log.info "setting smt to #{value}"
@smt = value

if value
matcher = CFA::Matcher.new(key: "nosmt")
grub_default.kernel_params.remove_parameter(matcher)
elsif !grub_default.kernel_params.parameter("nosmt")
grub_default.kernel_params.add_parameter("nosmt", true)
end
end

def read
super

Expand Down Expand Up @@ -192,13 +213,13 @@ def merge_password(other)

def merge_grub_default(other)
default = grub_default
other = other.grub_default
other_default = other.grub_default

log.info "before merge default #{default.inspect}"
log.info "before merge other #{other.inspect}"
log.info "before merge other #{other_default.inspect}"

KERNEL_FLAVORS_METHODS.each do |method|
other_params = other.public_send(method)
other_params = other_default.public_send(method)
default_params = default.public_send(method)
next if other_params.empty?

Expand All @@ -211,7 +232,11 @@ def merge_grub_default(other)
default_params.replace(new_kernel_params)
end

merge_attributes(default, other)
merge_attributes(default, other_default)

# explicitly set smt
self.smt = other.explicit_smt unless other.explicit_smt.nil?
log.info "smt after merge #{smt}"

log.info "after merge default #{default.inspect}"
end
Expand Down
18 changes: 3 additions & 15 deletions src/lib/bootloader/proposal_client.rb
Expand Up @@ -4,6 +4,8 @@
require "bootloader/bootloader_factory"
require "yast2/popup"

Yast.import "BootArch"

module Bootloader
# Proposal client for bootloader configuration
class ProposalClient < ::Installation::ProposalClient
Expand Down Expand Up @@ -88,18 +90,6 @@ def make_proposal(attrs)
end

def ask_user(param)
if Yast::Mode.update
current_bl = ::Bootloader::BootloaderFactory.current

# we upgrading grub2, so no change there
if grub2_update?(current_bl)
::Yast2::Popup.show(
# TRANSLATORS: popup text when user click on link and we forbid to continue
_("Changing the bootloader configuration during an upgrade is not supported.")
)
return { "workflow_sequence" => :cancel }
end
end
chosen_id = param["chosen_id"]
result = :next
log.info "ask user called with #{chosen_id}"
Expand Down Expand Up @@ -212,7 +202,7 @@ def propose_for_update(force_reset)

if grub2_update?(current_bl)
log.info "update of grub2, do not repropose"
return false
Yast::Bootloader.ReadOrProposeIfNeeded
elsif old_bootloader == "none"
log.info "Bootloader not configured, do not repropose"
# blRead just exits for none bootloader
Expand All @@ -233,8 +223,6 @@ def propose_for_update(force_reset)
::Bootloader::BootloaderFactory.current = proposed
end

update_required_packages

true
end

Expand Down
21 changes: 21 additions & 0 deletions src/modules/BootArch.rb
Expand Up @@ -54,6 +54,7 @@ def DefaultKernelParams(resume)
if Arch.i386 || Arch.x86_64 || Arch.aarch64 || Arch.ppc
ret = kernel_cmdline
ret << " resume=#{resume}" unless resume.empty?
ret << propose_smt if Arch.x86_64
ret << " #{features}" unless features.empty?
ret << " quiet"
return ret
Expand Down Expand Up @@ -83,8 +84,28 @@ def ResumeAvailable
Arch.i386 || Arch.x86_64 || Arch.s390
end

SMT_DEFAULT = true
def smt_settings
linuxrc_value = Yast::Linuxrc.value_for("disablesmt")
product_value = ProductFeatures.GetBooleanFeatureWithFallback("globals", "smt", SMT_DEFAULT)
log.info "smt settings: linuxrc #{linuxrc_value.inspect} product #{product_value.inspect}"
# linuxrc cmdline
return linuxrc_value == "0" if !linuxrc_value.nil?

# product features
product_value
end

publish :function => :DefaultKernelParams, :type => "string (string)"
publish :function => :ResumeAvailable, :type => "boolean ()"

private

DISABLE_SMT = " nosmt".freeze

def propose_smt
smt_settings ? "" : DISABLE_SMT
end
end

BootArch = BootArchClass.new
Expand Down
3 changes: 2 additions & 1 deletion test/autoyast_converter_test.rb
Expand Up @@ -121,7 +121,8 @@
"os_prober" => "true",
"hiddenmenu" => "true",
"timeout" => 10,
"trusted_grub" => "true"
"trusted_grub" => "true",
"smt" => "true"
}

expect(subject.export(bootloader)["global"]).to eq expected_export
Expand Down
21 changes: 0 additions & 21 deletions test/bootloader_proposal_client_test.rb
Expand Up @@ -84,16 +84,6 @@

subject.ask_user({})
end

it "shows unsupported popup when upgrading from grub2 (bsc#1070233)" do
allow(Yast::Mode).to receive(:update).and_return(true)

expect(subject).to receive("old_bootloader").and_return("grub2")

expect(Yast::Bootloader).to_not receive(:Export)
expect(Yast2::Popup).to receive(:show)
subject.ask_user({})
end
end
end

Expand Down Expand Up @@ -180,17 +170,6 @@
subject.make_proposal({})
end

it "propose no change if old bootloader is grub2" do
allow(Yast::Mode).to receive(:update).and_return(true)

expect(subject).to receive("old_bootloader").and_return("grub2")

expect(Yast::Bootloader).to_not receive(:Propose)
expect(Yast::Bootloader).to_not receive(:Read)

expect(subject.make_proposal({})).to eq("raw_proposal" => ["do not change"])
end

it "always resets if storage changed" do
expect(Yast::Bootloader).to receive(:Reset)
allow(Yast::BootStorage).to receive(:storage_changed?).and_return(true)
Expand Down
2 changes: 1 addition & 1 deletion test/grub2base_test.rb
Expand Up @@ -117,7 +117,7 @@
end
end

context "when Product explicitelly disable os prober" do
context "when Product explicitly disable os prober" do
before do
allow(Yast::ProductFeatures).to receive(:GetBooleanFeature).and_return(true)
end
Expand Down

0 comments on commit 6c05209

Please sign in to comment.