Skip to contentSkip to conversation

master - lvconvert: Conversions between striped and raid0.

PATCH Alasdair Kergon 1 participant 1 message Jun 28, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=686acce23fed6bd72af63201e4cc56bc5958379e
Commit:        686acce23fed6bd72af63201e4cc56bc5958379e
Parent:        6f216692b47b38f480e50d213de5c513a309d9e0
Author:        Alasdair G Kergon <[email protected]>
AuthorDate:    Tue Jun 28 23:44:15 2016 +0100
Committer:     Alasdair G Kergon <[email protected]>
CommitterDate: Tue Jun 28 23:44:15 2016 +0100

lvconvert: Conversions between striped and raid0.

---
 WHATS_NEW                 |    1 +
 lib/metadata/lv.c         |   30 ++-
 lib/metadata/lv_manip.c   |    3 +-
 lib/metadata/metadata.h   |    4 +
 lib/metadata/raid_manip.c |  595 +++++++++++++++++++++++++++++++++++++++++----
 lib/metadata/segtype.c    |   13 +
 lib/metadata/segtype.h    |    2 +
 lib/misc/util.h           |    2 +
 8 files changed, 593 insertions(+), 57 deletions(-)
WHATS_NEW +1 -0
index 3184412..619c64d 100644
@@ -1,5 +1,6 @@
 Version 2.02.159 - 
 =================================
+  Support conversions between striped and raid0 segment types.
   Add infrastructure for raid takeover lvconvert options.
 
 Version 2.02.158 - 25th June 2016
lib/metadata/lv.c +23 -7
index cdf658e..e7a56cf 100644
@@ -577,14 +577,14 @@ char *lv_name_dup(struct dm_pool *mem, const struct logical_volume *lv)
 
 char *lv_fullname_dup(struct dm_pool *mem, const struct logical_volume *lv)
 {
-        char lvfullname[NAME_LEN * 2 + 2];
+	char lvfullname[NAME_LEN * 2 + 2];
 
-        if (dm_snprintf(lvfullname, sizeof(lvfullname), "%s/%s", lv->vg->name, lv->name) < 0) {
-                log_error("lvfullname snprintf failed");
-                return NULL;
-        }
+	if (dm_snprintf(lvfullname, sizeof(lvfullname), "%s/%s", lv->vg->name, lv->name) < 0) {
+		log_error("lvfullname snprintf failed");
+		return NULL;
+	}
 
-        return dm_pool_strdup(mem, lvfullname);
+	return dm_pool_strdup(mem, lvfullname);
 }
 
 struct logical_volume *lv_parent(const struct logical_volume *lv)
@@ -930,7 +930,7 @@ char *lv_dmpath_dup(struct dm_pool *mem, const struct logical_volume *lv)
 	if (!*lv->vg->name)
 		return dm_pool_strdup(mem, "");
 
-        if (!(name = dm_build_dm_name(mem, lv->vg->name, lv->name, NULL))) {
+	if (!(name = dm_build_dm_name(mem, lv->vg->name, lv->name, NULL))) {
 		log_error("dm_build_dm_name failed");
 		return NULL;
 	}
@@ -1581,3 +1581,19 @@ struct profile *lv_config_profile(const struct logical_volume *lv)
 {
 	return lv->profile ? : lv->vg->profile;
 }
+
+int lv_has_constant_stripes(struct logical_volume *lv)
+{
+	uint32_t previous_area_count = 0;
+	struct lv_segment *seg;
+
+	dm_list_iterate_items(seg, &lv->segments) {
+		if (!seg_is_striped(seg))
+			return 0;
+		if (previous_area_count && previous_area_count != seg->area_count)
+			return 0;
+		previous_area_count = seg->area_count;
+	}
+
+	return 1;
+}
lib/metadata/lv_manip.c +2 -1
index 40c1c1a..db71939 100644
@@ -3301,7 +3301,8 @@ static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
 
 void alloc_destroy(struct alloc_handle *ah)
 {
-	dm_pool_destroy(ah->mem);
+	if (ah)
+		dm_pool_destroy(ah->mem);
 }
 
 /*
lib/metadata/metadata.h +4 -0
index 31c9346..e6dc14a 100644
@@ -415,6 +415,10 @@ struct logical_volume *alloc_lv(struct dm_pool *mem);
  */
 int check_lv_segments(struct logical_volume *lv, int complete_vg);
 
+/*
+ * Does every LV segment have the same number of stripes?
+ */
+int lv_has_constant_stripes(struct logical_volume *lv);
 
 /*
  * Checks that a replicator segment is correct.
lib/metadata/raid_manip.c +546 -49

769 lines not on this page · raw message

lib/metadata/segtype.c +13 -0
index 0e17111..8d8b28c 100644
@@ -34,3 +34,16 @@ struct segment_type *get_segtype_from_string(struct cmd_context *cmd,
 
 	return segtype;
 }
+
+struct segment_type *get_segtype_from_flag(struct cmd_context *cmd, uint64_t flag)
+{
+	struct segment_type *segtype;
+
+	dm_list_iterate_items(segtype, &cmd->segtypes)
+		if (flag & segtype->flags)
+			return segtype;
+
+	log_error(INTERNAL_ERROR "Unrecognised segment type flag 0x%" PRIu64, flag);
+
+	return NULL;
+}
lib/metadata/segtype.h +2 -0
index f3b1510..b43f228 100644
@@ -222,6 +222,8 @@ struct segtype_handler {
 
 struct segment_type *get_segtype_from_string(struct cmd_context *cmd,
 					     const char *str);
+struct segment_type *get_segtype_from_flag(struct cmd_context *cmd,
+					   uint64_t flag);
 
 struct segtype_library;
 int lvm_register_segtype(struct segtype_library *seglib,
lib/misc/util.h +2 -0
index 1011fdd..730b903 100644
@@ -27,6 +27,8 @@
 		     (void) (&_a == &_b); \
 		     _a > _b ? _a : _b; })
 
+#define is_power_of_2(n) ((n) && !((n) & ((n) - 1)))
+
 #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
 #define uninitialized_var(x) x
 #else