Skip to content

Commit

Permalink
Merge 2d319a9 into 9eb182a
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Apr 24, 2020
2 parents 9eb182a + 2d319a9 commit be52e8e
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/lib/y2storage/encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ def in_network?

# Options that must be propagated from the fstab entries of the mount points
# to the crypttab entries of the corresponding device
OPTIONS_TO_PROPAGATE = ["_netdev", "noauto", "nofail"]
private_constant :OPTIONS_TO_PROPAGATE
OPTIONS_TO_PROPAGATE = {
"_netdev" => "_netdev",
"noauto" => "noauto",
"nofail" => "nofail",
"x-initrd.mount" => "x-initrd.attach"
}
ROOTFS_OPTIONS_TO_ADD = ["x-initrd.attach"]
private_constant :OPTIONS_TO_PROPAGATE, :ROOTFS_OPTIONS_TO_ADD

# Synchronizes {#crypt_options} with the {MountPoint#mount_options} of the
# mount points associated to this encryption device
Expand All @@ -349,8 +355,13 @@ def adjust_crypt_options
# Moreover, libstorage-ng currently enforces that behavior.
mount_points = descendants.select { |d| d.is?(:filesystem) }.map(&:mount_point).compact

OPTIONS_TO_PROPAGATE.each do |opt|
propagate_mount_option(opt, mount_points)
OPTIONS_TO_PROPAGATE.each_pair do |fstab_opt, crypttab_opt|
propagate_mount_option(fstab_opt, crypttab_opt, mount_points)
end

ROOTFS_OPTIONS_TO_ADD.each do |crypttab_opt|
is_rootfs = mount_points.any? { |m| m.path == "/" }
propagate_mount_option(nil, crypttab_opt, mount_points) if is_rootfs
end
end

Expand Down Expand Up @@ -402,17 +413,20 @@ def suitable_mount_bys

# @see #adjust_crypt_options
#
# @param option [String] option from fstab and crypttab
# @param fstab_option [String, nil] option from fstab; if nil, crypttab_option
# is always added
# @param crypttab_option [String] option for crypttab
# @param mount_points [Array<MountPoint>] relevant mount points associated
# to the encryption device
def propagate_mount_option(option, mount_points)
in_mount_points = mount_points.all? { |mp| mp.mount_options.include?(option) }
in_encryption = crypt_options.include?(option)
def propagate_mount_option(fstab_option, crypttab_option, mount_points)
in_mount_points = fstab_option.nil? ||
mount_points.all? { |mp| mp.mount_options.include?(fstab_option) }
in_encryption = crypt_options.include?(crypttab_option)

if in_mount_points && !in_encryption
self.crypt_options = crypt_options + [option]
self.crypt_options = crypt_options + [crypttab_option]
elsif !in_mount_points && in_encryption
self.crypt_options = crypt_options - [option]
self.crypt_options = crypt_options - [crypttab_option]
end
end

Expand Down

0 comments on commit be52e8e

Please sign in to comment.