Skip to contentSkip to conversation

master - cache: api update

PATCH Zdenek Kabelac 1 participant 1 message Aug 12, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f0c18fceb43d77b0a79685fc7b1c8bbe64df7e97
Commit:        f0c18fceb43d77b0a79685fc7b1c8bbe64df7e97
Parent:        22a1337a9ba1ebf73c3f0b27f621d9d8917bf6cf
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Tue Aug 11 14:01:12 2015 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Aug 12 14:32:24 2015 +0200

cache: api update

Change logic and naming of some internal API functions.

cache_set_mode() and cache_set_policy() both take segment.

cache mode is now correctly 'masked-in'.

If the passed segment is 'cache' segment - it will automatically try to find 'defaults' according to profiles if the are NOT specified on command line or they are NOT already set for cache-pool.

These defaults are never set for cache-pool.

---
 WHATS_NEW                        |    1 +
 lib/cache_segtype/cache.c        |   53 +++++++--------
 lib/metadata/cache_manip.c       |  129 ++++++++++++++++++++++++++++++--------
 lib/metadata/lv.c                |    2 +-
 lib/metadata/lv_manip.c          |   31 +++++++---
 lib/metadata/metadata-exported.h |    9 ++-
 lib/report/report.c              |    2 +-
 tools/lvchange.c                 |    2 +-
 tools/lvconvert.c                |    8 ++-
 9 files changed, 166 insertions(+), 71 deletions(-)
WHATS_NEW +1 -0
index 7c35d13..7fcf49a 100644
@@ -1,5 +1,6 @@
 Version 2.02.128 - 
 ===================================
+  Enhance internal API cache_set_mode() and cache_set_policy().
   Enhance toollib's get_cache_params().
   Runtime detect presence of cache smq policy.
   Add demo cache-mq  and cache-smq profiles.
lib/cache_segtype/cache.c +24 -27

75 lines not on this page · raw message

lib/metadata/cache_manip.c +102 -27

164 lines not on this page · raw message

