All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] Fix extent rounding for striped segments.
@ 2011-06-09 14:30 Milan Broz
  2011-06-09 14:30 ` [PATCH 2/4] Validate mirror segments size Milan Broz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Milan Broz @ 2011-06-09 14:30 UTC (permalink / raw)
  To: lvm-devel

We should never remove more extents than requested by user,
so round up to next stripe boundary during lvreduce.

Also this fixes round to zero sized LV bug:

# lvcreate -i2 -I 64k -l10 -n lvs vg_test
# lvreduce -f -l1 vg_test/lvs
  Rounding size (1 extents) down to stripe boundary size for segment (0 extents)
  WARNING: Reducing active logical volume to 0
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Reducing logical volume lvs to 0
  Failed to suspend lvs

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 test/t-lvextend-percent-extents.sh |    5 +++++
 tools/lvresize.c                   |   10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/test/t-lvextend-percent-extents.sh b/test/t-lvextend-percent-extents.sh
index 24fac60..ecd5a1b 100755
--- a/test/t-lvextend-percent-extents.sh
+++ b/test/t-lvextend-percent-extents.sh
@@ -99,3 +99,8 @@ check lv_field $vg/$lv seg_count 2
 lvreduce -f -l -$(( $pe_count * 1 )) $vg/$lv
 check lv_field $vg/$lv seg_count 1
 
+# do not reduce to 0 extents
+lvremove -f $vg/$lv
+lvcreate -i2 -I 64k -l10 -n $lv $vg
+lvreduce -f -l1 $vg/$lv
+check lv_field $vg/$lv lv_size "8.00m"
diff --git a/tools/lvresize.c b/tools/lvresize.c
index b9084e6..30e0bf0 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -575,11 +575,17 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 		return EINVALID_CMD_LINE;
 	}
 
-	if ((lp->stripes > 1)) {
+	if (lp->stripes > 1) {
 		if (!(stripesize_extents = lp->stripe_size / vg->extent_size))
 			stripesize_extents = 1;
 
-		if ((size_rest = seg_size % (lp->stripes * stripesize_extents))) {
+		size_rest = seg_size % (lp->stripes * stripesize_extents);
+		if (size_rest && lp->resize == LV_REDUCE) {
+			log_print("Rounding size (%d extents) up to stripe "
+				  "boundary size for segment (%d extents)",
+				  lp->extents, lp->extents + size_rest);
+			lp->extents = lp->extents + size_rest;
+		} else if (size_rest) {
 			log_print("Rounding size (%d extents) down to stripe "
 				  "boundary size for segment (%d extents)",
 				  lp->extents, lp->extents - size_rest);
-- 
1.7.5.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] Validate mirror segments size
  2011-06-09 14:30 [PATCH 1/4] Fix extent rounding for striped segments Milan Broz
@ 2011-06-09 14:30 ` Milan Broz
  2011-06-09 14:30 ` [PATCH 3/4] Fix mirrored stripe reduction Milan Broz
  2011-06-09 14:30 ` [PATCH 4/4] Fix dmsetup table output (different format in 2.02.85) Milan Broz
  2 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2011-06-09 14:30 UTC (permalink / raw)
  To: lvm-devel

Currently some operation with striped mirrors lead
to corrupted metadata, this patch just add detection of such
situation.

Example:
# lvcreate -i2 -l10 -n lvs vg_test
# lvconvert -m1 vg_test/lvs

# lvreduce -f -l1 vg_test/lvs
  Reducing logical volume lvs to 4.00 MiB
  Segment extent reduction 9not divisible by #stripes 2
  Logical volume lvs successfully resized

# lvremove vg_test/lvs
  Segment extent reduction 1not divisible by #stripes 2
  LV segment lvs:0-4294967295 is incorrectly listed as being used by LV lvs_mimage_0
  Internal error: LV segments corrupted in lvs_mimage_0.

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 lib/metadata/merge.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index 3b8895c..8de9ef4 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -204,6 +204,16 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
 					inc_error_count;
 				}
 			}
