From afb4290111b67b5abb2cb75e543f3605f605b92b Mon Sep 17 00:00:00 2001
From: Zdenek Kabelac <zkabelac@redhat.com>
Date: Fri, 18 Jan 2019 22:27:02 +0100
Subject: [PATCH 01/17] lv_manip: better work with PERCENT_VG modifier
When using 'lvcreate -l100%VG' and there is big disproportion between
real available space and requested setting - automatically fallback
to 100%FREE.
Difference can be seen when VG is big and already most space was
allocated, so the requestion 100%VG can end (and by spec for % modifier
it's correct) as LV with size of 1%VG. Usually this is not a big
problem - buit in some cases - like cache-pool allocation, this
can result a big difference for chunksize selection.
With this patch it's more closely match common-sense logic without
the need of reitteration of too big changes in lvm2 core ATM.
TODO: in the future there should be allocator solving all allocations
in a single call.
(cherry picked from commit 022ebb0cfebee4ac8fdbe4e0c61e85db1038a115)
Conflicts:
WHATS_NEW
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 6 ++++++
tools/lvcreate.c | 6 ++++++
3 files changed, 13 insertions(+)
diff --git a/WHATS_NEW b/WHATS_NEW
index f429d27..152fa5e 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.03 -
====================================
+ Improve -lXXX%VG modifier which improves cache segment estimation.
Ensure migration_threshold for cache is at least 8 chunks.
Move VDO support towards V2 target (6.2) support.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 9794074..0c54b2c 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5022,6 +5022,12 @@ static int _lvresize_extents_from_percent(const struct logical_volume *lv,
case PERCENT_VG:
lp->extents = percent_of_extents(lp->extents, vg->extent_count,
(lp->sign != SIGN_MINUS));
+ if (lp->sign == SIGN_NONE && lp->extents > vg->free_count) {
+ lp->extents = vg->free_count;
+ log_print_unless_silent("Reducing %u%%VG to remaining free space %s in VG.",
+ old_extents,
+ display_size(vg->cmd, (uint64_t)vg->extent_size * lp->extents));
+ }
break;
case PERCENT_FREE:
lp->extents = percent_of_extents(lp->extents, vg->free_count,
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 3c22794..ebe51d9 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -278,6 +278,12 @@ static int _update_extents_params(struct volume_group *vg,
switch (lcp->percent) {
case PERCENT_VG:
extents = percent_of_extents(lp->extents, base_calc_extents = vg->extent_count, 0);
+ if (extents > vg->free_count) {
+ extents = vg->free_count;
+ log_print_unless_silent("Reducing %u%%VG to remaining free space %s in VG.",
+ lp->extents,
+ display_size(vg->cmd, (uint64_t)vg->extent_size * extents));
+ }
break;
case PERCENT_FREE:
extents = percent_of_extents(lp->extents, base_calc_extents = vg->free_count, 0);
--
1.8.3.1