1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-21 22:04:19 +03:00

raid_manip: select by segtype in _raid_conv_unduplicate(); some cleanup

This commit is contained in:
Heinz Mauelshagen 2015-10-06 20:08:44 +02:00
parent 1a1fc812ae
commit 7bbda2e66e
4 changed files with 43 additions and 30 deletions

View File

@ -7739,7 +7739,7 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
dm_list_splice(&lv->tags, &lp->tags);
PFLA("lp->stripe_size=%u", lp->stripe_size);
PFLA("lp->stripes=%u lp->stripe_size=%u lp->mirrors=%u", lp->stripes, lp->stripe_size, lp->mirrors);
if (!lv_extend(lv, create_segtype,
lp->stripes, lp->stripe_size,
lp->mirrors,

View File

@ -4037,6 +4037,17 @@ static int _rename_metasub_lvs(struct logical_volume *lv, enum rename_dir dir)
return __rename_sub_lvs(lv, dir, RAID_META);
}
/* Remove any infox in @seg_lv_name between @suffix and @lv_name */
static void _remove_any_infix(const char *lv_name, char *seg_lv_name, const char *suffix)
{
char *s;
if ((s = strstr(seg_lv_name, suffix))) {
strcpy(seg_lv_name, lv_name);
strcat(seg_lv_name, s);
}
}
/*
* HM Helper:
*
@ -4065,7 +4076,7 @@ static int _raid_split_duplicate(struct logical_volume *lv, const char *split_na
return 0;
}
if (new_image_count != 1) {
if (seg->area_count - new_image_count != 1) {
log_error("Only suitable on duplicating LV %s with \"lvconvert --splitmirrors 1\"",
display_lvname(lv));
return 0;
@ -4131,7 +4142,6 @@ PFL();
!lv_update_and_reload_origin(split_lv))
return 0;
PFL();
#if 1
/* We are down to the last sub lv -> remove the top-level raid1 mapping */
if (seg->area_count == 1) {
struct logical_volume *slv = seg_lv(seg, 0);
@ -4164,29 +4174,19 @@ PFL();
if (!_lv_reset_raid_add_to_list(slv, &removal_lvs))
return 0;
/* Remove "_dup_N" infixes if sub LVs present */
for (s = 0; s < seg->area_count; s++)
if (seg_type(seg, s) == AREA_LV) {
char *suffix, *p;
p = (char *) seg_lv(seg, s)->name;
if ((suffix = strstr(p, "_rimage"))) {
strcpy(p, lv->name);
strcat(p, suffix);
}
if (seg->meta_areas) {
p = (char *) seg_metalv(seg, s)->name;
if ((suffix = strstr(p, "_rmeta"))) {
strcpy(p, lv->name);
strcat(p, suffix);
}
}
_remove_any_infix(lv->name, (char*) seg_lv(seg,s)->name, "_rimage");
if (seg->meta_areas)
_remove_any_infix(lv->name, (char*) seg_metalv(seg,s)->name, "_rmeta");
}
log_debug_metadata("Updating VG metadata and reactivating %s",
display_lvname(lv));
if (!_lv_update_and_reload_origin_eliminate_lvs(lv, &removal_lvs))
return_0;
}
#endif
PFL();
return 1;
}
@ -4211,6 +4211,7 @@ static int _raid_conv_unduplicate(struct logical_volume *lv,
* else withdraw the source LV
*/
int s, keep_idx = UINT_MAX;
uint32_t segtype_count = 0;
struct dm_list removal_lvs;
struct logical_volume *lv_tmp;
struct lv_segment *seg = first_seg(lv), *seg0;
@ -4222,19 +4223,28 @@ PFL();
return 0;
}
PFLA("new_segtype=%s new_image_count=%u new_datacopes=%u", new_segtype->name, new_image_count, new_data_copies);
PFLA("new_segtype=%s new_image_count=%u new_stripes=%u new_datacopies=%u", new_segtype->name, new_image_count, new_stripes, new_data_copies);
/* Find sublv to keep based on passed in properties */
for (s = seg->area_count - 1; s > -1; s--) {
seg0 = first_seg(seg_lv(seg, s));
if (seg0->segtype == new_segtype &&
_data_rimages_count(seg0, seg0->area_count) == new_stripes &&
(new_data_copies > 1 ? (seg0->data_copies == new_data_copies) : 1)) {
for (s = 0; s < seg->area_count; s++) {
if (first_seg(seg_lv(seg, s))->segtype == new_segtype) {
segtype_count++;
keep_idx = s;
PFLA("keep_idx=%u", keep_idx);
break;
}
}
/* If segtype isn't unique -> select again */
if (segtype_count != 1)
for (s = seg->area_count - 1; s > -1; s--) {
seg0 = first_seg(seg_lv(seg, s));
if (seg0->segtype == new_segtype &&
_data_rimages_count(seg0, seg0->area_count) == new_stripes &&
(new_data_copies > 1 ? (seg0->data_copies == new_data_copies) : 1)) {
keep_idx = s;
PFLA("keep_idx=%u", keep_idx);
break;
}
}
if (keep_idx > seg->area_count) {
log_error("Wrong raid type %s/stripes=%u/mirrors=%u requested to remove duplicating conversion",
new_segtype->name, new_image_count, new_data_copies);
@ -6984,6 +6994,9 @@ int lv_create_raid01(struct logical_volume *lv, const struct segment_type *segty
struct segment_type *image_segtype;
struct volume_group *vg = lv->vg;
#if 0
return 0;
#endif
PFLA("data_copies=%u region_size=%u stripes=%u stripe_size=%u", data_copies, region_size, stripes, stripe_size);
if (data_copies < 2 || stripes < 2)
return 0;

View File

@ -2024,8 +2024,8 @@ static int _segdata_copies_disp(struct dm_report *rh, struct dm_pool *mem,
uint32_t data_copies = seg->segtype->parity_devs ?
(seg->segtype->parity_devs + 1) : seg->data_copies;
if (seg_is_raid1(seg) ||
seg_is_mirrored(seg))
if ((seg_is_raid1(seg) || seg_is_mirrored(seg)) &&
!seg_is_any_raid10(seg))
data_copies = seg->area_count;
if (data_copies > 1)

View File

@ -453,7 +453,7 @@ static int _read_mirror_params(struct cmd_context *cmd,
static int _read_raid_params(struct cmd_context *cmd,
struct lvcreate_params *lp)
{
if (seg_is_raid10_near(lp)) {
if (seg_is_any_raid10(lp)) {
if (lp->stripes * lp->mirrors < 2) {
if (arg_count(cmd, stripes_ARG) || arg_count(cmd, mirrors_ARG)) {
/* User supplied the bad argument */