[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH mirror 5/13] lv_mirror_count() to cope with stacked mirror



Change lv_mirror_count() to cope with stacked mirror with resync layers.

When adding mirrors to already mirrored LV, LVM2 will stack a temporary
mirror layer for resync.

So the lv_mirror_count() should take into account these things:
  - loop down through the mirror stack
  - exclude the resync LV from the count

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America

Change lv_mirror_count() to cope with stacked mirror with resync layers.

When adding mirrors to already mirrored LV, LVM2 will stack a temporary
mirror layer for resync.

So the lv_mirror_count() should take into account these things:
  - loop down through the mirror stack
  - exclude the resync LV from the count

Index: LVM2.work/lib/metadata/mirror.c
===================================================================
--- LVM2.work.orig/lib/metadata/mirror.c
+++ LVM2.work/lib/metadata/mirror.c
@@ -33,11 +33,40 @@
 #define MIRROR_ALLOCATE_ANYWHERE 2
 
 /*
+ * Returns true if the lv is temporary mirror layer for resync
+ */
+int is_temporary_mirror_layer(const struct logical_volume *lv)
+{
+	if (lv->status & MIRROR_IMAGE
+	    && lv->status & MIRRORED
+	    && !(lv->status & LOCKED))
+		return 1;
+
+	return 0;
+}
+
+/*
  * Returns the number of mirrors of the LV
  */
 uint32_t lv_mirror_count(const struct logical_volume *lv)
 {
-	return (lv->status & MIRRORED) ? first_seg(lv)->area_count : 1;
+	struct lv_segment *seg;
+	uint32_t s, mirrors;
+
+	if (!(lv->status & MIRRORED))
+		return 1;
+
+	seg = first_seg(lv);
+	mirrors = seg->area_count;
+
+	for (s = 0; s < seg->area_count; s++) {
+		if (seg_type(seg, s) != AREA_LV)
+			continue;
+		if (is_temporary_mirror_layer(seg_lv(seg, s)))
+			mirrors += lv_mirror_count(seg_lv(seg, s)) - 1;
+	}
+
+	return mirrors;
 }
 
 struct lv_segment *find_mirror_seg(struct lv_segment *seg)
Index: LVM2.work/lib/metadata/metadata-exported.h
===================================================================
--- LVM2.work.orig/lib/metadata/metadata-exported.h
+++ LVM2.work/lib/metadata/metadata-exported.h
@@ -461,6 +461,7 @@ int lv_remove_mirrors(struct cmd_context
 #define MIRROR_BY_SEG	0x00000001U	/* segment-by-segment mirror */
 #define MIRROR_BY_LV	0x00000002U	/* mirror by mimage LVs */
 
+int is_temporary_mirror_layer(const struct logical_volume *lv);
 uint32_t lv_mirror_count(const struct logical_volume *lv);
 uint32_t adjusted_mirror_region_size(uint32_t extent_size, uint32_t extents,
                                     uint32_t region_size);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]