Skip to contentSkip to conversation

master - cache: handle older metadata format

PATCH Zdenek Kabelac 1 participant 1 message Nov 16, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e31f4b76f470c7da7328d16551cfaba9cae4674a
Commit:        e31f4b76f470c7da7328d16551cfaba9cae4674a
Parent:        d9295410e98e32636d3bf03ee375c5739bd44b23
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Sun Nov 15 20:03:08 2015 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Nov 16 01:12:57 2015 +0100

cache: handle older metadata format

When reading older lvm2 metadata for cache-pool - we now handle more extended syntax - basically we want to enter most setting when actually creating cached LV.

For this new validation code has been added. However older metadata without new settings set is now found as invalid.

Fix it by adding default settings for cache policy mq and cache mode writethrough.

---
 WHATS_NEW                        |    1 +
 lib/cache_segtype/cache.c        |   34 +++++++++++++++++++++++++++++++
 test/shell/lvchange-cache-old.sh |   41 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 0 deletions(-)
WHATS_NEW +1 -0
index 2dea99c..d5a4a3b 100644
@@ -1,5 +1,6 @@
 Version 2.02.135 - 
 ====================================
+  Fix reading of old metadata with missing cache policy or mode settings.
   Issue error if external_device_info_source=udev and udev db record incomplete.
   Fix passing of 32bit values through daemons (mostly lvmlockd).
   Use local memory pool for whole alloc_handle manipulation.
lib/cache_segtype/cache.c +34 -0
index 733c330..033cabe 100644
@@ -34,6 +34,32 @@ static unsigned _feature_mask;
         log_error(t " segment %s of logical volume %s.", ## p,	\
                   dm_config_parent_name(sn), seg->lv->name), 0;
 
+/*
+ * When older metadata are loaded without newer settings,
+ * set then to default settings (the one that could have been
+ * used implicitely at that time).
+ *
+ * Needs both segments cache and cache_pool to be loaded.
+ */
+static int _fix_missing_defaults(struct lv_segment *cpool_seg)
+{
+	if (!cpool_seg->policy_name) {
+		cpool_seg->policy_name = "mq";
+		log_verbose("Cache is missing cache policy, using %s.",
+			    cpool_seg->policy_name);
+	}
+
+	if (!cache_mode_is_set(cpool_seg)) {
+		if (!cache_set_mode(cpool_seg, "writethrough")) {
+			log_error(INTERNAL_ERROR "Failed to writethrough cache mode.");
+			return 0;
+		}
+		log_verbose("Cache is missing cache mode, using %s.",
+			    get_cache_mode_name(cpool_seg));
+	}
+
+	return 1;
+}
 
 static int _cache_pool_text_import(struct lv_segment *seg,
 				   const struct dm_config_node *sn,
@@ -115,6 +141,10 @@ static int _cache_pool_text_import(struct lv_segment *seg,
 	if (!attach_pool_metadata_lv(seg, meta_lv))
 		return_0;
 
+	if (!dm_list_empty(&seg->lv->segs_using_this_lv) &&
+	    !_fix_missing_defaults(seg))
+		return_0;
+
 	return 1;
 }
 
@@ -319,6 +349,10 @@ static int _cache_text_import(struct lv_segment *seg,
 	if (!attach_pool_lv(seg, pool_lv, NULL, NULL))
 		return_0;
 
+	if (!dm_list_empty(&pool_lv->segments) &&
+	    !_fix_missing_defaults(first_seg(pool_lv)))
+		return_0;
+
 	return 1;
 }
 
test/shell/lvchange-cache-old.sh new file +41 -0

41 lines not on this page · raw message