Fix extent rounding for striped segments.
PATCH 1/4 Fix extent rounding for striped segments.
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
--- test/t-lvextend-percent-extents.sh | 5 +++++ tools/lvresize.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
test/t-lvextend-percent-extents.sh +5 -0
@@ -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"
tools/lvresize.c +8 -2
@@ -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);
Signature · 1 line
1.7.5.3
PATCH 2/4 Validate mirror segments size
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.
--- lib/metadata/merge.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
lib/metadata/merge.c +10 -0
@@ -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;
Signature · 1 line
1.7.5.3
PATCH 3/4 Fix mirrored stripe reduction.
In reply to Milan BrozPatch 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.
--- test/t-lvconvert-mirror.sh | 8 ++++++++ tools/lvresize.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-)
test/t-lvconvert-mirror.sh +8 -0
@@ -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
tools/lvresize.c +30 -4
@@ -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);
Signature · 1 line
1.7.5.3
PATCH 4/4 Fix dmsetup table output (different format in 2.02.85)
In reply to Milan BrozIn 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
--- test/t-covercmd.sh | 5 +++++ tools/dmsetup.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-)
test/t-covercmd.sh +5 -0
@@ -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
tools/dmsetup.c +6 -3
@@ -1310,7 +1310,7 @@ static int _process_all(const struct command *cmd, int argc, char **argv, int sido { 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");
Signature · 1 line
1.7.5.3