Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scheduler activation (bsc#1052770) #27

Merged
merged 1 commit into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-tune.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Aug 14 18:19:47 UTC 2017 - lslezak@suse.cz

- Fixed scheduler activation: do not activate the new scheduler
for devices which do not support it (bsc#1052770)
- 3.3.0

-------------------------------------------------------------------
Fri Jan 20 16:21:30 UTC 2017 - mvidner@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-tune.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-tune
Version: 3.2.0
Version: 3.3.0
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
27 changes: 27 additions & 0 deletions src/modules/SystemSettings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,38 @@ def activate_scheduler
# activate the scheduler for all disk devices
return if new_elevator == :missing
Dir["/sys/block/*/queue/scheduler"].each do |f|
# skip devices which do not support the selected scheduler,
# keep the original scheduler
next unless device_supports_scheduler(f, new_elevator)

log.info("Activating scheduler '#{new_elevator}' for device #{f}")
File.write(f, new_elevator)
end
end

# read available schedulers for the device
# @param device [String] path to device scheduler file
# @return [Array<String>] read schedulers from the file
def read_device_schedulers(device)
schedulers = File.read(device).split(/\s+/).map do |sched|
# remove the current scheduler marks [] around the name
sched[0] == "[" && sched [-1] == "]" ? sched[1..-2] : sched
end

log.info("Available schedulers for #{device}: #{schedulers}")

schedulers
end

# does the device support support the scheduler?
# @param device [String] path to device scheduler file
# @param scheduler [String] name of the requested scheduler
# @return [Boolean] true if supported
def device_supports_scheduler(device, scheduler)
schedulers = read_device_schedulers(device)
schedulers.include?(scheduler)
end

# Read IO scheduler configuration updating the module's value
#
# @see Read
Expand Down
15 changes: 14 additions & 1 deletion test/system_settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@
let(:sysrq_keys) { false }
let(:scheduler) { "" }
let(:disk) { "/sys/block/sda/queue/scheduler" }
let(:disk2) { "/sys/block/sdb/queue/scheduler" }

before do
settings.SetSysRqKeysEnabled(sysrq_keys)
settings.SetIOScheduler(scheduler)
allow(Yast::Bootloader).to receive(:modify_kernel_params)
allow(Yast::Bootloader).to receive(:proposed_cfg_changed=)
allow(Dir).to receive(:[]).with(/scheduler/).and_return([disk])
allow(Dir).to receive(:[]).with(/scheduler/).and_return([disk, disk2])
end

context "when SysRq keys status is unknown" do
Expand Down Expand Up @@ -161,6 +162,8 @@

before do
allow(File).to receive(:write).with(KERNEL_SYSRQ_FILE, anything)
allow(File).to receive(:read).with(disk).and_return("noop deadline [cfq]")
allow(File).to receive(:read).with(disk2).and_return("noop deadline [cfq]")
end

it "updates bootloader configuration" do
Expand All @@ -173,6 +176,16 @@

it "activates scheduler for all disk devices" do
expect(File).to receive(:write).with(disk, scheduler)
expect(File).to receive(:write).with(disk2, scheduler)
settings.Activate
end

it "does not activate the scheduler if the device does not support it" do
# make the "cfq" scheduler unsupported
expect(File).to receive(:read).with(disk2).and_return("[mq-deadline] none")
expect(File).to receive(:write).with(disk, scheduler)
# ensure it is not changed
expect(File).to_not receive(:write).with(disk2, scheduler)
settings.Activate
end
end
Expand Down