diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2016-05-05 21:30:15 +0200 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2016-05-05 23:30:49 +0200 |
commit | def65507e6beab7d1830622492772cc89abe4ccb (patch) | |
tree | 8db1ac03899a8c63c2058ed21743d711b1ce8424 | |
parent | ae805eea50b1033115a18b8a0c9931c2c917b8b2 (diff) | |
download | lvm2-def65507e6beab7d1830622492772cc89abe4ccb.tar.gz |
cache: add cache_set_params function
Wrapping function to handle setup of various cache related params.
Reusable with lvcreate & lvconvert.
-rw-r--r-- | lib/metadata/cache_manip.c | 34 | ||||
-rw-r--r-- | lib/metadata/metadata-exported.h | 5 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index 5ecfbe2f1..27a716a27 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -632,6 +632,40 @@ out: } /* + * Universal 'wrapper' function do-it-all + * to update all commonly specified cache parameters + */ +int cache_set_params(struct lv_segment *seg, + const char *cache_mode, + const char *policy_name, + const struct dm_config_tree *policy_settings, + uint32_t chunk_size) +{ + struct lv_segment *pool_seg; + + if (!cache_set_mode(seg, cache_mode)) + return_0; + + if (!cache_set_policy(seg, policy_name, policy_settings)) + return_0; + + 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)) + 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, + THIN_CHUNK_SIZE_CALC_METHOD_GENERIC)) + return_0; + } + + return 1; +} + +/* * Wipe cache pool metadata area before use. * * Activates metadata volume as 'cache-pool' so regular wiping diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 54c2668a6..b3f450afc 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -1216,6 +1216,11 @@ int cache_mode_is_set(const struct lv_segment *seg); int cache_set_mode(struct lv_segment *cache_seg, const char *str); 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, + const char *cache_mode, + const char *policy_name, + const struct dm_config_tree *policy_settings, + uint32_t chunk_size); 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, |