From 0e0f706f2ed0aa8dd7c2f65a467cefa355a0495d Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 21 Dec 2011 13:10:52 +0000 Subject: [PATCH] Thin automatic policy based extension --- doc/example.conf.in | 19 +++++++++++++++++++ lib/config/defaults.h | 2 ++ tools/lvresize.c | 44 ++++++++++++++++++++++++++++++------------- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/doc/example.conf.in b/doc/example.conf.in index 3868c149f..ee78deab2 100644 --- a/doc/example.conf.in +++ b/doc/example.conf.in @@ -603,6 +603,25 @@ activation { snapshot_autoextend_threshold = 100 snapshot_autoextend_percent = 20 + # 'thin_pool_autoextend_threshold' and 'thin_pool_autoextend_percent' define + # how to handle automatic pool extension. The former defines when the + # pool should be extended: when its space usage exceeds this many + # percent. The latter defines how much extra space should be allocated for + # the pool, in percent of its current size. + # + # For example, if you set thin_pool_autoextend_threshold to 70 and + # thin_pool_autoextend_percent to 20, whenever a pool exceeds 70% usage, + # it will be extended by another 20%. For a 1G pool, using up 700M will + # trigger a resize to 1.2G. When the usage exceeds 840M, the pool will + # be extended to 1.44G, and so on. + # + # Setting thin_pool_autoextend_threshold to 100 disables automatic + # extensions. The minimum value is 50 (A setting below 50 will be treated + # as 50). + + thin_pool_autoextend_threshold = 100 + thin_pool_autoextend_percent = 20 + # While activating devices, I/O to devices being (re)configured is # suspended, and as a precaution against deadlocks, LVM2 needs to pin # any memory it is using so it is not paged out. Groups of pages that diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 374ab3dd9..a22d25e6a 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -170,5 +170,7 @@ #define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate" #define DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD 100 #define DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT 20 +#define DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD 100 +#define DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT 20 #endif /* _LVM_DEFAULTS_H */ diff --git a/tools/lvresize.c b/tools/lvresize.c index 20ea366a4..9fc56e076 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -285,23 +285,40 @@ static int _adjust_policy_params(struct cmd_context *cmd, percent_t percent; int policy_threshold, policy_amount; - policy_threshold = - find_config_tree_int(cmd, "activation/snapshot_autoextend_threshold", - DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD) * PERCENT_1; - policy_amount = - find_config_tree_int(cmd, "activation/snapshot_autoextend_percent", - DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT); + if (lv_is_thin_pool(lv)) { + policy_threshold = + find_config_tree_int(cmd, "activation/thin_pool_autoextend_threshold", + DEFAULT_THIN_POOL_AUTOEXTEND_THRESHOLD) * PERCENT_1; + policy_amount = + find_config_tree_int(cmd, "activation/thin_pool_autoextend_percent", + DEFAULT_THIN_POOL_AUTOEXTEND_PERCENT); + } else { + policy_threshold = + find_config_tree_int(cmd, "activation/snapshot_autoextend_threshold", + DEFAULT_SNAPSHOT_AUTOEXTEND_THRESHOLD) * PERCENT_1; + policy_amount = + find_config_tree_int(cmd, "activation/snapshot_autoextend_percent", + DEFAULT_SNAPSHOT_AUTOEXTEND_PERCENT); + } if (policy_threshold >= PERCENT_100) return 1; /* nothing to do */ - if (!lv_snapshot_percent(lv, &percent)) - return_0; - - if (!(PERCENT_0 < percent && percent < PERCENT_100) || percent <= policy_threshold) - return 1; /* nothing to do */ + if (lv_is_thin_pool(lv)) { + if (!lv_thin_pool_percent(lv, &percent)) + return_0; + if (!(PERCENT_0 < percent && percent <= PERCENT_100) || + percent <= policy_threshold) + return 1; /* nothing to do */ + } else { + if (!lv_snapshot_percent(lv, &percent)) + return_0; + if (!(PERCENT_0 < percent && percent < PERCENT_100) || percent <= policy_threshold) + return 1; /* nothing to do */ + } lp->extents = policy_amount; + return 1; } @@ -399,8 +416,9 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg, lv = lvl->lv; if (use_policy) { - if (!lv_is_cow(lv)) { - log_error("Can't use policy-based resize for non-snapshot volumes."); + if (!lv_is_cow(lv) && + !lv_is_thin_pool(lv)) { + log_error("Policy-based resize is supported only for snapshot and thin pool volumes."); return ECMD_FAILED; } _adjust_policy_params(cmd, lv, lp);