Skip to content

Commit

Permalink
use for resume the biggest mounted swap (bsc#1071354)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 26, 2019
1 parent f8ecba8 commit 0224195
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/modules/BootStorage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ def prep_partitions
def available_swap_partitions
ret = {}

staging.filesystems.select { |f| f.type.is?(:swap) }.each do |swap|
blk_device = swap.blk_devices[0]
ret[blk_device.name] = blk_device.size.to_i / 1024
mounted = Y2Storage::MountPoint.find_by_path(staging, Y2Storage::MountPoint::SWAP_PATH.to_s)
if mounted.empty?
log.info "No mounted swap found, using fallback."
staging.filesystems.select { |f| f.type.is?(:swap) }.each do |swap|
blk_device = swap.blk_devices[0]
ret[blk_device.name] = blk_device.size.to_i / 1024
end
else
log.info "Mounted swap found: #{mounted.inspect}"
mounted.each do |mp|
blk_device = mp.filesystem.blk_devices[0]
ret[blk_device.name] = blk_device.size.to_i / 1024
end
end

log.info "Available swap partitions: #{ret}"
Expand Down
7 changes: 7 additions & 0 deletions test/boot_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"/dev/mapper/cr_swap" => 2_095_104
)
end

it "returns only mounted swaps if it is available" do
devicegraph_stub("multi_swap.yaml")
expect(subject.available_swap_partitions).to eq(
"/dev/sdb2" => 1_026_048
)
end
end

describe ".encrypted_boot?" do
Expand Down
45 changes: 45 additions & 0 deletions test/data/multi_swap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
- disk:
name: /dev/sda
size: 800 GiB
partition_table: gpt
partitions:

- partition:
size: 5 GiB
name: /dev/sda1
id: swap
file_system: swap

- partition:
size: unlimited
name: /dev/sda2
file_system: btrfs
mount_point: /home

- disk:
name: /dev/sdb
size: 8 GiB
partition_table: gpt
partitions:

- partition:
size: 1 MiB
name: /dev/sdb1
id: bios_boot
file_system: vfat
uuid: 3de29985-8cc6-4c9d-8562-2ede26b0c5b6

- partition:
size: 1002 MiB
name: /dev/sdb2
id: swap
file_system: swap
mount_point: swap
uuid: ec8e9948-ca5f-4b18-a863-ac999365e4a9

- partition:
size: unlimited
name: /dev/sdb3
file_system: btrfs
mount_point: /

0 comments on commit 0224195

Please sign in to comment.