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

[lvm-devel] [PATCH mirror 6/13] Count the correct number of mirror images



If temporary mirror layers are inserted, you can't get
the number of mirror images by seg->area_count.

The patch adds a function to recursively sum up the number
of mirror images.
Used later by lvconvert and reporting functions.

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

Since the mirrored LV could have temporary intermediate mirror layer,
just using seg->area_count is not enough to get the number of mirror legs.

lv_mirror_count() will loop down through the stack.

Index: LVM2.work/lib/metadata/mirror.c
===================================================================
--- LVM2.work.orig/lib/metadata/mirror.c
+++ LVM2.work/lib/metadata/mirror.c
@@ -195,6 +195,26 @@ static int _mirrored_lv_in_sync(struct l
 	return 0;
 }
 
+uint32_t lv_mirror_count(const struct logical_volume *lv)
+{
+	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 (is_temporary_mirror_layer(seg_lv(seg, s))) {
+			mirrors += lv_mirror_count(seg_lv(seg, s)) - 1;
+		}
+	}
+
+	return mirrors;
+}
+
 static int _merge_mirror_images(struct logical_volume *lv,
 				const struct list *mimages)
 {
Index: LVM2.work/lib/metadata/metadata-exported.h
===================================================================
--- LVM2.work.orig/lib/metadata/metadata-exported.h
+++ LVM2.work/lib/metadata/metadata-exported.h
@@ -438,6 +438,7 @@ int remove_mirror_images(struct lv_segme
 			      struct list *removable_pvs, unsigned remove_log);
 int collapse_mirrored_lv(struct logical_volume *lv);
 int is_temporary_mirror_layer(const struct logical_volume *lv);
+uint32_t lv_mirror_count(const struct logical_volume *lv);
 
 int insert_pvmove_mirrors(struct cmd_context *cmd,
 			  struct logical_volume *lv_mirr,

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