]> sourceware.org Git - lvm2.git/commitdiff
Thin add pool_below_threshold
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 8 Feb 2012 13:05:38 +0000 (13:05 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Wed, 8 Feb 2012 13:05:38 +0000 (13:05 +0000)
Test both data and metadata percent usage.

WHATS_NEW
lib/metadata/lv_manip.c
lib/metadata/metadata.h
lib/metadata/thin_manip.c

index 7375f5aafa892e6317a74e63fcb8fa300aa6e0c5..5fed8a70482daedfed0dfd982171f45faf5307aa 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.91 -
 ===================================
+  Add pool_below_threshold() function to check thin pool percent status.
   Fix test for snap percent for failing merge when removing LV.
   Switch int to void return for str_list_del().
   Fix error path handling in _build_desc().
index 252a5563ed7c393f039d385ac3c640c5e56ecc9f..da52e59d925aa8c1b5c2f79dbed6e44a1de5617a 100644 (file)
@@ -4054,7 +4054,6 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l
        struct logical_volume *lv, *org = NULL;
        struct logical_volume *pool_lv;
        struct lv_list *lvl;
-       percent_t percent;
        int origin_active = 0;
        struct lvinfo info;
 
@@ -4375,26 +4374,20 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l
        if (seg_is_thin(lp)) {
                /* For snapshot, suspend active thin origin first */
                if (org && lv_is_active(org)) {
-                       /* Check if the pool is bellow threshold (Works only for active thin) */
-                       if (!lv_thin_pool_percent(first_seg(org)->pool_lv, 0, &percent)) {
-                               stack;
-                               goto revert_new_lv;
-                       }
-                       percent /= PERCENT_1;
-                       if (percent >= (find_config_tree_int(cmd, "activation/thin_pool_autoextend_threshold",
-                                                            DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD))) {
-                               log_error("Failed to create snapshot, pool is filled over "
-                                         "the autoextend threshold (%d%%).", percent);
+                       if (!pool_below_threshold(first_seg(first_seg(org)->pool_lv))) {
+                               log_error("Cannot create thin snapshot. Pool %s/%s is filled "
+                                         "over the autoextend threshold.",
+                                         org->vg->name, first_seg(org)->pool_lv->name);
                                goto revert_new_lv;
                        }
                        if (!suspend_lv_origin(cmd, org)) {
-                               log_error("Failed to suspend thin snapshot origin %s.",
-                                         org->name);
+                               log_error("Failed to suspend thin snapshot origin %s/%s.",
+                                         org->vg->name, org->name);
                                goto revert_new_lv;
                        }
                        if (!resume_lv_origin(cmd, org)) { /* deptree updates thin-pool */
-                               log_error("Failed to resume thin snapshot origin %s.",
-                                         org->name);
+                               log_error("Failed to resume thin snapshot origin %s/%s.",
+                                         org->vg->name, org->name);
                                goto revert_new_lv;
                        }
                        /* At this point remove pool messages, snapshot is active */
index bdac68302352adedc794702145dae8d067cb27cf..be9b92cc37cf5dc968bdd5fa91cb4bf215213ad3 100644 (file)
@@ -464,6 +464,7 @@ int attach_pool_message(struct lv_segment *pool_seg, dm_thin_message_t type,
                        int auto_increment);
 int pool_has_message(const struct lv_segment *seg,
                     const struct logical_volume *lv, uint32_t device_id);
+int pool_below_threshold(const struct lv_segment *pool_seg);
 int extend_pool(struct logical_volume *lv, const struct segment_type *segtype,
                struct alloc_handle *ah, uint32_t stripes, uint32_t stripe_size);
 
index 4eaf3594c0cfc8f7f0bd725a28cebfc09be035de..9644ba0a1c74612f99b1d4018a26a3f3f9511d90 100644 (file)
@@ -19,6 +19,7 @@
 #include "segtype.h"
 #include "lv_alloc.h"
 #include "archiver.h"
+#include "defaults.h"
 
 int attach_pool_metadata_lv(struct lv_segment *pool_seg, struct logical_volume *metadata_lv)
 {
@@ -215,6 +216,35 @@ int pool_has_message(const struct lv_segment *seg,
        return 0;
 }
 
+int pool_below_threshold(const struct lv_segment *pool_seg)
+{
+       percent_t percent;
+       int threshold = PERCENT_1 *
+               find_config_tree_int(pool_seg->lv->vg->cmd,
+                                    "activation/thin_pool_autoextend_threshold",
+                                    DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD);
+
+       /* Data */
+       if (!lv_thin_pool_percent(pool_seg->lv, 0, &percent)) {
+               stack;
+               return 0;
+       }
+
+       if (percent >= threshold)
+               return 0;
+
+       /* Metadata */
+       if (!lv_thin_pool_percent(pool_seg->lv, 1, &percent)) {
+               stack;
+               return 0;
+       }
+
+       if (percent >= threshold)
+               return 0;
+
+       return 1;
+}
+
 struct lv_segment *find_pool_seg(const struct lv_segment *seg)
 {
        struct lv_segment *pool_seg;
This page took 0.046813 seconds and 5 git commands to generate.