master - pool: validate_pool_chunk_size
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a2aa609810d7d0d6b8ff5b9fe8c6e1e13fbfbbac Commit: a2aa609810d7d0d6b8ff5b9fe8c6e1e13fbfbbac Parent: 7783fe3e93b6fee0e8ea8198917b2d1a3072bdab Author: Zdenek Kabelac <[email protected]> AuthorDate: Mon Oct 6 12:18:57 2014 +0200 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Mon Oct 6 15:23:01 2014 +0200
pool: validate_pool_chunk_size
Introduce pool function for validation of chunk size. It's good idea to be able to reject invalid chunk size when entered on command line before we open VG.
--- WHATS_NEW | 1 + lib/metadata/metadata-exported.h | 1 + lib/metadata/pool_manip.c | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
@@ -1,5 +1,6 @@ Version 2.02.112 - ===================================== + Introduce single validation routine for pool chunk size. Support --yes like --force in vg/lvremove to skip y|n prompt. Support --yes with lvconvert --splitsnapshot. Fix detection of unsupported thin external lvconversions.
lib/metadata/metadata-exported.h +1 -0
@@ -731,6 +731,7 @@ int thin_pool_feature_supported(const struct logical_volume *pool_lv, int featurint recalculate_pool_chunk_size_with_dev_hints (struct logical_volume *pool_lv,int passed_args,int chunk_size_calc_policy); +int validate_pool_chunk_size (struct cmd_context *cmd,const struct segment_type *segtype,uint32_t chunk_size);int update_pool_lv (struct logical_volume *lv,int activate); int update_pool_params(const struct segment_type *segtype, struct volume_group *vg, unsigned target_attr,
lib/metadata/pool_manip.c +40 -0
@@ -232,6 +232,46 @@ struct lv_segment *find_pool_seg(const struct lv_segment *seg)return pool_seg; } +int validate_pool_chunk_size (struct cmd_context *cmd, +const struct segment_type *segtype, +uint32_t chunk_size) +{ +uint32_t min_size, max_size; +const char *name; +int r =1 ; + +if (segtype_is_cache (segtype) ||segtype_is_cache_pool (segtype)) { + min_size =DM_CACHE_MIN_DATA_BLOCK_SIZE ; + max_size =DM_CACHE_MAX_DATA_BLOCK_SIZE ; + name ="Cache" ; + }else if (segtype_is_thin (segtype)) { + min_size =DM_THIN_MIN_DATA_BLOCK_SIZE ; + max_size =DM_THIN_MAX_DATA_BLOCK_SIZE ; + name ="Thin" ; + }else { +log_error (INTERNAL_ERROR "Cannot validate chunk size of " +"%s segtype." , segtype->name); +return 0 ; + } + +if ((chunk_size < min_size) || (chunk_size > max_size)) { +log_error ("%s pool chunk size %s is not in the range %s to %s." , + name,display_size (cmd, chunk_size), +display_size (cmd, min_size), +display_size (cmd, max_size)); + r =0 ; + } + +if (chunk_size & (min_size -1 )) { +log_error ("%s pool chunk size %s must be a multiple of %s." , + name,display_size (cmd, chunk_size), +display_size (cmd, min_size)); + r =0 ; + } + +return r; +} +/* Greatest common divisor */ static unsigned long _gcd (unsigned long n1,unsigned long n2) {