]> sourceware.org Git - lvm2.git/commitdiff
lv_manip: ensure it will fit bellow threshold
authorZdenek Kabelac <zkabelac@redhat.com>
Sun, 25 Oct 2015 18:19:39 +0000 (19:19 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Sun, 25 Oct 2015 20:03:11 +0000 (21:03 +0100)
Use single code to evaluate if the percentage value has
crossed threshold.

Recalculate amount value to always fit bellow
threshold so there are not need any extra reiterations
to reach this state in case policy amount is too small.

WHATS_NEW
lib/metadata/lv_manip.c

index 0495e4683fc3c43df86f034ab62ba24db1c07346..8ca0aa7f50d0391d9be974946accba272a8a56d2 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.133 - 
 ======================================
+  Ensure --use-policy will resize volume to fit below threshold.
   Correct percentage evaluation when checking thin-pool over threshold.
   Fix lvmcache to move PV from VG to orphans if VG is removed and lvmetad used.
   Fix lvmcache to not cache even invalid info about PV which got removed.
index 19032e9b23743e137e55e67ad33c17ec6d343960..8029dabf5dea74b736cfc5330759cb457ec918fe 100644 (file)
@@ -4424,6 +4424,25 @@ static int _fsadm_cmd(struct cmd_context *cmd,
        return exec_cmd(cmd, argv, status, 1);
 }
 
+static int _adjust_amount(dm_percent_t percent, int policy_threshold, int *policy_amount)
+{
+       if (!(DM_PERCENT_0 < percent && percent <= DM_PERCENT_100) ||
+           percent <= (policy_threshold * DM_PERCENT_1))
+               return 0;
+       /*
+        * Evaluate the minimal amount needed to get bellow threshold.
+        * Keep using DM_PERCENT_1 units for better precision.
+        * Round-up to needed percentage value
+        */
+       percent = (percent/policy_threshold + (DM_PERCENT_1 - 1) / 100) / (DM_PERCENT_1 / 100) - 100;
+
+       /* Use it if current policy amount is smaller */
+       if (*policy_amount < percent)
+               *policy_amount = percent;
+
+       return 1;
+}
+
 static int _adjust_policy_params(struct cmd_context *cmd,
                                 struct logical_volume *lv, struct lvresize_params *lp)
 {
@@ -4469,35 +4488,29 @@ static int _adjust_policy_params(struct cmd_context *cmd,
                return 0;
        }
 
-       policy_threshold *= DM_PERCENT_1;
-
        if (lv_is_thin_pool(lv)) {
                if (!lv_thin_pool_percent(lv, 1, &percent))
                        return_0;
-               if ((DM_PERCENT_0 < percent && percent <= DM_PERCENT_100) &&
-                   (percent > policy_threshold)) {
+               if (_adjust_amount(percent, policy_threshold, &policy_amount)) {
                        if (!thin_pool_feature_supported(lv, THIN_FEATURE_METADATA_RESIZE)) {
-                               log_error_once("Online metadata resize for %s/%s is not supported.",
-                                              lv->vg->name, lv->name);
+                               log_error_once("Online metadata resize for %s is not supported.",
+                                              display_lvname(lv));
                                return 0;
                        }
                        lp->poolmetadatasize = (first_seg(lv)->metadata_lv->size *
                                                policy_amount + 99) / 100;
                        lp->poolmetadatasign = SIGN_PLUS;
                }
-
                if (!lv_thin_pool_percent(lv, 0, &percent))
                        return_0;
-               if (!(DM_PERCENT_0 < percent && percent <= DM_PERCENT_100) ||
-                   percent <= policy_threshold)
-                       return 1;
        } else {
                if (!lv_snapshot_percent(lv, &percent))
                        return_0;
-               if (!(DM_PERCENT_0 < percent && percent <= DM_PERCENT_100) || percent <= policy_threshold)
-                       return 1; /* nothing to do */
        }
 
+       if (!_adjust_amount(percent, policy_threshold, &policy_amount))
+               return 1; /* nothing to do */
+
        lp->extents = policy_amount;
        lp->sizeargs = (lp->extents) ? 1 : 0;
 
This page took 0.062291 seconds and 5 git commands to generate.