master - lvconvert: share function for cache params
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=46820bfff3f40d58d28...
Commit: 46820bfff3f40d58d28500ce9caafb8625211597
Parent: 298d12c4590ccca26b92e1457c72c6369a32d3e9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 27 14:54:08 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
lvconvert: share function for cache params
Reuse same code for getting/setting cache parameters with lvcreate.
So there is single one place how to get vars from profiles and configs.
Variables declarations are moved to start of function and
there is no need to initialize them as they are always
defined by functions get_cache_params() and get_pool_params().
---
WHATS_NEW | 1 +
tools/lvconvert.c | 101 ++++++++++++++--------------------------------------
2 files changed, 28 insertions(+), 74 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 61b01b6..ef3ec3f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.169 -
=====================================
+ Use function cache_set_params() for both lvcreate and lvconvert.
Skip rounding on cache chunk size boudary when create cache LV.
Improve cache_set_params support for chunk_size selection.
Fix metadata profile allocation/cache_[mode|policy] setting.
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 9641a16..7500746 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2680,7 +2680,12 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
uint32_t meta_extents;
uint32_t chunk_size;
int chunk_calc;
+ cache_mode_t cache_mode;
+ const char *policy_name;
struct dm_config_tree *policy_settings = NULL;
+ int pool_metadata_spare;
+ thin_discards_t discards;
+ thin_zero_t zero_new_blocks;
int r = 0;
/* for handling lvmlockd cases */
@@ -2692,7 +2697,6 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
struct id lockd_meta_id;
const char *str_seg_type = to_cachepool ? SEG_TYPE_NAME_CACHE_POOL : SEG_TYPE_NAME_THIN_POOL;
-
if (lv_is_thin_pool(lv) || lv_is_cache_pool(lv)) {
log_error(INTERNAL_ERROR "LV %s is already a pool.", display_lvname(lv));
return 0;
@@ -2786,34 +2790,21 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
}
}
- /*
- * Determine the size of the metadata LV and the chunk size. When an
- * existing LV is to be used for metadata, this introduces some
- * constraints/defaults. When chunk_size=0 and/or meta_extents=0 are
- * passed to the "update params" function, defaults are calculated and
- * returned.
- */
+ if (!get_pool_params(cmd, pool_segtype, &passed_args,
+ &meta_size, &pool_metadata_spare,
+ &chunk_size, &discards, &zero_new_blocks))
+ goto_bad;
- if (arg_is_set(cmd, chunksize_ARG)) {
- passed_args |= PASS_ARG_CHUNK_SIZE;
- chunk_size = arg_uint_value(cmd, chunksize_ARG, 0);
- if (!validate_pool_chunk_size(cmd, pool_segtype, chunk_size))
- return_0;
- } else /* A default will be chosen by the "update" function. */
- chunk_size = 0;
+ if (to_cachepool &&
+ !get_cache_params(cmd, &chunk_size, &cache_mode, &policy_name, &policy_settings))
+ goto_bad;
- if (arg_is_set(cmd, poolmetadatasize_ARG)) {
- meta_size = arg_uint64_value(cmd, poolmetadatasize_ARG, UINT64_C(0));
- meta_extents = extents_from_size(cmd, meta_size, vg->extent_size);
- passed_args |= PASS_ARG_POOL_METADATA_SIZE;
- } else if (metadata_lv) {
+ if (metadata_lv)
meta_extents = metadata_lv->le_count;
- passed_args |= PASS_ARG_POOL_METADATA_SIZE;
- } else /* A default will be chosen by the "update" function. */
- meta_extents = 0;
-
- /* Tell the "update" function to ignore these, they are handled below. */
- passed_args |= PASS_ARG_DISCARDS | PASS_ARG_ZERO;
+ else if (meta_size)
+ meta_extents = extents_from_size(cmd, meta_size, vg->extent_size);
+ else
+ meta_extents = 0; /* A default will be chosen by the "update" function. */
/*
* Validate and/or choose defaults for meta_extents and chunk_size,
@@ -2833,18 +2824,10 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
&meta_extents,
&chunk_calc,
&chunk_size,
- NULL, NULL))
+ &discards, &zero_new_blocks))
goto_bad;
}
- if ((uint64_t)chunk_size > ((uint64_t)lv->le_count * vg->extent_size)) {
- log_error("Pool data LV %s is too small (%s) for specified chunk size (%s).",
- display_lvname(lv),
- display_size(cmd, (uint64_t)lv->le_count * vg->extent_size),
- display_size(cmd, chunk_size));
- goto bad;
- }
-
if (metadata_lv && (meta_extents > metadata_lv->le_count)) {
log_error("Pool metadata LV %s is too small (%u extents) for required metadata (%u extents).",
display_lvname(metadata_lv), metadata_lv->le_count, meta_extents);
@@ -3034,44 +3017,15 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
}
}
- /*
- * Apply settings to the new pool seg, from command line, from
- * defaults, sometimes adjusted.
- */
-
- seg->transaction_id = 0;
- seg->chunk_size = chunk_size;
-
+ /* Apply settings to the new pool seg */
if (to_cachepool) {
- cache_mode_t cache_mode = 0;
- const char *policy_name = NULL;
-
- if (!get_cache_params(cmd, &chunk_size, &cache_mode, &policy_name, &policy_settings))
- goto_bad;
-
- if (cache_mode &&
- !cache_set_cache_mode(seg, cache_mode))
- goto_bad;
-
- if ((policy_name || policy_settings) &&
- !cache_set_policy(seg, policy_name, policy_settings))
+ if (!cache_set_params(seg, chunk_size, cache_mode, policy_name, policy_settings))
goto_bad;
} else {
- const char *discards_name;
-
- if (arg_is_set(cmd, zero_ARG))
- seg->zero_new_blocks = arg_int_value(cmd, zero_ARG, 0) ? THIN_ZERO_YES : THIN_ZERO_NO;
- else
- seg->zero_new_blocks = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, vg->profile) ? THIN_ZERO_YES : THIN_ZERO_NO;
-
- if (arg_is_set(cmd, discards_ARG))
- seg->discards = (thin_discards_t) arg_uint_value(cmd, discards_ARG, THIN_DISCARDS_PASSDOWN);
- else {
- if (!(discards_name = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG, vg->profile)))
- goto_bad;
- if (!set_pool_discards(&seg->discards, discards_name))
- goto_bad;
- }
+ seg->transaction_id = 0;
+ seg->chunk_size = chunk_size;
+ seg->discards = discards;
+ seg->zero_new_blocks = zero_new_blocks;
}
/*
@@ -3087,8 +3041,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (!handle_pool_metadata_spare(vg,
metadata_lv->le_count,
- use_pvh,
- arg_int_value(cmd, poolmetadataspare_ARG, DEFAULT_POOL_METADATA_SPARE)))
+ use_pvh, pool_metadata_spare))
goto_bad;
if (!vg_write(vg) || !vg_commit(vg))
@@ -3173,8 +3126,8 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
{
struct logical_volume *cache_lv;
uint32_t chunk_size = 0;
- cache_mode_t cache_mode = 0;
- const char *policy_name = NULL;
+ cache_mode_t cache_mode;
+ const char *policy_name;
struct dm_config_tree *policy_settings = NULL;
int r = 0;
7 years, 2 months
master - lvcreate: do not round cache volumes on cache chunks
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=298d12c4590ccca26b9...
Commit: 298d12c4590ccca26b92e1457c72c6369a32d3e9
Parent: f24a1f06b2a9856c2bde0f8ee740bb9c3c695c35
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Mar 9 17:15:56 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
lvcreate: do not round cache volumes on cache chunks
Since cache chunk might be huge and there is no technical need
to enforce rounding and there is actually more 'real' VG space
used then necessary - keep rounding on 'chunk' bounrary only
for thin volumes - where it's the space used anyway.
NB: we support conversion of any-size 'existing' LV into cached LV.
---
WHATS_NEW | 1 +
lib/metadata/lv_manip.c | 25 ++++++++++++-------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 00465cc..61b01b6 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.169 -
=====================================
+ Skip rounding on cache chunk size boudary when create cache LV.
Improve cache_set_params support for chunk_size selection.
Fix metadata profile allocation/cache_[mode|policy] setting.
Fix missing support for using allocation/cache_pool_chunk_size setting.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 5ef9d73..120eb58 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7402,21 +7402,20 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
return NULL;
}
- /* Validate volume size to to aling on chunk for small extents */
- /* Cache chunk size is always set */
- size = first_seg(pool_lv)->chunk_size;
- if (size > vg->extent_size) {
- /* Align extents on chunk boundary size */
- size = ((uint64_t)vg->extent_size * lp->extents + size - 1) /
- size * size / vg->extent_size;
- if (size != lp->extents) {
- log_print_unless_silent("Rounding size (%d extents) up to chunk boundary "
- "size (%d extents).", lp->extents, size);
- lp->extents = size;
+ if (seg_is_thin_volume(lp)) {
+ /* Validate volume size to to aling on chunk for small extents */
+ size = first_seg(pool_lv)->chunk_size;
+ if (size > vg->extent_size) {
+ /* Align extents on chunk boundary size */
+ size = ((uint64_t)vg->extent_size * lp->extents + size - 1) /
+ size * size / vg->extent_size;
+ if (size != lp->extents) {
+ log_print_unless_silent("Rounding size (%d extents) up to chunk boundary "
+ "size (%d extents).", lp->extents, size);
+ lp->extents = size;
+ }
}
- }
- if (seg_is_thin_volume(lp)) {
thin_pool_was_active = lv_is_active(pool_lv);
if (lv_is_new_thin_pool(pool_lv)) {
if (!check_new_thin_pool(pool_lv))
7 years, 2 months
master - lvcreate: respecting profile settings
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f24a1f06b2a9856c2bd...
Commit: f24a1f06b2a9856c2bde0f8ee740bb9c3c695c35
Parent: 36003df7e39bd2b3faf7b9d3f651109ddf30cebb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 10 13:04:30 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
lvcreate: respecting profile settings
---
lib/metadata/lv_manip.c | 8 --------
tools/lvcreate.c | 3 ---
2 files changed, 0 insertions(+), 11 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e78a9ac..5ef9d73 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7402,14 +7402,6 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
return NULL;
}
- if (seg_is_cache(lp)) {
- /* validate metadata size */
- if (!validate_lv_cache_chunk_size(pool_lv, lp->chunk_size))
- return_0;
-
- first_seg(pool_lv)->chunk_size = lp->chunk_size;
- }
-
/* Validate volume size to to aling on chunk for small extents */
/* Cache chunk size is always set */
size = first_seg(pool_lv)->chunk_size;
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 80c97b0..01bd4b6 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -1156,9 +1156,6 @@ static int _determine_cache_argument(struct volume_group *vg,
/* Pool exists, create cache volume */
lp->create_pool = 0;
lp->origin_name = NULL;
- /* If cache args not given, use those from cache pool */
- if (!arg_is_set(cmd, chunksize_ARG))
- lp->chunk_size = first_seg(lv)->chunk_size;
} else if (lv) {
/* Origin exists, create cache pool volume */
if (!validate_lv_cache_create_origin(lv))
7 years, 2 months
master - cache: extend usability of cache_set_params
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=36003df7e39bd2b3faf...
Commit: 36003df7e39bd2b3faf7b9d3f651109ddf30cebb
Parent: dcf038c7a616cb415ea55e3d19a1c1ee0d0086b9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 27 14:53:45 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
cache: extend usability of cache_set_params
Fix missing reset of '*settings' pointer when no args were given.
Handle cache_chunk settings like all other settings, so it is properly
updated only with non-zero settings and the existing cache-pool
chunk_size is not being reconfigured.
---
WHATS_NEW | 1 +
lib/metadata/cache_manip.c | 28 ++++++++++++++++++++++++----
lib/metadata/lv_manip.c | 2 --
tools/lvconvert.c | 2 --
tools/toollib.c | 40 ++++++++++++++++++++++------------------
5 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index da541d2..00465cc 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.169 -
=====================================
+ Improve cache_set_params support for chunk_size selection.
Fix metadata profile allocation/cache_[mode|policy] setting.
Fix missing support for using allocation/cache_pool_chunk_size setting.
Upstream git moved to https://sourceware.org/git/?p=lvm2
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 92f368e..8d6896b 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -772,6 +772,7 @@ int cache_set_params(struct lv_segment *seg,
const struct dm_config_tree *policy_settings)
{
struct lv_segment *pool_seg;
+ struct cmd_context *cmd = seg->lv->vg->cmd;
if (!cache_set_cache_mode(seg, mode))
return_0;
@@ -782,16 +783,35 @@ int cache_set_params(struct lv_segment *seg,
pool_seg = seg_is_cache(seg) ? first_seg(seg->pool_lv) : seg;
if (chunk_size) {
- if (!validate_lv_cache_chunk_size(pool_seg->lv, chunk_size))
+ if (seg_is_cache(seg) &&
+ !validate_lv_cache_chunk_size(pool_seg->lv, chunk_size))
return_0;
pool_seg->chunk_size = chunk_size;
- } else {
- /* TODO: some calc_policy solution for cache ? */
- if (!recalculate_pool_chunk_size_with_dev_hints(pool_seg->lv, 0,
+ } else if (seg_is_cache(seg)) {
+ /* Chunk size in profile has priority over cache-pool chunk size */
+ if ((chunk_size = find_config_tree_int(cmd, allocation_cache_pool_chunk_size_CFG,
+ seg->lv->profile) * 2)) {
+ if (!validate_lv_cache_chunk_size(pool_seg->lv, chunk_size))
+ return_0;
+ if (pool_seg->chunk_size != chunk_size)
+ log_verbose("Replacing chunk size %s in cache pool %s with "
+ "chunk size %s from profile.",
+ display_size(cmd, pool_seg->chunk_size),
+ display_lvname(seg->lv),
+ display_size(cmd, chunk_size));
+ pool_seg->chunk_size = chunk_size;
+ }
+ } else if (seg_is_cache_pool(seg)) {
+ if (!pool_seg->chunk_size &&
+ /* TODO: some calc_policy solution for cache ? */
+ !recalculate_pool_chunk_size_with_dev_hints(pool_seg->lv,
THIN_CHUNK_SIZE_CALC_METHOD_GENERIC))
return_0;
}
+ if (seg_is_cache(seg))
+ cache_check_for_warns(seg);
+
return 1;
}
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 6528811..e78a9ac 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7887,8 +7887,6 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
lp->policy_settings))
return_NULL; /* revert? */
- cache_check_for_warns(first_seg(lv));
-
if (!lv_update_and_reload(lv)) {
/* FIXME Do a better revert */
log_error("Aborting. Manual intervention required.");
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index f7210cc..9641a16 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -3193,8 +3193,6 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
if (!cache_set_params(first_seg(cache_lv), chunk_size, cache_mode, policy_name, policy_settings))
goto_bad;
- cache_check_for_warns(first_seg(cache_lv));
-
if (!lv_update_and_reload(cache_lv))
goto_bad;
diff --git a/tools/toollib.c b/tools/toollib.c
index 3c00045..bd19ac4 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1358,14 +1358,19 @@ int get_cache_params(struct cmd_context *cmd,
struct dm_config_node *cn;
int ok = 0;
- if (cache_mode)
- *cache_mode = (cache_mode_t) arg_uint_value(cmd, cachemode_ARG, CACHE_MODE_UNSELECTED);
+ if (arg_is_set(cmd, chunksize_ARG)) {
+ *chunk_size = arg_uint_value(cmd, chunksize_ARG, 0);
- if (name)
- *name = arg_str_value(cmd, cachepolicy_ARG, NULL);
+ if (!validate_cache_chunk_size(cmd, *chunk_size))
+ return_0;
- if (!settings)
- return 1;
+ log_very_verbose("Setting pool chunk size to %s.",
+ display_size(cmd, *chunk_size));
+ }
+
+ *cache_mode = (cache_mode_t) arg_uint_value(cmd, cachemode_ARG, CACHE_MODE_UNSELECTED);
+
+ *name = arg_str_value(cmd, cachepolicy_ARG, NULL);
dm_list_iterate_items(group, &cmd->arg_value_groups) {
if (!grouped_arg_is_set(group->arg_values, cachesettings_ARG))
@@ -1386,23 +1391,22 @@ int get_cache_params(struct cmd_context *cmd,
goto_out;
}
- if (!current)
- return 1;
+ if (current) {
+ if (!(result = dm_config_flatten(current)))
+ goto_out;
- if (!(result = dm_config_flatten(current)))
- goto_out;
+ if (result->root) {
+ if (!(cn = dm_config_create_node(result, "policy_settings")))
+ goto_out;
- if (result->root) {
- if (!(cn = dm_config_create_node(result, "policy_settings")))
- goto_out;
+ cn->child = result->root;
+ result->root = cn;
+ }
- cn->child = result->root;
- result->root = cn;
+ if (!_validate_cachepool_params(*name, result))
+ goto_out;
}
- if (!_validate_cachepool_params(*name, result))
- goto_out;
-
ok = 1;
out:
if (!ok && result) {
7 years, 2 months
master - cache: improve support for profile for cache settings
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dcf038c7a616cb415ea...
Commit: dcf038c7a616cb415ea55e3d19a1c1ee0d0086b9
Parent: c598e65de988663d2174f9d9b00408a1d50a075e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 5 17:42:15 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
cache: improve support for profile for cache settings
User can specify metadata profile which stores important cache
geometry data for easy configuration.
Fix missing support for getting chunk_size, cache_mode, cache_policy
for a cache/cache pools volumes from configuration or metadata profile.
---
WHATS_NEW | 2 ++
lib/config/config_settings.h | 16 ++++++++--------
lib/metadata/cache_manip.c | 22 ++++++++++++++++------
3 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 63cc2d2..da541d2 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
Version 2.02.169 -
=====================================
+ Fix metadata profile allocation/cache_[mode|policy] setting.
+ Fix missing support for using allocation/cache_pool_chunk_size setting.
Upstream git moved to https://sourceware.org/git/?p=lvm2
Support conversion of raid type, stripesize and number of disks
Reject writemostly/writebehind in lvchange during resynchronization.
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 2b76526..6a01a97 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -473,14 +473,14 @@ cfg(allocation_raid_stripe_all_devices_CFG, "raid_stripe_all_devices", allocatio
"when the command does not specify the number of stripes to use.\n"
"This was the default behaviour until release 2.02.162.\n")
-cfg(allocation_cache_pool_metadata_require_separate_pvs_CFG, "cache_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_CACHE_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 106), NULL, 0, NULL,
+cfg(allocation_cache_pool_metadata_require_separate_pvs_CFG, "cache_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA, CFG_TYPE_BOOL, DEFAULT_CACHE_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 106), NULL, 0, NULL,
"Cache pool metadata and data will always use different PVs.\n")
-cfg(allocation_cache_pool_cachemode_CFG, "cache_pool_cachemode", allocation_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 113), NULL, vsn(2, 2, 128),
+cfg(allocation_cache_pool_cachemode_CFG, "cache_pool_cachemode", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 113), NULL, vsn(2, 2, 128),
"This has been replaced by the allocation/cache_mode setting.\n",
"Cache mode.\n")
-cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 128), NULL, 0, NULL,
+cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_CACHE_MODE, vsn(2, 2, 128), NULL, 0, NULL,
"The default cache mode used for new cache.\n"
"#\n"
"Accepted values:\n"
@@ -492,20 +492,20 @@ cfg(allocation_cache_mode_CFG, "cache_mode", allocation_CFG_SECTION, CFG_PROFILA
"#\n"
"This setting replaces allocation/cache_pool_cachemode.\n")
-cfg(allocation_cache_policy_CFG, "cache_policy", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, 0, vsn(2, 2, 128), NULL, 0, NULL,
+cfg(allocation_cache_policy_CFG, "cache_policy", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, 0, vsn(2, 2, 128), NULL, 0, NULL,
"The default cache policy used for new cache volume.\n"
"Since kernel 4.2 the default policy is smq (Stochastic multique),\n"
"otherwise the older mq (Multiqueue) policy is selected.\n")
-cfg_section(allocation_cache_settings_CFG_SECTION, "cache_settings", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_COMMENTED, vsn(2, 2, 128), 0, NULL,
+cfg_section(allocation_cache_settings_CFG_SECTION, "cache_settings", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_COMMENTED, vsn(2, 2, 128), 0, NULL,
"Settings for the cache policy.\n"
"See documentation for individual cache policies for more info.\n")
-cfg_section(policy_settings_CFG_SUBSECTION, "policy_settings", allocation_cache_settings_CFG_SECTION, CFG_NAME_VARIABLE | CFG_SECTION_NO_CHECK | CFG_PROFILABLE | CFG_DEFAULT_COMMENTED, vsn(2, 2, 128), 0, NULL,
+cfg_section(policy_settings_CFG_SUBSECTION, "policy_settings", allocation_cache_settings_CFG_SECTION, CFG_NAME_VARIABLE | CFG_SECTION_NO_CHECK | CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_COMMENTED, vsn(2, 2, 128), 0, NULL,
"Replace this subsection name with a policy name.\n"
"Multiple subsections for different policies can be created.\n")
-cfg_runtime(allocation_cache_pool_chunk_size_CFG, "cache_pool_chunk_size", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT, vsn(2, 2, 106), 0, NULL,
+cfg_runtime(allocation_cache_pool_chunk_size_CFG, "cache_pool_chunk_size", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT, vsn(2, 2, 106), 0, NULL,
"The minimal chunk size in KiB for cache pool volumes.\n"
"Using a chunk_size that is too large can result in wasteful use of\n"
"the cache, where small reads and writes can cause large sections of\n"
@@ -516,7 +516,7 @@ cfg_runtime(allocation_cache_pool_chunk_size_CFG, "cache_pool_chunk_size", alloc
"on the smaller end of the spectrum. Supported values range from\n"
"32KiB to 1GiB in multiples of 32.\n")
-cfg(allocation_cache_pool_max_chunks_CFG, "cache_pool_max_chunks", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT, 0, vsn(2, 2, 165), NULL, 0, NULL,
+cfg(allocation_cache_pool_max_chunks_CFG, "cache_pool_max_chunks", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA | CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT, 0, vsn(2, 2, 165), NULL, 0, NULL,
"The maximum number of chunks in a cache pool.\n"
"For cache target v1.9 the recommended maximumm is 1000000 chunks.\n"
"Using cache pool with more chunks may degrade cache performance.\n")
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index eb4ebfe..92f368e 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -77,6 +77,7 @@ int set_cache_mode(cache_mode_t *mode, const char *cache_mode)
int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
{
struct cmd_context *cmd = seg->lv->vg->cmd;
+ struct profile *profile = seg->lv->profile;
const char *str;
int id;
@@ -107,7 +108,7 @@ int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
find_config_node(cmd, cmd->cft, allocation_cache_pool_cachemode_CFG))
id = allocation_cache_pool_cachemode_CFG;
- if (!(str = find_config_tree_str(cmd, id, NULL))) {
+ if (!(str = find_config_tree_str(cmd, id, profile))) {
log_error(INTERNAL_ERROR "Cache mode is not determined.");
return 0;
}
@@ -162,7 +163,7 @@ int update_cache_pool_params(const struct segment_type *segtype,
uint32_t extent_size = vg->extent_size;
uint64_t pool_metadata_size = (uint64_t) *pool_metadata_extents * extent_size;
uint64_t pool_data_size = (uint64_t) pool_data_extents * extent_size;
- uint64_t max_chunks =
+ const uint64_t max_chunks =
get_default_allocation_cache_pool_max_chunks_CFG(vg->cmd, vg->profile);
/* min chunk size in a multiple of DM_CACHE_MIN_DATA_BLOCK_SIZE */
uint64_t min_chunk_size = (((pool_data_size + max_chunks - 1) / max_chunks +
@@ -170,7 +171,10 @@ int update_cache_pool_params(const struct segment_type *segtype,
DM_CACHE_MIN_DATA_BLOCK_SIZE) * DM_CACHE_MIN_DATA_BLOCK_SIZE;
if (!(passed_args & PASS_ARG_CHUNK_SIZE)) {
- *chunk_size = DEFAULT_CACHE_POOL_CHUNK_SIZE * 2;
+ if (!(*chunk_size = find_config_tree_int(vg->cmd, allocation_cache_pool_chunk_size_CFG,
+ vg->profile) * 2))
+ *chunk_size = get_default_allocation_cache_pool_chunk_size_CFG(vg->cmd,
+ vg->profile);
if (*chunk_size < min_chunk_size) {
/*
* When using more then 'standard' default,
@@ -236,7 +240,7 @@ int update_cache_pool_params(const struct segment_type *segtype,
int validate_lv_cache_chunk_size(struct logical_volume *pool_lv, uint32_t chunk_size)
{
struct volume_group *vg = pool_lv->vg;
- uint64_t max_chunks = get_default_allocation_cache_pool_max_chunks_CFG(vg->cmd, vg->profile);
+ const uint64_t max_chunks = get_default_allocation_cache_pool_max_chunks_CFG(vg->cmd, pool_lv->profile);
uint64_t min_size = _cache_min_metadata_size(pool_lv->size, chunk_size);
uint64_t chunks = pool_lv->size / chunk_size;
int r = 1;
@@ -394,6 +398,9 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool_lv,
if (!attach_pool_lv(seg, pool_lv, NULL, NULL, NULL))
return_NULL;
+ if (!seg->lv->profile) /* Inherit profile from cache-pool */
+ seg->lv->profile = seg->pool_lv->profile;
+
return cache_lv;
}
@@ -665,6 +672,7 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
struct dm_config_tree *old = NULL, *new = NULL, *tmp = NULL;
int r = 0;
const int passed_seg_is_cache = seg_is_cache(seg);
+ struct profile *profile = seg->lv->profile;
if (passed_seg_is_cache)
seg = first_seg(seg->pool_lv);
@@ -675,7 +683,8 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
return 0;
}
} else if (!seg->policy_name && passed_seg_is_cache) {
- if (!(seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG, NULL)) &&
+ if (!(seg->policy_name = find_config_tree_str(seg->lv->vg->cmd, allocation_cache_policy_CFG,
+ profile)) &&
!(seg->policy_name = _get_default_cache_policy(seg->lv->vg->cmd)))
return_0;
}
@@ -702,7 +711,8 @@ int cache_set_policy(struct lv_segment *seg, const char *name,
!(seg->policy_settings = dm_config_clone_node_with_mem(seg->lv->vg->vgmem, cn, 0)))
goto_out;
} else if (passed_seg_is_cache && /* Look for command's profile cache_policies */
- (cns = find_config_tree_node(seg->lv->vg->cmd, allocation_cache_settings_CFG_SECTION, NULL))) {
+ (cns = find_config_tree_node(seg->lv->vg->cmd, allocation_cache_settings_CFG_SECTION,
+ seg->lv->profile))) {
/* Try to find our section for given policy */
for (cn = cns->child; cn; cn = cn->sib) {
/* Only matching section names */
7 years, 2 months
master - cache: get and set cache params
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c598e65de988663d217...
Commit: c598e65de988663d2174f9d9b00408a1d50a075e
Parent: 861992d874a7f42619559bf3768750977b4b1446
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Mar 9 16:20:44 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
cache: get and set cache params
---
tools/lvchange.c | 3 ++-
tools/lvconvert.c | 21 ++++-----------------
tools/lvcreate.c | 1 +
tools/toollib.c | 1 +
tools/toollib.h | 1 +
5 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/tools/lvchange.c b/tools/lvchange.c
index d0d67b3..3804041 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -627,11 +627,12 @@ static int _lvchange_cache(struct cmd_context *cmd, struct logical_volume *lv)
struct dm_config_tree *settings = NULL;
struct lv_segment *pool_seg = first_seg(lv);
int r = 0, is_clean;
+ uint32_t chunk_size = 0; /* FYI: lvchange does NOT support its change */
if (lv_is_cache(lv))
pool_seg = first_seg(pool_seg->pool_lv);
- if (!get_cache_params(cmd, &mode, &name, &settings))
+ if (!get_cache_params(cmd, &chunk_size, &mode, &name, &settings))
goto_out;
if ((mode != CACHE_MODE_UNSELECTED) &&
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 45c5a49..f7210cc 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -3046,7 +3046,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
cache_mode_t cache_mode = 0;
const char *policy_name = NULL;
- if (!get_cache_params(cmd, &cache_mode, &policy_name, &policy_settings))
+ if (!get_cache_params(cmd, &chunk_size, &cache_mode, &policy_name, &policy_settings))
goto_bad;
if (cache_mode &&
@@ -3172,6 +3172,7 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
struct logical_volume *cachepool_lv)
{
struct logical_volume *cache_lv;
+ uint32_t chunk_size = 0;
cache_mode_t cache_mode = 0;
const char *policy_name = NULL;
struct dm_config_tree *policy_settings = NULL;
@@ -3180,7 +3181,7 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
if (!validate_lv_cache_create_pool(cachepool_lv))
return_0;
- if (!get_cache_params(cmd, &cache_mode, &policy_name, &policy_settings))
+ if (!get_cache_params(cmd, &chunk_size, &cache_mode, &policy_name, &policy_settings))
goto_bad;
if (!archive(lv->vg))
@@ -3189,10 +3190,7 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
if (!(cache_lv = lv_cache_create(cachepool_lv, lv)))
goto_bad;
- if (!cache_set_cache_mode(first_seg(cache_lv), cache_mode))
- goto_bad;
-
- if (!cache_set_policy(first_seg(cache_lv), policy_name, policy_settings))
+ if (!cache_set_params(first_seg(cache_lv), chunk_size, cache_mode, policy_name, policy_settings))
goto_bad;
cache_check_for_warns(first_seg(cache_lv));
@@ -3814,7 +3812,6 @@ static int _lvconvert_to_cache_vol_single(struct cmd_context *cmd,
struct volume_group *vg = lv->vg;
struct logical_volume *cachepool_lv;
const char *cachepool_name;
- uint32_t chunk_size = 0;
if (!(cachepool_name = arg_str_value(cmd, cachepool_ARG, NULL)))
goto_out;
@@ -3863,16 +3860,6 @@ static int _lvconvert_to_cache_vol_single(struct cmd_context *cmd,
goto out;
}
- if (arg_is_set(cmd, chunksize_ARG))
- chunk_size = arg_uint_value(cmd, chunksize_ARG, 0);
- if (!chunk_size)
- chunk_size = first_seg(cachepool_lv)->chunk_size;
-
- /* FIXME: why is chunk_size read and checked if it's not used? */
-
- if (!validate_lv_cache_chunk_size(cachepool_lv, chunk_size))
- goto_out;
-
/* Note: requires rather deep know-how to skip zeroing */
if (!arg_is_set(cmd, zero_ARG)) {
if (!arg_is_set(cmd, yes_ARG) &&
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 63b2c6d..80c97b0 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -633,6 +633,7 @@ static int _read_cache_params(struct cmd_context *cmd,
return 1;
if (!get_cache_params(cmd,
+ &lp->chunk_size,
&lp->cache_mode,
&lp->policy_name,
&lp->policy_settings))
diff --git a/tools/toollib.c b/tools/toollib.c
index 4d746ea..3c00045 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1347,6 +1347,7 @@ static int _validate_cachepool_params(const char *name,
}
int get_cache_params(struct cmd_context *cmd,
+ uint32_t *chunk_size,
cache_mode_t *cache_mode,
const char **name,
struct dm_config_tree **settings)
diff --git a/tools/toollib.h b/tools/toollib.h
index 7c588fc..22ae491 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -221,6 +221,7 @@ int get_stripe_params(struct cmd_context *cmd, const struct segment_type *segtyp
unsigned *stripes_supplied, unsigned *stripe_size_supplied);
int get_cache_params(struct cmd_context *cmd,
+ uint32_t *chunk_size,
cache_mode_t *cache_mode,
const char **name,
struct dm_config_tree **settings);
7 years, 2 months
master - lvconvert: replacing with goto
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=861992d874a7f426195...
Commit: 861992d874a7f42619559bf3768750977b4b1446
Parent: 2d11fc695e7c2baff1b919fb9f92e491e49d5db1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Mar 9 18:10:35 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
lvconvert: replacing with goto
Split-off patch that just replaces returns with 'goto bad'
so there is single place to release policy_settings.
In the next patch we will start to use some shared
function call between lvconvert and lvcreate
(effectively restoring previous logic which has got lost).
---
tools/lvconvert.c | 84 +++++++++++++++++++++++++++--------------------------
1 files changed, 43 insertions(+), 41 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 4ed5018..45c5a49 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2680,6 +2680,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
uint32_t meta_extents;
uint32_t chunk_size;
int chunk_calc;
+ struct dm_config_tree *policy_settings = NULL;
int r = 0;
/* for handling lvmlockd cases */
@@ -2825,7 +2826,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
&meta_extents,
&chunk_calc,
&chunk_size))
- return_0;
+ goto_bad;
} else {
if (!update_thin_pool_params(pool_segtype, vg, target_attr,
passed_args, lv->le_count,
@@ -2833,7 +2834,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
&chunk_calc,
&chunk_size,
NULL, NULL))
- return_0;
+ goto_bad;
}
if ((uint64_t)chunk_size > ((uint64_t)lv->le_count * vg->extent_size)) {
@@ -2841,13 +2842,13 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
display_lvname(lv),
display_size(cmd, (uint64_t)lv->le_count * vg->extent_size),
display_size(cmd, chunk_size));
- return 0;
+ goto bad;
}
if (metadata_lv && (meta_extents > metadata_lv->le_count)) {
log_error("Pool metadata LV %s is too small (%u extents) for required metadata (%u extents).",
display_lvname(metadata_lv), metadata_lv->le_count, meta_extents);
- return 0;
+ goto bad;
}
log_verbose("Pool metadata extents %u chunk_size %u", meta_extents, chunk_size);
@@ -2875,7 +2876,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
metadata_lv ? " and " : "",
metadata_lv ? display_lvname(metadata_lv) : "") == 'n') {
log_error("Conversion aborted.");
- return 0;
+ goto bad;
}
/*
@@ -2898,13 +2899,13 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
&meta_stripe_size,
&meta_stripes_supplied,
&meta_stripe_size_supplied))
- return_0;
+ goto_bad;
meta_readahead = arg_uint_value(cmd, readahead_ARG, cmd->default_settings.read_ahead);
meta_alloc = (alloc_policy_t) arg_uint_value(cmd, alloc_ARG, ALLOC_INHERIT);
if (!archive(vg))
- return_0;
+ goto_bad;
if (!(metadata_lv = alloc_pool_metadata(lv,
meta_name,
@@ -2914,28 +2915,28 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
meta_extents,
meta_alloc,
use_pvh)))
- return_0;
+ goto_bad;
} else {
if (!deactivate_lv(cmd, metadata_lv)) {
log_error("Aborting. Failed to deactivate %s.",
display_lvname(metadata_lv));
- return 0;
+ goto bad;
}
if (!archive(vg))
- return_0;
+ goto_bad;
if (zero_metadata) {
metadata_lv->status |= LV_TEMPORARY;
if (!activate_lv_local(cmd, metadata_lv)) {
log_error("Aborting. Failed to activate metadata lv.");
- return 0;
+ goto bad;
}
metadata_lv->status &= ~LV_TEMPORARY;
if (!wipe_lv(metadata_lv, (struct wipe_params) { .do_zero = 1 })) {
log_error("Aborting. Failed to wipe metadata lv.");
- return 0;
+ goto bad;
}
}
}
@@ -2948,13 +2949,13 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (!deactivate_lv(cmd, metadata_lv)) {
log_error("Aborting. Failed to deactivate metadata lv. "
"Manual intervention required.");
- return 0;
+ goto bad;
}
if (!deactivate_lv(cmd, lv)) {
log_error("Aborting. Failed to deactivate logical volume %s.",
display_lvname(lv));
- return 0;
+ goto bad;
}
/*
@@ -2984,7 +2985,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
*/
if (!lv_rename_update(cmd, data_lv, data_name, 0))
- return_0;
+ goto_bad;
/*
* Create LV structures for the new pool LV object,
@@ -2995,14 +2996,14 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
(to_cachepool ? CACHE_POOL : THIN_POOL) | VISIBLE_LV | LVM_READ | LVM_WRITE,
ALLOC_INHERIT, vg))) {
log_error("Creation of pool LV failed.");
- return 0;
+ goto bad;
}
/* Allocate a new pool segment */
if (!(seg = alloc_lv_segment(pool_segtype, pool_lv, 0, data_lv->le_count, 0,
pool_lv->status, 0, NULL, 1,
data_lv->le_count, 0, 0, 0, 0, NULL)))
- return_0;
+ goto_bad;
/* Add the new segment to the layer LV */
dm_list_add(&pool_lv->segments, &seg->list);
@@ -3010,7 +3011,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
pool_lv->size = data_lv->size;
if (!attach_pool_data_lv(seg, data_lv))
- return_0;
+ goto_bad;
/*
* Create a new lock for a thin pool LV. A cache pool LV has no lock.
@@ -3044,21 +3045,17 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (to_cachepool) {
cache_mode_t cache_mode = 0;
const char *policy_name = NULL;
- struct dm_config_tree *policy_settings = NULL;
if (!get_cache_params(cmd, &cache_mode, &policy_name, &policy_settings))
- return_0;
+ goto_bad;
if (cache_mode &&
!cache_set_cache_mode(seg, cache_mode))
- return_0;
+ goto_bad;
if ((policy_name || policy_settings) &&
!cache_set_policy(seg, policy_name, policy_settings))
- return_0;
-
- if (policy_settings)
- dm_config_destroy(policy_settings);
+ goto_bad;
} else {
const char *discards_name;
@@ -3071,9 +3068,9 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
seg->discards = (thin_discards_t) arg_uint_value(cmd, discards_ARG, THIN_DISCARDS_PASSDOWN);
else {
if (!(discards_name = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG, vg->profile)))
- return_0;
+ goto_bad;
if (!set_pool_discards(&seg->discards, discards_name))
- return_0;
+ goto_bad;
}
}
@@ -3083,19 +3080,19 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
*/
if (pool_metadata_name &&
!lv_rename_update(cmd, metadata_lv, meta_name, 0))
- return_0;
+ goto_bad;
if (!attach_pool_metadata_lv(seg, metadata_lv))
- return_0;
+ goto_bad;
if (!handle_pool_metadata_spare(vg,
metadata_lv->le_count,
use_pvh,
arg_int_value(cmd, poolmetadataspare_ARG, DEFAULT_POOL_METADATA_SPARE)))
- return_0;
+ goto_bad;
if (!vg_write(vg) || !vg_commit(vg))
- return_0;
+ goto_bad;
if ((seg->zero_new_blocks == THIN_ZERO_YES) &&
seg->chunk_size >= DEFAULT_THIN_POOL_CHUNK_SIZE_PERFORMANCE * 2)
@@ -3146,6 +3143,9 @@ out:
log_error("Failed to unlock pool metadata LV %s/%s", vg->name, lockd_meta_name);
lockd_free_lv(cmd, vg, lockd_meta_name, &lockd_meta_id, lockd_meta_args);
}
+bad:
+ if (policy_settings)
+ dm_config_destroy(policy_settings);
return r;
#if 0
@@ -3175,37 +3175,39 @@ static int _lvconvert_to_cache_vol(struct cmd_context *cmd,
cache_mode_t cache_mode = 0;
const char *policy_name = NULL;
struct dm_config_tree *policy_settings = NULL;
+ int r = 0;
if (!validate_lv_cache_create_pool(cachepool_lv))
return_0;
if (!get_cache_params(cmd, &cache_mode, &policy_name, &policy_settings))
- return_0;
+ goto_bad;
if (!archive(lv->vg))
- return_0;
+ goto_bad;
if (!(cache_lv = lv_cache_create(cachepool_lv, lv)))
- return_0;
+ goto_bad;
if (!cache_set_cache_mode(first_seg(cache_lv), cache_mode))
- return_0;
+ goto_bad;
if (!cache_set_policy(first_seg(cache_lv), policy_name, policy_settings))
- return_0;
-
- if (policy_settings)
- dm_config_destroy(policy_settings);
+ goto_bad;
cache_check_for_warns(first_seg(cache_lv));
if (!lv_update_and_reload(cache_lv))
- return_0;
+ goto_bad;
log_print_unless_silent("Logical volume %s is now cached.",
display_lvname(cache_lv));
+ r = 1;
+bad:
+ if (policy_settings)
+ dm_config_destroy(policy_settings);
- return 1;
+ return r;
}
static struct convert_poll_id_list* _convert_poll_id_list_create(struct cmd_context *cmd,
7 years, 2 months
master - cache: set chunk_size as first param
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=2d11fc695e7c2baff1b...
Commit: 2d11fc695e7c2baff1b919fb9f92e491e49d5db1
Parent: 41843319654c671ce4419443a73f3cf87bb15199
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Mar 9 15:54:30 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
cache: set chunk_size as first param
---
lib/metadata/cache_manip.c | 4 ++--
lib/metadata/lv_manip.c | 8 ++++----
lib/metadata/metadata-exported.h | 4 ++--
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 1e93127..eb4ebfe 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -756,10 +756,10 @@ out:
* to update all commonly specified cache parameters
*/
int cache_set_params(struct lv_segment *seg,
+ uint32_t chunk_size,
cache_mode_t mode,
const char *policy_name,
- const struct dm_config_tree *policy_settings,
- uint32_t chunk_size)
+ const struct dm_config_tree *policy_settings)
{
struct lv_segment *pool_seg;
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index cb9ba68..6528811 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7672,10 +7672,10 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
if (lv_is_cache_pool(lv)) {
if (!cache_set_params(first_seg(lv),
+ lp->chunk_size,
lp->cache_mode,
lp->policy_name,
- lp->policy_settings,
- lp->chunk_size)) {
+ lp->policy_settings)) {
stack;
goto revert_new_lv;
}
@@ -7881,10 +7881,10 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
lv = tmp_lv;
if (!cache_set_params(first_seg(lv),
+ lp->chunk_size,
lp->cache_mode,
lp->policy_name,
- lp->policy_settings,
- (lp->passed_args & PASS_ARG_CHUNK_SIZE) ? lp->chunk_size : 0))
+ lp->policy_settings))
return_NULL; /* revert? */
cache_check_for_warns(first_seg(lv));
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 7f9bbfe..c0b6359 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -1276,10 +1276,10 @@ int cache_set_cache_mode(struct lv_segment *cache_seg, cache_mode_t mode);
int cache_set_policy(struct lv_segment *cache_seg, const char *name,
const struct dm_config_tree *settings);
int cache_set_params(struct lv_segment *seg,
+ uint32_t chunk_size,
cache_mode_t mode,
const char *policy_name,
- const struct dm_config_tree *policy_settings,
- uint32_t chunk_size);
+ const struct dm_config_tree *policy_settings);
void cache_check_for_warns(const struct lv_segment *seg);
int update_cache_pool_params(const struct segment_type *segtype,
struct volume_group *vg, unsigned attr,
7 years, 2 months
master - cache: use UNSELECTED enum
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=41843319654c671ce44...
Commit: 41843319654c671ce4419443a73f3cf87bb15199
Parent: b8cd0f4808fcb88ea803a7ffff5f27801fb14e02
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 3 14:52:32 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
cache: use UNSELECTED enum
Switch from _UNDEFINED to _UNSELECTED which is more describing
its value 0, while value -1 is better match for UNDEFINED.
---
lib/cache_segtype/cache.c | 4 ++--
lib/metadata/cache_manip.c | 8 ++++----
lib/metadata/metadata-exported.h | 2 +-
tools/lvchange.c | 2 +-
tools/toollib.c | 2 +-
5 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index 4fb06e7..ffa5d37 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -52,7 +52,7 @@ static void _fix_missing_defaults(struct lv_segment *cpool_seg)
cpool_seg->policy_name);
}
- if (cpool_seg->cache_mode == CACHE_MODE_UNDEFINED) {
+ if (cpool_seg->cache_mode == CACHE_MODE_UNSELECTED) {
cpool_seg->cache_mode = CACHE_MODE_WHEN_MISSING;
log_verbose("Cache pool %s is missing cache mode, using %s.",
display_lvname(cpool_seg->lv),
@@ -169,7 +169,7 @@ static int _cache_pool_text_export(const struct lv_segment *seg,
* but not worth to break backward compatibility, by shifting
* content to cache segment
*/
- if (seg->cache_mode != CACHE_MODE_UNDEFINED) {
+ if (seg->cache_mode != CACHE_MODE_UNSELECTED) {
if (!(cache_mode = get_cache_mode_name(seg)))
return_0;
outf(f, "cache_mode = \"%s\"", cache_mode);
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 5779f2d..1e93127 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -35,7 +35,7 @@ const char *display_cache_mode(const struct lv_segment *seg)
seg = first_seg(seg->pool_lv);
if (!seg_is_cache_pool(seg) ||
- (seg->cache_mode == CACHE_MODE_UNDEFINED))
+ (seg->cache_mode == CACHE_MODE_UNSELECTED))
return "";
return get_cache_mode_name(seg);
@@ -83,7 +83,7 @@ int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
if (seg_is_cache(seg))
seg = first_seg(seg->pool_lv);
else if (seg_is_cache_pool(seg)) {
- if (mode == CACHE_MODE_UNDEFINED)
+ if (mode == CACHE_MODE_UNSELECTED)
return 1; /* Defaults only for cache */
} else {
log_error(INTERNAL_ERROR "Cannot set cache mode for non cache volume %s.",
@@ -91,12 +91,12 @@ int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
return 0;
}
- if (mode != CACHE_MODE_UNDEFINED) {
+ if (mode != CACHE_MODE_UNSELECTED) {
seg->cache_mode = mode;
return 1;
}
- if (seg->cache_mode != CACHE_MODE_UNDEFINED)
+ if (seg->cache_mode != CACHE_MODE_UNSELECTED)
return 1; /* Default already set in cache pool */
/* Figure default settings from config/profiles */
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 42ca820..7f9bbfe 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -288,7 +288,7 @@ typedef enum {
} thin_discards_t;
typedef enum {
- CACHE_MODE_UNDEFINED = 0,
+ CACHE_MODE_UNSELECTED = 0,
CACHE_MODE_WRITETHROUGH,
CACHE_MODE_WRITEBACK,
CACHE_MODE_PASSTHROUGH,
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 8fae806..d0d67b3 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -634,7 +634,7 @@ static int _lvchange_cache(struct cmd_context *cmd, struct logical_volume *lv)
if (!get_cache_params(cmd, &mode, &name, &settings))
goto_out;
- if ((mode != CACHE_MODE_UNDEFINED) &&
+ if ((mode != CACHE_MODE_UNSELECTED) &&
(mode != pool_seg->cache_mode) &&
lv_is_cache(lv)) {
if (!lv_cache_wait_for_clean(lv, &is_clean))
diff --git a/tools/toollib.c b/tools/toollib.c
index c9461e5..4d746ea 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1358,7 +1358,7 @@ int get_cache_params(struct cmd_context *cmd,
int ok = 0;
if (cache_mode)
- *cache_mode = (cache_mode_t) arg_uint_value(cmd, cachemode_ARG, CACHE_MODE_UNDEFINED);
+ *cache_mode = (cache_mode_t) arg_uint_value(cmd, cachemode_ARG, CACHE_MODE_UNSELECTED);
if (name)
*name = arg_str_value(cmd, cachepolicy_ARG, NULL);
7 years, 2 months
master - thin: add new ZERO/DISCARDS_UNSELECTED
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b8cd0f4808fcb88ea80...
Commit: b8cd0f4808fcb88ea803a7ffff5f27801fb14e02
Parent: 8c72878cf2f53811cf5ae6fc9b7c787feb74e0c6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 3 20:46:13 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Mar 10 19:33:00 2017 +0100
thin: add new ZERO/DISCARDS_UNSELECTED
To more easily recognize unselected state from select '0' state
add new 'THIN_ZERO_UNSELECTED' enum.
Same applies to THIN_DISCARDS_UNSELECTED.
For those we no longer need to use PASS_ARG_ZERO or PASS_ARG_DISCARDS.
---
lib/metadata/lv.c | 2 +-
lib/metadata/lv_manip.c | 2 +-
lib/metadata/merge.c | 8 ++++++--
lib/metadata/metadata-exported.h | 12 ++++++++++--
lib/metadata/thin_manip.c | 27 +++++++++++++++++++--------
lib/report/properties.c | 2 +-
lib/report/report.c | 2 +-
lib/thin/thin.c | 16 ++++++++++++----
tools/lvchange.c | 2 +-
tools/lvconvert.c | 6 +++---
tools/lvcreate.c | 2 +-
tools/toollib.c | 16 ++++++++++------
tools/toollib.h | 2 +-
13 files changed, 67 insertions(+), 32 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 8c33a5e..e58de66 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -1279,7 +1279,7 @@ char *lv_attr_dup_with_info_and_seg_status(struct dm_pool *mem, const struct lv_
if (((lv_is_thin_volume(lv) && (seg = first_seg(lv)) && seg->pool_lv && (seg = first_seg(seg->pool_lv))) ||
(lv_is_thin_pool(lv) && (seg = first_seg(lv)))) &&
- seg->zero_new_blocks)
+ (seg->zero_new_blocks == THIN_ZERO_YES))
repstr[7] = 'z';
else
repstr[7] = '-';
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 90c61aa..cb9ba68 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7684,7 +7684,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
first_seg(lv)->max_recovery_rate = lp->max_recovery_rate;
} else if (lv_is_thin_pool(lv)) {
first_seg(lv)->chunk_size = lp->chunk_size;
- first_seg(lv)->zero_new_blocks = lp->zero ? 1 : 0;
+ first_seg(lv)->zero_new_blocks = lp->zero_new_blocks;
first_seg(lv)->discards = lp->discards;
if (!recalculate_pool_chunk_size_with_dev_hints(lv, lp->passed_args,
lp->thin_chunk_size_calc_policy)) {
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index b600bc4..a5cb9f3 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -396,10 +396,14 @@ static void _check_lv_segment(struct logical_volume *lv, struct lv_segment *seg,
if (!validate_thin_pool_chunk_size(lv->vg->cmd, seg->chunk_size))
seg_error("has invalid chunk size.");
+
+ if (seg->zero_new_blocks != THIN_ZERO_YES &&
+ seg->zero_new_blocks != THIN_ZERO_NO)
+ seg_error("zero_new_blocks is invalid");
} else { /* !thin_pool */
- if (seg->zero_new_blocks)
+ if (seg->zero_new_blocks != THIN_ZERO_UNSELECTED)
seg_error("sets zero_new_blocks");
- if (seg->discards)
+ if (seg->discards != THIN_DISCARDS_UNSELECTED)
seg_error("sets discards");
if (!dm_list_empty(&seg->thin_messages))
seg_error("sets thin_messages list");
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index c80a3c5..42ca820 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -275,6 +275,13 @@ enum {
};
typedef enum {
+ THIN_ZERO_UNSELECTED = 0,
+ THIN_ZERO_NO,
+ THIN_ZERO_YES,
+} thin_zero_t;
+
+typedef enum {
+ THIN_DISCARDS_UNSELECTED = 0,
THIN_DISCARDS_IGNORE,
THIN_DISCARDS_NO_PASSDOWN,
THIN_DISCARDS_PASSDOWN,
@@ -482,7 +489,7 @@ struct lv_segment {
struct lv_segment_area *meta_areas; /* For RAID */
struct logical_volume *metadata_lv; /* For thin_pool */
uint64_t transaction_id; /* For thin_pool, thin */
- unsigned zero_new_blocks; /* For thin_pool */
+ thin_zero_t zero_new_blocks; /* For thin_pool */
thin_discards_t discards; /* For thin_pool */
struct dm_list thin_messages; /* For thin_pool */
struct logical_volume *external_lv; /* For thin */
@@ -868,7 +875,7 @@ int update_thin_pool_params(const struct segment_type *segtype,
int passed_args, uint32_t pool_data_extents,
uint32_t *pool_metadata_extents,
int *chunk_size_calc_method, uint32_t *chunk_size,
- thin_discards_t *discards, int *zero);
+ thin_discards_t *discards, thin_zero_t *zero_new_blocks);
const char *get_pool_discards_name(thin_discards_t discards);
int set_pool_discards(thin_discards_t *discards, const char *str);
struct logical_volume *alloc_pool_metadata(struct logical_volume *pool_lv,
@@ -931,6 +938,7 @@ struct lvcreate_params {
int activation_skip; /* activation skip flags */
activation_change_t activate; /* non-snapshot, non-mirror */
thin_discards_t discards; /* thin */
+ thin_zero_t zero_new_blocks;
#define THIN_CHUNK_SIZE_CALC_METHOD_GENERIC 0x01
#define THIN_CHUNK_SIZE_CALC_METHOD_PERFORMANCE 0x02
int thin_chunk_size_calc_policy;
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 7748cd3..5c74248 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -604,7 +604,7 @@ int update_thin_pool_params(const struct segment_type *segtype,
uint32_t pool_data_extents,
uint32_t *pool_metadata_extents,
int *chunk_size_calc_method, uint32_t *chunk_size,
- thin_discards_t *discards, int *zero)
+ thin_discards_t *discards, thin_zero_t *zero_new_blocks)
{
struct cmd_context *cmd = vg->cmd;
struct profile *profile = vg->profile;
@@ -625,7 +625,9 @@ int update_thin_pool_params(const struct segment_type *segtype,
if (!validate_thin_pool_chunk_size(cmd, *chunk_size))
return_0;
- if (!(passed_args & PASS_ARG_DISCARDS)) {
+ if (discards &&
+ (*discards == THIN_DISCARDS_UNSELECTED) &&
+ find_config_tree_node(cmd, allocation_thin_pool_discards_CFG, profile)) {
if (!(str = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG, profile))) {
log_error(INTERNAL_ERROR "Could not find configuration.");
return 0;
@@ -634,8 +636,11 @@ int update_thin_pool_params(const struct segment_type *segtype,
return_0;
}
- if (!(passed_args & PASS_ARG_ZERO))
- *zero = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, profile);
+ if (zero_new_blocks &&
+ (*zero_new_blocks == THIN_ZERO_UNSELECTED) &&
+ find_config_tree_node(cmd, allocation_thin_pool_zero_CFG, profile))
+ *zero_new_blocks = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, profile)
+ ? THIN_ZERO_YES : THIN_ZERO_NO;
if (!(attr & THIN_FEATURE_BLOCK_SIZE) &&
!is_power_of_2(*chunk_size)) {
@@ -705,6 +710,13 @@ int update_thin_pool_params(const struct segment_type *segtype,
extents_from_size(vg->cmd, pool_metadata_size, extent_size)))
return_0;
+ if (discards && (*discards == THIN_DISCARDS_UNSELECTED))
+ if (!set_pool_discards(discards, DEFAULT_THIN_POOL_DISCARDS))
+ return_0;
+
+ if (zero_new_blocks && (*zero_new_blocks == THIN_ZERO_UNSELECTED))
+ *zero_new_blocks = (DEFAULT_THIN_POOL_ZERO) ? THIN_ZERO_YES : THIN_ZERO_NO;
+
return 1;
}
@@ -733,11 +745,10 @@ const char *get_pool_discards_name(thin_discards_t discards)
return "nopassdown";
case THIN_DISCARDS_IGNORE:
return "ignore";
+ default:
+ log_error(INTERNAL_ERROR "Unknown discards type encountered.");
+ return "unknown";
}
-
- log_error(INTERNAL_ERROR "Unknown discards type encountered.");
-
- return "unknown";
}
int lv_is_thin_origin(const struct logical_volume *lv, unsigned int *snap_count)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 04f2cef..c07fb2a 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -470,7 +470,7 @@ GET_LVSEG_NUM_PROPERTY_FN(chunk_size, (SECTOR_SIZE * lvseg_chunksize(lvseg)))
#define _chunk_size_set prop_not_implemented_set
GET_LVSEG_NUM_PROPERTY_FN(thin_count, dm_list_size(&lvseg->lv->segs_using_this_lv))
#define _thin_count_set prop_not_implemented_set
-GET_LVSEG_NUM_PROPERTY_FN(zero, lvseg->zero_new_blocks)
+GET_LVSEG_NUM_PROPERTY_FN(zero, (lvseg->zero_new_blocks == THIN_ZERO_YES))
#define _zero_set prop_not_implemented_set
GET_LVSEG_NUM_PROPERTY_FN(transaction_id, lvseg->transaction_id)
#define _transaction_id_set prop_not_implemented_set
diff --git a/lib/report/report.c b/lib/report/report.c
index b5791c6..27269d4 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3654,7 +3654,7 @@ static int _thinzero_disp(struct dm_report *rh, struct dm_pool *mem,
seg = first_seg(seg->pool_lv);
if (seg_is_thin_pool(seg))
- return _binary_disp(rh, mem, field, seg->zero_new_blocks, GET_FIRST_RESERVED_NAME(zero_y), private);
+ return _binary_disp(rh, mem, field, (seg->zero_new_blocks == THIN_ZERO_YES), GET_FIRST_RESERVED_NAME(zero_y), private);
return _binary_undef_disp(rh, mem, field, private);
}
diff --git a/lib/thin/thin.c b/lib/thin/thin.c
index 1e29566..73fffa6 100644
--- a/lib/thin/thin.c
+++ b/lib/thin/thin.c
@@ -45,7 +45,7 @@ static void _thin_pool_display(const struct lv_segment *seg)
dm_list_size(&seg->lv->segs_using_this_lv));
log_print(" Transaction ID\t%" PRIu64, seg->transaction_id);
log_print(" Zero new blocks\t%s",
- seg->zero_new_blocks ? "yes" : "no");
+ (seg->zero_new_blocks == THIN_ZERO_YES) ? "yes" : "no");
log_print(" ");
}
@@ -84,6 +84,7 @@ static int _thin_pool_text_import(struct lv_segment *seg,
const char *lv_name;
struct logical_volume *pool_data_lv, *pool_metadata_lv;
const char *discards_str = NULL;
+ uint32_t zero = 0;
if (!dm_config_get_str(sn, "metadata", &lv_name))
return SEG_LOG_ERROR("Metadata must be a string in");
@@ -124,9 +125,11 @@ static int _thin_pool_text_import(struct lv_segment *seg,
seg->device_id);
if (dm_config_has_node(sn, "zero_new_blocks") &&
- !dm_config_get_uint32(sn, "zero_new_blocks", &seg->zero_new_blocks))
+ !dm_config_get_uint32(sn, "zero_new_blocks", &zero))
return SEG_LOG_ERROR("Could not read zero_new_blocks for");
+ seg->zero_new_blocks = (zero) ? THIN_ZERO_YES : THIN_ZERO_NO;
+
/* Read messages */
for (; sn; sn = sn->sib)
if (!(sn->v) && !_thin_pool_add_message(seg, sn->key, sn->child))
@@ -165,8 +168,13 @@ static int _thin_pool_text_export(const struct lv_segment *seg, struct formatter
return 0;
}
- if (seg->zero_new_blocks)
+ if (seg->zero_new_blocks == THIN_ZERO_YES)
outf(f, "zero_new_blocks = 1");
+ else if (seg->zero_new_blocks != THIN_ZERO_NO) {
+ log_error(INTERNAL_ERROR "Invalid zero new blocks value %d.",
+ seg->zero_new_blocks);
+ return 0;
+ }
dm_list_iterate_items(tmsg, &seg->thin_messages) {
/* Extra validation */
@@ -304,7 +312,7 @@ static int _thin_pool_add_target_line(struct dev_manager *dm,
seg->transaction_id,
metadata_dlid, pool_dlid,
seg->chunk_size, low_water_mark,
- seg->zero_new_blocks ? 0 : 1))
+ (seg->zero_new_blocks == THIN_ZERO_YES) ? 0 : 1))
return_0;
if (attr & THIN_FEATURE_DISCARDS) {
diff --git a/tools/lvchange.c b/tools/lvchange.c
index cba0496..8fae806 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -98,7 +98,7 @@ static int _lvchange_pool_update(struct cmd_context *cmd,
}
if (arg_is_set(cmd, zero_ARG)) {
- val = arg_uint_value(cmd, zero_ARG, 1);
+ val = arg_uint_value(cmd, zero_ARG, 0) ? THIN_ZERO_YES : THIN_ZERO_NO;
if (val != first_seg(lv)->zero_new_blocks) {
first_seg(lv)->zero_new_blocks = val;
update++;
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 3d7259e..4ed5018 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -3063,9 +3063,9 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
const char *discards_name;
if (arg_is_set(cmd, zero_ARG))
- seg->zero_new_blocks = arg_int_value(cmd, zero_ARG, 0);
+ seg->zero_new_blocks = arg_int_value(cmd, zero_ARG, 0) ? THIN_ZERO_YES : THIN_ZERO_NO;
else
- seg->zero_new_blocks = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, vg->profile);
+ seg->zero_new_blocks = find_config_tree_bool(cmd, allocation_thin_pool_zero_CFG, vg->profile) ? THIN_ZERO_YES : THIN_ZERO_NO;
if (arg_is_set(cmd, discards_ARG))
seg->discards = (thin_discards_t) arg_uint_value(cmd, discards_ARG, THIN_DISCARDS_PASSDOWN);
@@ -3097,7 +3097,7 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
if (!vg_write(vg) || !vg_commit(vg))
return_0;
- if (seg->zero_new_blocks &&
+ if ((seg->zero_new_blocks == THIN_ZERO_YES) &&
seg->chunk_size >= DEFAULT_THIN_POOL_CHUNK_SIZE_PERFORMANCE * 2)
log_warn("WARNING: Pool zeroing and large %s chunk size slows down provisioning.",
display_size(cmd, seg->chunk_size));
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 206a10b..63b2c6d 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -1079,7 +1079,7 @@ static int _lvcreate_params(struct cmd_context *cmd,
(lp->create_pool &&
!get_pool_params(cmd, lp->segtype, &lp->passed_args,
&lp->pool_metadata_size, &lp->pool_metadata_spare,
- &lp->chunk_size, &lp->discards, &lp->zero)) ||
+ &lp->chunk_size, &lp->discards, &lp->zero_new_blocks)) ||
!_read_cache_params(cmd, lp) ||
!_read_mirror_and_raid_params(cmd, lp))
return_0;
diff --git a/tools/toollib.c b/tools/toollib.c
index c10f5ca..c9461e5 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2017 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -1199,22 +1199,26 @@ int get_pool_params(struct cmd_context *cmd,
int *pool_metadata_spare,
uint32_t *chunk_size,
thin_discards_t *discards,
- int *zero)
+ thin_zero_t *zero_new_blocks)
{
*passed_args = 0;
if (segtype_is_thin_pool(segtype) || segtype_is_thin(segtype)) {
if (arg_is_set(cmd, zero_ARG)) {
*passed_args |= PASS_ARG_ZERO;
- *zero = arg_int_value(cmd, zero_ARG, 1);
- log_very_verbose("%s pool zeroing.", *zero ? "Enabling" : "Disabling");
- }
+ *zero_new_blocks = arg_int_value(cmd, zero_ARG, 0) ? THIN_ZERO_YES : THIN_ZERO_NO;
+ log_very_verbose("%s pool zeroing.",
+ (*zero_new_blocks == THIN_ZERO_YES) ? "Enabling" : "Disabling");
+ } else
+ *zero_new_blocks = THIN_ZERO_UNSELECTED;
+
if (arg_is_set(cmd, discards_ARG)) {
*passed_args |= PASS_ARG_DISCARDS;
*discards = (thin_discards_t) arg_uint_value(cmd, discards_ARG, 0);
log_very_verbose("Setting pool discards to %s.",
get_pool_discards_name(*discards));
- }
+ } else
+ *discards = THIN_DISCARDS_UNSELECTED;
}
if (arg_from_list_is_negative(cmd, "may not be negative",
diff --git a/tools/toollib.h b/tools/toollib.h
index 504721e..7c588fc 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -214,7 +214,7 @@ int get_pool_params(struct cmd_context *cmd,
int *pool_metadata_spare,
uint32_t *chunk_size,
thin_discards_t *discards,
- int *zero);
+ thin_zero_t *zero_new_blocks);
int get_stripe_params(struct cmd_context *cmd, const struct segment_type *segtype,
uint32_t *stripes, uint32_t *stripe_size,
7 years, 2 months