+
+			if (complete_vg && seg_is_mirrored(seg) &&
+			    seg_type(seg, s) == AREA_LV &&
+			    seg_lv(seg, s)->le_count != seg->area_len) {
+				log_error("LV %s: mirrored LV segment %u has "
+					  "wrong size %u (should be %u).",
+					  lv->name, s, seg_lv(seg, s)->le_count,
+					  seg->area_len);
+				inc_error_count;
+			}
 		}
 
 		le += seg->len;
-- 
1.7.5.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] Fix mirrored stripe reduction.
  2011-06-09 14:30 [PATCH 1/4] Fix extent rounding for striped segments Milan Broz
  2011-06-09 14:30 ` [PATCH 2/4] Validate mirror segments size Milan Broz
@ 2011-06-09 14:30 ` Milan Broz
  2011-06-09 14:30 ` [PATCH 4/4] Fix dmsetup table output (different format in 2.02.85) Milan Broz
  2 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2011-06-09 14:30 UTC (permalink / raw)
  To: lvm-devel

Patch adds check for stripe not only in direct
LV segment but also in mirror image segment.

This prevents bugs like:

# lvcreate -i2 -l10 -n lv vg_test
# lvconvert -m1 -i1 vg_test/lv

# lvreduce -f -l1 vg_test/lv
  WARNING: Reducing active logical volume to 4.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Reducing logical volume lv to 4.00 MiB
  Segment extent reduction 9 not divisible by #stripes 2
  Logical volume lv successfully resized

# lvremove -f vg_test
  Segment extent reduction 1 not divisible by #stripes 2
  LV segment lv:0-4294967295 is incorrectly listed as being used by LV lv_mimage_0
  Internal error: LV segments corrupted in lv_mimage_0.

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 test/t-lvconvert-mirror.sh |    8 ++++++++
 tools/lvresize.c           |   34 ++++++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/test/t-lvconvert-mirror.sh b/test/t-lvconvert-mirror.sh
index 129a4d4..64c407b 100644
--- a/test/t-lvconvert-mirror.sh
+++ b/test/t-lvconvert-mirror.sh
@@ -240,3 +240,11 @@ lvconvert -m+1 --mirrorlog disk -i1 $vg/$lv1 $dev4 $dev3:0
 check mirror $vg $lv1 $dev3
 check mirror_no_temporaries $vg $lv1
 check mirror_legs $vg $lv1 3
+
+# simple mirrored stripe
+aux prepare_vg 5
+lvcreate -i2 -l10 -n $lv1 $vg
+lvconvert -m1 -i1 $vg/$lv1
+lvreduce -f -l1 $vg/$lv1
+lvextend -f -l10 $vg/$lv1
+lvremove -ff $vg/$lv1
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 30e0bf0..02f1f32 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -305,6 +305,34 @@ static int _adjust_policy_params(struct cmd_context *cmd,
 	return 1;
 }
 
+static uint32_t lvseg_get_stripes(struct lv_segment *seg, uint32_t *stripesize)
+{
+	uint32_t s;
+	struct lv_segment *seg_mirr;
+
+	/* If segment mirrored, check if images are striped */
+	if (seg_is_mirrored(seg))
+		for (s = 0; s < seg->area_count; s++) {
+			if (seg_type(seg, s) != AREA_LV)
+				continue;
+			seg_mirr = first_seg(seg_lv(seg, s));
+
+			if (seg_is_striped(seg_mirr)) {
+				seg = seg_mirr;
+				break;
+			}
+		}
+
+
+	if (seg_is_striped(seg)) {
+		*stripesize = seg->stripe_size;
+		return seg->area_count;
+	}
+
+	*stripesize = 0;
+	return 0;
+}
+
 static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 		     struct lvresize_params *lp)
 {
@@ -548,10 +576,8 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
 		dm_list_iterate_items(seg, &lv->segments) {
 			seg_extents = seg->len;
 
-			if (seg_is_striped(seg)) {
-				seg_stripesize = seg->stripe_size;
-				seg_stripes = seg->area_count;
-			}
+			/* Check for underlying stripe sizes */
+			seg_stripes = lvseg_get_stripes(seg, &seg_stripesize);
 
 			if (seg_is_mirrored(seg))
 				seg_mirrors = lv_mirror_count(seg->lv);
-- 
1.7.5.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] Fix dmsetup table output (different format in 2.02.85)
  2011-06-09 14:30 [PATCH 1/4] Fix extent rounding for striped segments Milan Broz
  2011-06-09 14:30 ` [PATCH 2/4] Validate mirror segments size Milan Broz
  2011-06-09 14:30 ` [PATCH 3/4] Fix mirrored stripe reduction Milan Broz
@ 2011-06-09 14:30 ` Milan Broz
  2 siblings, 0 replies; 4+ messages in thread
