From 8a1ef2121512697fbc946877bfcfca40f3c39d42 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 31 Jan 2024 10:14:13 +0100 Subject: [PATCH 01/11] Handling of YAST_REUSE_LVM linuxrc option --- src/lib/y2storage/proposal/lvm_helper.rb | 9 +++++---- src/lib/y2storage/proposal_settings.rb | 1 + src/lib/y2storage/storage_env.rb | 12 ++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/y2storage/proposal/lvm_helper.rb b/src/lib/y2storage/proposal/lvm_helper.rb index b32bed229..25995cc04 100644 --- a/src/lib/y2storage/proposal/lvm_helper.rb +++ b/src/lib/y2storage/proposal/lvm_helper.rb @@ -1,4 +1,4 @@ -# Copyright (c) [2015] SUSE LLC +#eCopyright (c) [2015] SUSE LLC # # All Rights Reserved. # @@ -21,6 +21,7 @@ require "y2storage/disk_size" require "y2storage/exceptions" require "y2storage/planned/lvm_vg" +require "y2storage/storage_env" module Y2Storage module Proposal @@ -166,9 +167,9 @@ def new_volume_group # @return [Boolean] def try_to_reuse? # Setting introduced to completely avoid LVM reusing in D-Installer. - # It's a new playground, so no need to carry YaST behaviors that have - # proven to be confusing. - return false if settings.lvm_vg_reuse == false + # However it happened to be handy even in old yast later on. Preset + # settings can get overwritten by Linuxrc boot param. + return false if StorageEnv.instance.reuse_lvm? == false || settings.lvm_vg_reuse == false # We introduced this when we still didn't have a mechanism to activate # existing LUKS. Now such mechanism exists but this check has never been diff --git a/src/lib/y2storage/proposal_settings.rb b/src/lib/y2storage/proposal_settings.rb index df50dff65..7d181dc1b 100644 --- a/src/lib/y2storage/proposal_settings.rb +++ b/src/lib/y2storage/proposal_settings.rb @@ -414,6 +414,7 @@ def load_features load_feature(:proposal, :other_delete_mode) load_feature(:proposal, :delete_resize_configurable) load_feature(:proposal, :lvm_vg_strategy) + load_feature(:proposal, :lvm_vg_reuse) load_feature(:proposal, :allocate_volume_mode) load_feature(:proposal, :multidisk_first) load_size_feature(:proposal, :lvm_vg_size) diff --git a/src/lib/y2storage/storage_env.rb b/src/lib/y2storage/storage_env.rb index c1064876f..06ca02c9c 100644 --- a/src/lib/y2storage/storage_env.rb +++ b/src/lib/y2storage/storage_env.rb @@ -36,8 +36,11 @@ class StorageEnv ENV_LIBSTORAGE_IGNORE_PROBE_ERRORS = "LIBSTORAGE_IGNORE_PROBE_ERRORS".freeze + ENV_REUSE_LVM = "YAST_REUSE_LVM".freeze + private_constant :ENV_MULTIPATH, :ENV_BIOS_RAID, :ENV_ACTIVATE_LUKS, :ENV_LUKS2_AVAILABLE private_constant :ENV_LIBSTORAGE_IGNORE_PROBE_ERRORS + private_constant :ENV_REUSE_LVM def initialize reset_cache @@ -89,6 +92,15 @@ def luks2_available? active?(ENV_LUKS2_AVAILABLE, default: false) end + # Whether YaST should reuse existing LVM + # + # see jsc#PED-6407 or jsc#IBM-1315 + # + # @return [Boolean] + def reuse_lvm? + active?(ENV_REUSE_LVM, default: true) + end + # Whether errors during libstorage probing should be ignored. # # See bsc#1177332: From ebd05a52068e7cfd36148d12467cda45f7b64fd2 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Thu, 1 Feb 2024 10:57:23 +0100 Subject: [PATCH 02/11] Happy rubocop --- src/lib/y2storage/proposal/lvm_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/y2storage/proposal/lvm_helper.rb b/src/lib/y2storage/proposal/lvm_helper.rb index 25995cc04..6beedb262 100644 --- a/src/lib/y2storage/proposal/lvm_helper.rb +++ b/src/lib/y2storage/proposal/lvm_helper.rb @@ -1,4 +1,4 @@ -#eCopyright (c) [2015] SUSE LLC +# Copyright (c) [2015] SUSE LLC # # All Rights Reserved. # From 9fe9f4eba863d5c930a6331ad0fac34e105840b6 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Fri, 2 Feb 2024 08:42:55 +0100 Subject: [PATCH 03/11] Relocated default setup of lvm reuse flag --- src/lib/y2storage/proposal/lvm_helper.rb | 4 +--- src/lib/y2storage/proposal_settings.rb | 9 +++++++++ src/lib/y2storage/storage_env.rb | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/y2storage/proposal/lvm_helper.rb b/src/lib/y2storage/proposal/lvm_helper.rb index 6beedb262..771755356 100644 --- a/src/lib/y2storage/proposal/lvm_helper.rb +++ b/src/lib/y2storage/proposal/lvm_helper.rb @@ -167,9 +167,7 @@ def new_volume_group # @return [Boolean] def try_to_reuse? # Setting introduced to completely avoid LVM reusing in D-Installer. - # However it happened to be handy even in old yast later on. Preset - # settings can get overwritten by Linuxrc boot param. - return false if StorageEnv.instance.reuse_lvm? == false || settings.lvm_vg_reuse == false + return false if settings.lvm_vg_reuse == false # We introduced this when we still didn't have a mechanism to activate # existing LUKS. Now such mechanism exists but this check has never been diff --git a/src/lib/y2storage/proposal_settings.rb b/src/lib/y2storage/proposal_settings.rb index 7d181dc1b..84138a352 100644 --- a/src/lib/y2storage/proposal_settings.rb +++ b/src/lib/y2storage/proposal_settings.rb @@ -236,6 +236,7 @@ def self.new_for_current_product def for_current_product apply_defaults load_features + apply_user_enforced end # Produces a deep copy of settings @@ -401,6 +402,14 @@ def apply_defaults end end + # Some values can be explicitly enforced by user + # This setting should have precendence over everything else + def apply_user_enforced + value = StorageEnv.instance.reuse_lvm? + + send(:lvm_vg_reuse, StorageEnv.instance.reuse_lvm?) if !value.nil? + end + # Overrides the settings with values read from the YaST product features # (i.e. values in /control.xml). # diff --git a/src/lib/y2storage/storage_env.rb b/src/lib/y2storage/storage_env.rb index 06ca02c9c..0090a616c 100644 --- a/src/lib/y2storage/storage_env.rb +++ b/src/lib/y2storage/storage_env.rb @@ -96,9 +96,9 @@ def luks2_available? # # see jsc#PED-6407 or jsc#IBM-1315 # - # @return [Boolean] + # @return [Boolean, nil] boolean as explicitly set by user, nil if user set nothing def reuse_lvm? - active?(ENV_REUSE_LVM, default: true) + active?(ENV_REUSE_LVM, default: nil) end # Whether errors during libstorage probing should be ignored. From 9f06c612f2f86653600dafe61353493a896773bd Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Fri, 2 Feb 2024 10:57:05 +0100 Subject: [PATCH 04/11] Cleanup --- src/lib/y2storage/proposal/lvm_helper.rb | 1 - src/lib/y2storage/proposal_settings.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/y2storage/proposal/lvm_helper.rb b/src/lib/y2storage/proposal/lvm_helper.rb index 771755356..3d204c224 100644 --- a/src/lib/y2storage/proposal/lvm_helper.rb +++ b/src/lib/y2storage/proposal/lvm_helper.rb @@ -21,7 +21,6 @@ require "y2storage/disk_size" require "y2storage/exceptions" require "y2storage/planned/lvm_vg" -require "y2storage/storage_env" module Y2Storage module Proposal diff --git a/src/lib/y2storage/proposal_settings.rb b/src/lib/y2storage/proposal_settings.rb index 84138a352..b12b9acd7 100644 --- a/src/lib/y2storage/proposal_settings.rb +++ b/src/lib/y2storage/proposal_settings.rb @@ -29,6 +29,7 @@ require "y2storage/encryption_method" require "y2storage/equal_by_instance_variables" require "y2storage/proposal_space_settings" +require "y2storage/storage_env" module Y2Storage # Class to manage settings used by the proposal (typically read from control.xml) From 66165b2073be4adc44d821d28764ef7d7539ad9b Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Mon, 5 Feb 2024 09:15:25 +0100 Subject: [PATCH 05/11] Minor adaption to ruby standards --- src/lib/y2storage/proposal_settings.rb | 4 ++-- src/lib/y2storage/storage_env.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/y2storage/proposal_settings.rb b/src/lib/y2storage/proposal_settings.rb index b12b9acd7..c8d10b869 100644 --- a/src/lib/y2storage/proposal_settings.rb +++ b/src/lib/y2storage/proposal_settings.rb @@ -406,9 +406,9 @@ def apply_defaults # Some values can be explicitly enforced by user # This setting should have precendence over everything else def apply_user_enforced - value = StorageEnv.instance.reuse_lvm? + value = StorageEnv.instance.requested_lvm_reuse - send(:lvm_vg_reuse, StorageEnv.instance.reuse_lvm?) if !value.nil? + send(:lvm_vg_reuse=, StorageEnv.instance.requested_lvm_reuse) if !value.nil? end # Overrides the settings with values read from the YaST product features diff --git a/src/lib/y2storage/storage_env.rb b/src/lib/y2storage/storage_env.rb index 0090a616c..1fbe00b34 100644 --- a/src/lib/y2storage/storage_env.rb +++ b/src/lib/y2storage/storage_env.rb @@ -97,7 +97,7 @@ def luks2_available? # see jsc#PED-6407 or jsc#IBM-1315 # # @return [Boolean, nil] boolean as explicitly set by user, nil if user set nothing - def reuse_lvm? + def requested_lvm_reuse active?(ENV_REUSE_LVM, default: nil) end From 951ba961fbb7224e19ba21dcb5d6292316298615 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Tue, 6 Feb 2024 09:00:22 +0100 Subject: [PATCH 06/11] Minor refactoring --- src/lib/y2storage/storage_env.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lib/y2storage/storage_env.rb b/src/lib/y2storage/storage_env.rb index 1fbe00b34..a9048f17b 100644 --- a/src/lib/y2storage/storage_env.rb +++ b/src/lib/y2storage/storage_env.rb @@ -98,7 +98,11 @@ def luks2_available? # # @return [Boolean, nil] boolean as explicitly set by user, nil if user set nothing def requested_lvm_reuse - active?(ENV_REUSE_LVM, default: nil) + value = read(ENV_REUSE_LVM) + + return env_str_to_bool(value) if value + + nil end # Whether errors during libstorage probing should be ignored. @@ -118,6 +122,13 @@ def ignore_probe_errors? private + # Takes a string and translates it to bool in a similar way how linuxrc does + def env_str_to_bool(value) + # Similar to what linuxrc does, also consider the flag activated if the + # variable is used with no value or with "1" + value.casecmp?("on") || value.empty? || value == "1" + end + # Whether the env variable is active # # @param variable [String] @@ -128,9 +139,7 @@ def active?(variable, default: false) value = read(variable) result = if value - # Similar to what linuxrc does, also consider the flag activated if the - # variable is used with no value or with "1" - value.casecmp?("on") || value.empty? || value == "1" + env_str_to_bool(value) else default end From 366e6f33e5fe42d62be7f92cce60ab2d942eee03 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 7 Feb 2024 14:18:57 +0100 Subject: [PATCH 07/11] Do not introduce loading lvm_vg_reuse from control file --- src/lib/y2storage/proposal_settings.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/y2storage/proposal_settings.rb b/src/lib/y2storage/proposal_settings.rb index c8d10b869..451ec0f58 100644 --- a/src/lib/y2storage/proposal_settings.rb +++ b/src/lib/y2storage/proposal_settings.rb @@ -424,7 +424,6 @@ def load_features load_feature(:proposal, :other_delete_mode) load_feature(:proposal, :delete_resize_configurable) load_feature(:proposal, :lvm_vg_strategy) - load_feature(:proposal, :lvm_vg_reuse) load_feature(:proposal, :allocate_volume_mode) load_feature(:proposal, :multidisk_first) load_size_feature(:proposal, :lvm_vg_size) From 1f4516e51fe4379959bb06da775ca7433c614dc8 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 14 Feb 2024 09:50:32 +0100 Subject: [PATCH 08/11] Updated the testsuite to cover requested_lvm_reuse --- test/y2storage/storage_env_test.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/y2storage/storage_env_test.rb b/test/y2storage/storage_env_test.rb index 28b55399d..2fd814655 100755 --- a/test/y2storage/storage_env_test.rb +++ b/test/y2storage/storage_env_test.rb @@ -68,4 +68,26 @@ end end end + + describe "#requested_lvm_reuse" do + context "YAST_REUSE_LVM is set to '1'" do + let(:env_vars) do + { "YAST_REUSE_LVM" => "1" } + end + + it "returns true" do + expect(Y2Storage::StorageEnv.instance.requested_lvm_reuse).to be true + end + end + + context "YAST_REUSE_LVM not set" do + let(:env_vars) do + {} + end + + it "returns nil" do + expect(Y2Storage::StorageEnv.instance.requested_lvm_reuse).to be nil + end + end + end end From fd6927348297e114448831bbed7099aa2d0ce8f8 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 14 Feb 2024 10:05:07 +0100 Subject: [PATCH 09/11] Minor code reorganization --- src/lib/y2storage/storage_env.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/y2storage/storage_env.rb b/src/lib/y2storage/storage_env.rb index a9048f17b..0f8037745 100644 --- a/src/lib/y2storage/storage_env.rb +++ b/src/lib/y2storage/storage_env.rb @@ -100,9 +100,9 @@ def luks2_available? def requested_lvm_reuse value = read(ENV_REUSE_LVM) - return env_str_to_bool(value) if value + return nil if !value - nil + env_str_to_bool(value) end # Whether errors during libstorage probing should be ignored. From 6ebb66b233d5ca5bdd428a5c8c1b7fb6edf47019 Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 14 Feb 2024 10:07:52 +0100 Subject: [PATCH 10/11] Minor testsuite update --- test/y2storage/storage_env_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/y2storage/storage_env_test.rb b/test/y2storage/storage_env_test.rb index 2fd814655..8185b8f35 100755 --- a/test/y2storage/storage_env_test.rb +++ b/test/y2storage/storage_env_test.rb @@ -80,6 +80,16 @@ end end + context "YAST_REUSE_LVM is set to '0'" do + let(:env_vars) do + { "YAST_REUSE_LVM" => "0" } + end + + it "returns false" do + expect(Y2Storage::StorageEnv.instance.requested_lvm_reuse).to be false + end + end + context "YAST_REUSE_LVM not set" do let(:env_vars) do {} From eb6aa7d2d784f40b973dabc2371be6bdecf5af1a Mon Sep 17 00:00:00 2001 From: Michal Filka Date: Wed, 14 Feb 2024 10:13:09 +0100 Subject: [PATCH 11/11] Updated changelog --- package/yast2-storage-ng.changes | 8 ++++++++ package/yast2-storage-ng.spec | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package/yast2-storage-ng.changes b/package/yast2-storage-ng.changes index 1cf690ffe..f8b3687ff 100644 --- a/package/yast2-storage-ng.changes +++ b/package/yast2-storage-ng.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Wed Feb 14 09:11:06 UTC 2024 - Michal Filka + +- jsc#PED-6407 + - new env variable YAST_REUSE_LVM for reusing LVM in new + installation. It can be used as linuxrc boot param. +- 4.6.15 + ------------------------------------------------------------------- Wed Oct 11 08:41:15 UTC 2023 - Ancor Gonzalez Sosa diff --git a/package/yast2-storage-ng.spec b/package/yast2-storage-ng.spec index f01312b7b..463e47065 100644 --- a/package/yast2-storage-ng.spec +++ b/package/yast2-storage-ng.spec @@ -16,7 +16,7 @@ # Name: yast2-storage-ng -Version: 4.6.14 +Version: 4.6.15 Release: 0 Summary: YaST2 - Storage Configuration License: GPL-2.0-only OR GPL-3.0-only