lib/metadata/lv.c +1 -1
index df784c1..c775077 100644
@@ -131,7 +131,7 @@ char *lvseg_discards_dup(struct dm_pool *mem, const struct lv_segment *seg)
 
 char *lvseg_cachemode_dup(struct dm_pool *mem, const struct lv_segment *seg)
 {
-	const char *name = get_cache_pool_cachemode_name(seg);
+	const char *name = get_cache_mode_name(seg);
 
 	if (!name)
 		return_NULL;
lib/metadata/lv_manip.c +23 -8
index b22773e..f13df1b 100644
@@ -7264,17 +7264,26 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
 	memlock_unlock(vg->cmd);
 
 	if (seg_is_cache_pool(lp) || seg_is_cache(lp)) {
-		pool_lv = pool_lv ? : lv;
-		if (!lv_cache_set_policy(pool_lv, lp->policy_name, lp->policy_settings))
-			return_NULL; /* revert? */
-		first_seg(pool_lv)->chunk_size = lp->chunk_size;
-		first_seg(pool_lv)->feature_flags = lp->feature_flags;
-		/* TODO: some calc_policy solution for cache ? */
-		if (!recalculate_pool_chunk_size_with_dev_hints(pool_lv, lp->passed_args,
-								THIN_CHUNK_SIZE_CALC_METHOD_GENERIC)) {
+		if (!cache_set_mode(first_seg(lv), lp->cache_mode)) {
+			stack;
+			goto revert_new_lv;
+		}
+
+		if (!cache_set_policy(first_seg(lv), lp->policy_name, lp->policy_settings)) {
 			stack;
 			goto revert_new_lv;
 		}
+
+		pool_lv = pool_lv ? : lv;
+		if (lp->chunk_size) {
+			first_seg(pool_lv)->chunk_size = lp->chunk_size;
+			/* TODO: some calc_policy solution for cache ? */
+			if (!recalculate_pool_chunk_size_with_dev_hints(pool_lv, lp->passed_args,
+									THIN_CHUNK_SIZE_CALC_METHOD_GENERIC)) {
+				stack;
+				goto revert_new_lv;
+			}
+		}
 	} else if (seg_is_raid(lp)) {
 		first_seg(lv)->min_recovery_rate = lp->min_recovery_rate;
 		first_seg(lv)->max_recovery_rate = lp->max_recovery_rate;
@@ -7478,6 +7487,12 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
 		}
 		lv = tmp_lv;
 
+		if (!cache_set_mode(first_seg(lv), lp->cache_mode))
+			return_NULL; /* revert? */
+
+		if (!cache_set_policy(first_seg(lv), lp->policy_name, lp->policy_settings))
+			return_NULL; /* revert? */
+
 		if (!lv_update_and_reload(lv)) {
 			/* FIXME Do a better revert */
 			log_error("Aborting. Manual intervention required.");
lib/metadata/metadata-exported.h +5 -4
index 03a866a..fff24f0 100644
@@ -1153,8 +1153,11 @@ struct lv_status_cache {
 	dm_percent_t dirty_usage;
 };
 
-const char *get_cache_pool_cachemode_name(const struct lv_segment *seg);
-int set_cache_pool_feature(uint64_t *feature_flags, const char *str);
+const char *get_cache_mode_name(const struct lv_segment *cache_seg);
+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 update_cache_pool_params(const struct segment_type *segtype,
 			     struct volume_group *vg, unsigned attr,
 			     int passed_args, uint32_t pool_data_extents,
@@ -1165,8 +1168,6 @@ int validate_lv_cache_create_origin(const struct logical_volume *origin_lv);
 struct logical_volume *lv_cache_create(struct logical_volume *pool,
 				       struct logical_volume *origin);
 int lv_cache_remove(struct logical_volume *cache_lv);
-int lv_cache_set_policy(struct logical_volume *cache_lv, const char *name,
-			const struct dm_config_tree *settings);
 int wipe_cache_pool(struct logical_volume *cache_pool_lv);
 /* --  metadata/cache_manip.c */
 
lib/report/report.c +1 -1
index c2ab991..a17af32 100644
@@ -2079,7 +2079,7 @@ static int _cachemode_disp(struct dm_report *rh, struct dm_pool *mem,
 		seg = first_seg(seg->pool_lv);
 
 	if (seg_is_cache_pool(seg)) {
-		if (!(cachemode_str = get_cache_pool_cachemode_name(seg)))
+		if (!(cachemode_str = get_cache_mode_name(seg)))
 			return_0;
 
 		return dm_report_field_string(rh, field, &cachemode_str);
tools/lvchange.c +1 -1
index a6ad343..e24c07a 100644
@@ -692,7 +692,7 @@ static int _lvchange_cachepolicy(struct cmd_context *cmd, struct logical_volume
 
 	if (!get_cache_params(cmd, NULL, &name, &settings))
 		goto_out;
-	if (!lv_cache_set_policy(lv, name, settings))
+	if (!cache_set_policy(first_seg(lv), name, settings))
 		goto_out;
 	if (!lv_update_and_reload(lv))
 		goto_out;
tools/lvconvert.c +7 -1
index d48af62..040272a 100644
@@ -3070,7 +3070,7 @@ mda_write:
 	seg->zero_new_blocks = lp->zero ? 1 : 0;
 
 	if ((lp->policy_name || lp->policy_settings) &&
-	    !lv_cache_set_policy(seg->lv, lp->policy_name, lp->policy_settings))
+	    !cache_set_policy(seg, lp->policy_name, lp->policy_settings))
 		return_0;
 
 	/* Rename deactivated metadata LV to have _tmeta suffix */
@@ -3178,6 +3178,12 @@ static int _lvconvert_cache(struct cmd_context *cmd,
 	if (!(cache_lv = lv_cache_create(pool_lv, origin_lv)))
 		return_0;
 
+	if (!cache_set_mode(first_seg(cache_lv), lp->cache_mode))
+		return_0;
+
+	if (!cache_set_policy(first_seg(cache_lv), lp->policy_name, lp->policy_settings))
+		return_0;
+
 	if (!lv_update_and_reload(cache_lv))
 		return_0;