1
From: Alasdair G Kergon <agk@redhat.com>
2
Subject: discards: don't discard reconfigured extents
4
Update release_lv_segment_area not to discard any PV extents,
5
as it also gets used when moving extents between LVs.
6
Instead, call a new function release_and_discard_lv_segment_area() in
7
the two places where data should be discarded - lv_reduce() and
8
remove_mirrors_from_segments().
10
Origin: upstream, https://lists.fedorahosted.org/pipermail/lvm2-commits/2012-June/000039.html
11
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=832392
12
Bug-Debian: http://bugs.debian.org/691271
14
diff --git a/lib/metadata/lv_alloc.h b/lib/metadata/lv_alloc.h
15
index 71ca1ab..9f8e0e3 100644
16
--- a/lib/metadata/lv_alloc.h
17
+++ b/lib/metadata/lv_alloc.h
18
@@ -42,6 +42,7 @@ int move_lv_segment_area(struct lv_segment *seg_to, uint32_t area_to,
19
struct lv_segment *seg_from, uint32_t area_from);
20
int release_lv_segment_area(struct lv_segment *seg, uint32_t s,
21
uint32_t area_reduction);
22
+int release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_t s, uint32_t area_reduction);
25
struct alloc_handle *allocate_extents(struct volume_group *vg,
26
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
27
index bdcc925..a0be887 100644
28
--- a/lib/metadata/lv_manip.c
29
+++ b/lib/metadata/lv_manip.c
30
@@ -299,17 +299,22 @@ struct lv_segment *alloc_snapshot_seg(struct logical_volume *lv,
34
-int release_lv_segment_area(struct lv_segment *seg, uint32_t s,
35
- uint32_t area_reduction)
36
+static int _release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_t s,
37
+ uint32_t area_reduction, int with_discard)
39
if (seg_type(seg, s) == AREA_UNASSIGNED)
42
if (seg_type(seg, s) == AREA_PV) {
43
+ if (with_discard && !discard_pv_segment(seg_pvseg(seg, s), area_reduction))
46
if (!release_pv_segment(seg_pvseg(seg, s), area_reduction))
49
if (seg->area_len == area_reduction)
50
seg_type(seg, s) = AREA_UNASSIGNED;
55
@@ -365,6 +370,16 @@ int release_lv_segment_area(struct lv_segment *seg, uint32_t s,
59
+int release_and_discard_lv_segment_area(struct lv_segment *seg, uint32_t s, uint32_t area_reduction)
61
+ return _release_and_discard_lv_segment_area(seg, s, area_reduction, 1);
64
+int release_lv_segment_area(struct lv_segment *seg, uint32_t s, uint32_t area_reduction)
66
+ return _release_and_discard_lv_segment_area(seg, s, area_reduction, 0);
70
* Move a segment area from one segment to another
72
@@ -501,7 +516,7 @@ static int _lv_segment_reduce(struct lv_segment *seg, uint32_t reduction)
73
area_reduction = reduction;
75
for (s = 0; s < seg->area_count; s++)
76
- if (!release_lv_segment_area(seg, s, area_reduction))
77
+ if (!release_and_discard_lv_segment_area(seg, s, area_reduction))
80
seg->len -= reduction;
81
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
82
index d943175..61e4b47 100644
83
--- a/lib/metadata/mirror.c
84
+++ b/lib/metadata/mirror.c
85
@@ -1469,7 +1469,7 @@ int remove_mirrors_from_segments(struct logical_volume *lv,
88
for (s = new_mirrors + 1; s < seg->area_count; s++)
89
- if (!release_lv_segment_area(seg, s, seg->area_len))
90
+ if (!release_and_discard_lv_segment_area(seg, s, seg->area_len))
93
seg->area_count = new_mirrors + 1;