Skip to content

Commit

Permalink
Improve size calculation for automatic LVM PVs
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Oct 8, 2024
1 parent b2a8693 commit 970bebd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/lib/y2storage/planned/can_be_encrypted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ module Planned
module CanBeEncrypted
include SecretAttributes

# This value matches Storage::Luks.metadata_size, which is not exposed in
# This value matches Storage::Luks.v1_metadata_size, which is not exposed in
# the libstorage API
ENCRYPTION_OVERHEAD = DiskSize.MiB(2)
private_constant :ENCRYPTION_OVERHEAD
LUKS1_OVERHEAD = DiskSize.MiB(2)
private_constant :LUKS1_OVERHEAD

# This value matches Storage::Luks.v2_metadata_size, see above
LUKS2_OVERHEAD = DiskSize.MiB(16)
private_constant :LUKS2_OVERHEAD

# @!attribute encryption_method
# @return [EncryptionMethod::Base, nil] method used to encrypt the device. If is nil,
Expand Down Expand Up @@ -152,9 +156,13 @@ module ClassMethods
# I.e. how much smaller will be an encrypted device compared to the plain
# one.
#
# @param type [EncryptionType]
# @return [DiskSize]
def encryption_overhead
ENCRYPTION_OVERHEAD
def encryption_overhead(type = EncryptionType::LUKS1)
return LUKS1_OVERHEAD if type&.is?(:luks1)
return LUKS2_OVERHEAD if type&.is?(:luks2)

DiskSize.zero
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion src/lib/y2storage/planned/lvm_vg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def lvs_weight
#
# @return [DiskSize]
def useless_pv_space
pvs_encrypt? ? USELESS_PV_SPACE + Planned::Partition.encryption_overhead : USELESS_PV_SPACE
pvs_encrypt? ? USELESS_PV_SPACE + encryption_overhead : USELESS_PV_SPACE
end

def substract_reused_vg_size(size)
Expand All @@ -333,6 +333,11 @@ def substract_reused_vg_size(size)
DiskSize.zero
end
end

# @return [DiskSize]
def encryption_overhead
Planned::Partition.encryption_overhead(pvs_encryption_method&.encryption_type)
end
end
end
end

0 comments on commit 970bebd

Please sign in to comment.