-
Notifications
You must be signed in to change notification settings - Fork 22
Allow to customize how the proposal must handle pre-existing LVs in a reused VG #1421
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72f816f
Fix how volume groups are marked to be reused
ancorgs e7e5000
LvmCreator to raise the proper exception type
ancorgs 2032f6a
Proposal: Improve size calculation of LVM volumes
ancorgs 3b6bc2e
AutoYaST: fix creating new thin volumes in reused pools
ancorgs d7b9e8a
Small responsibility adjustment
ancorgs 6ccfcd0
Proposal: extract LVM space-making part
ancorgs fa21f46
Proposal: Separate LvmSpaceStrategies
ancorgs bb2c567
Documentation improvements from code review
ancorgs ac63913
Version and changelog
ancorgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Copyright (c) [2026] SUSE LLC | ||
| # | ||
| # All Rights Reserved. | ||
| # | ||
| # This program is free software; you can redistribute it and/or modify it | ||
| # under the terms of version 2 of the GNU General Public License as published | ||
| # by the Free Software Foundation. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| # more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License along | ||
| # with this program; if not, contact SUSE LLC. | ||
| # | ||
| # To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| # find current contact information at www.suse.com. | ||
|
|
||
| require "y2storage/proposal/lvm_space_strategies" | ||
|
|
||
| module Y2Storage | ||
| module Proposal | ||
| # Class to provide free space in a volume group by resizing and deleting pre-existing logical | ||
| # volumes. Analogous to what SpaceMaker does with partitions. | ||
| class LvmSpaceMaker | ||
| include Yast::Logger | ||
|
|
||
| # Strategies to use to find space. Equivalent to the corresponding SpaceMaker strategies. | ||
| STRATEGIES = { | ||
| auto: LvmSpaceStrategies::Auto, | ||
| bigger_resize: LvmSpaceStrategies::BiggerResize | ||
| } | ||
| private_constant :STRATEGIES | ||
|
|
||
| # Constructor | ||
| # | ||
| # @param volume_group [LvmVg] volume group to clean-up | ||
| # @param planned_vg [Planned::LvmVg] planned logical volume | ||
| # @param space_settings [ProposalSpaceSettings, nil] Optional settings. See | ||
| # {LvmCreator#initialize}. | ||
| def initialize(volume_group, planned_vg, space_settings) | ||
|
ancorgs marked this conversation as resolved.
|
||
| @volume_group = volume_group | ||
| @planned_vg = planned_vg | ||
| @space_settings = space_settings | ||
|
|
||
| if STRATEGIES[strategy] | ||
| @strategy_class = STRATEGIES[strategy] | ||
| else | ||
| err_msg = "Unsupported LVM strategy to make space: #{strategy}" | ||
| log.error err_msg | ||
| raise ArgumentError, err_msg | ||
| end | ||
| end | ||
|
|
||
| # Makes space for planned logical volumes | ||
| # | ||
| # This method modifies the volume group received as first argument. | ||
| def provide_space | ||
| log.info "Making space at LVM volume group with strategy #{strategy}" | ||
| log.info "vg: #{@volume_group.name}, planned: #{@planned_vg.inspect}" | ||
| @strategy_class.new(@volume_group, @planned_vg, @space_settings).provide_space | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Id of the strategy to be used | ||
| # | ||
| # @return [Symbol] | ||
| def strategy | ||
| return :auto unless @space_settings | ||
|
|
||
| @space_settings.strategy | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Copyright (c) [2026] SUSE LLC | ||
| # | ||
| # All Rights Reserved. | ||
| # | ||
| # This program is free software; you can redistribute it and/or modify it | ||
| # under the terms of version 2 of the GNU General Public License as published | ||
| # by the Free Software Foundation. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| # more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License along | ||
| # with this program; if not, contact SUSE LLC. | ||
| # | ||
| # To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| # find current contact information at www.suse.com. | ||
|
|
||
| module Y2Storage | ||
| module Proposal | ||
| # Namespace to group all the strategies used by LvmSpaceMaker. | ||
| # | ||
| # There is a strategy to mimic each strategy at SpaceMakerActions. | ||
| module LvmSpaceStrategy | ||
| end | ||
| end | ||
| end | ||
|
|
||
| require "y2storage/proposal/lvm_space_strategies/auto" | ||
| require "y2storage/proposal/lvm_space_strategies/bigger_resize" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Copyright (c) [2017-2026] SUSE LLC | ||
|
joseivanlopez marked this conversation as resolved.
|
||
| # | ||
| # All Rights Reserved. | ||
| # | ||
| # This program is free software; you can redistribute it and/or modify it | ||
| # under the terms of version 2 of the GNU General Public License as published | ||
| # by the Free Software Foundation. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| # more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License along | ||
| # with this program; if not, contact SUSE LLC. | ||
| # | ||
| # To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| # find current contact information at www.suse.com. | ||
|
|
||
| require "y2storage/proposal/lvm_space_strategies/base" | ||
|
|
||
| module Y2Storage | ||
| module Proposal | ||
| module LvmSpaceStrategies | ||
| # Traditional strategy used by the YaST and AutoYaST proposals to make space in a existing LVM | ||
| # volume group | ||
| # | ||
| # The behavior depends on the value of {Planned::LvmVg#make_space_policy}. | ||
| class Auto < Base | ||
| # Makes space for planned logical volumes | ||
| # | ||
| # When making free space, three different policies can be followed: | ||
| # | ||
| # * :needed: remove logical volumes until there's enough space for | ||
| # planned ones. | ||
| # * :remove: remove all logical volumes. | ||
| # * :keep: keep all logical volumes. | ||
| # | ||
| # @see Base#provide_space | ||
| def provide_space | ||
| return if planned_vg.make_space_policy == :keep | ||
|
|
||
| case planned_vg.make_space_policy | ||
| when :needed | ||
| make_space_until_fit | ||
| when :remove | ||
| lvs_to_keep = planned_vg.all_lvs.select(&:reuse?).map(&:reuse_name) | ||
| remove_logical_volumes(lvs_to_keep) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Makes sure the given volume group has enough free extends to allocate | ||
| # all the planned volumes, by deleting the existing logical volumes. | ||
| # | ||
| # This method modifies the volume group received as first argument. | ||
| # | ||
| # FIXME: the current implementation does not guarantee that the freed | ||
| # space is the minimum valid one. | ||
| def make_space_until_fit | ||
| while missing_vg_space > DiskSize.zero | ||
| lv_to_delete = delete_candidate(volume_group.lvm_lvs) | ||
| if lv_to_delete.nil? | ||
| error_msg = "The volume group #{volume_group.vg_name} is not big enough" | ||
| raise NoDiskSpaceError, error_msg | ||
| end | ||
| volume_group.delete_lvm_lv(lv_to_delete) | ||
| end | ||
| end | ||
|
|
||
| # Remove all logical volumes from a volume group | ||
| # | ||
| # This method modifies the volume group received as a first argument. | ||
| # | ||
| # @param lvs_to_keep [Array<String>] name of logical volumes to keep | ||
| def remove_logical_volumes(lvs_to_keep) | ||
| lvs_to_remove = volume_group.all_lvm_lvs.reject { |v| lvs_to_keep.include?(v.name) } | ||
| lvs_to_remove.each { |v| volume_group.delete_lvm_lv(v) } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.