From: Milan Broz @ 2011-06-09 14:30 UTC (permalink / raw)
  To: lvm-devel

In previous versions < 2.02.85 dmsetup table <dev>
produced just dmsetup table, no device.

# dmsetup table abc
0 100 zero

Now is the output changed to:
# dmsetup table abc
abc: 0 100 zero

It should be only for all and multiple devices, not for one.

It breaks at least cryptsetup test suite, I guess there
are more problems.

Patch somehow workarounds it, I have no idea what was the intention
for this change.
I guess even Alasdair should use patch review process sometimes :-p

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 test/t-covercmd.sh |    5 +++++
 tools/dmsetup.c    |    9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/test/t-covercmd.sh b/test/t-covercmd.sh
index 7843798..8c86388 100755
--- a/test/t-covercmd.sh
+++ b/test/t-covercmd.sh
@@ -34,6 +34,11 @@ pvcreate --norestorefile -u $TEST_UUID --metadatacopies 0 $dev5
 vgcreate -c n $vg $(cat DEVICES)
 lvcreate -n $lv -l 5 -i5 -I256 $vg
 
+# dmsetup table works
+dmsetup table "$vg-$lv"
+test $(dmsetup table "$vg-$lv" | cut -d' '  -f 3) = "striped"
+test $(dmsetup table "$vg-$lv" "$vg-$lv" | head -n 1 | cut -d:  -f 1) = "$vg-$lv"
+
 # test *scan and *display tools
 pvscan
 vgscan
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 2a8e5a6..0a2e429 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -1310,7 +1310,7 @@ static int _process_all(const struct command *cmd, int argc, char **argv, int si
 
 	do {
 		names = (struct dm_names *)((char *) names + next);
-		if (!fn(cmd, argc, argv, names, 1))
+		if (!fn(cmd, argc, argv, names, 2))
 			r = 0;
 		next = names->next;
 	} while (next);
@@ -1590,7 +1590,7 @@ static int _status(CMD_ARGS)
 			   _switches[VERBOSE_ARG]) {
 			if (!matched && _switches[VERBOSE_ARG])
 				_display_info(dmt);
-			if (multiple_devices && !_switches[VERBOSE_ARG])
+			if (multiple_devices > 1 && !_switches[VERBOSE_ARG])
 				printf("%s: ", name);
 			if (target_type) {
 				/* Suppress encryption key */
@@ -3412,7 +3412,10 @@ int main(int argc, char **argv)
 	#endif
 
       doit:
-	multiple_devices = (argc > 1);
+	if (argc > 1)
+		multiple_devices = (argc > 2) ? 2 : 1;
+	else
+		multiple_devices = 0;
 	do {
 		if (!cmd->fn(cmd, argc--, argv++, NULL, multiple_devices)) {
 			fprintf(stderr, "Command failed\n");
-- 
1.7.5.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-09 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-09 14:30 [PATCH 1/4] Fix extent rounding for striped segments Milan Broz
2011-06-09 14:30 ` [PATCH 2/4] Validate mirror segments size Milan Broz
2011-06-09 14:30 ` [PATCH 3/4] Fix mirrored stripe reduction Milan Broz
2011-06-09 14:30 ` [PATCH 4/4] Fix dmsetup table output (different format in 2.02.85) Milan Broz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.