1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-23 13:57:47 +03:00

vgsplit: handle cachevol

attached to a cache or writecache LV.
Ensure PVs in cachevol are moved with the main LV.
This commit is contained in:
David Teigland 2020-02-03 15:33:58 -06:00
parent adbb0a8d5b
commit 379a7e1288
2 changed files with 56 additions and 16 deletions

View File

@ -68,4 +68,28 @@ vgs $vg $vg1
test 4 -eq "$(get vg_field $vg pv_count)"
test 3 -eq "$(get vg_field $vg1 pv_count)"
vgremove -ff $vg $vg1
lvremove -y $vg
# dm-cache or dm-writecache with cachevol must not
# separated main LV and cachevol
vgremove -ff $vg
vgremove -ff $vg1
vgcreate $vg "$dev1" "$dev2" "$dev3" "$dev4"
lvcreate -L6 -n $lv1 -an $vg "$dev2"
lvcreate -L6 -n $lv2 -an $vg "$dev3"
lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
fail vgsplit $vg $vg1 "$dev2"
fail vgsplit $vg $vg1 "$dev3"
lvremove $vg/$lv1
lvcreate -L6 -n $lv1 -an $vg "$dev2"
lvcreate -L6 -n $lv2 -an $vg "$dev3"
lvconvert -y --type writecache --cachevol $lv2 $vg/$lv1
fail vgsplit $vg $vg1 "$dev2"
fail vgsplit $vg $vg1 "$dev3"
lvremove $vg/$lv1
vgremove -ff $vg

View File

@ -379,25 +379,25 @@ static int _move_cache(struct volume_group *vg_from,
{
int is_moving;
struct dm_list *lvh, *lvht;
struct logical_volume *lv, *data, *meta, *orig;
struct logical_volume *lv, *data = NULL, *meta = NULL, *orig = NULL, *fast = NULL;
struct lv_segment *seg, *cache_seg;
dm_list_iterate_safe(lvh, lvht, &vg_from->lvs) {
lv = dm_list_item(lvh, struct lv_list)->lv;
seg = first_seg(lv);
if (!lv_is_cache(lv) && !lv_is_cache_pool(lv))
if (!lv_is_cache(lv) && !lv_is_writecache(lv) && !lv_is_cache_pool(lv) && !lv_is_cache_vol(lv))
continue;
if (lv_is_cache(lv) && lv_is_cache_vol(seg->pool_lv)) {
log_error("Cannot split while LV %s has cache attached.", display_lvname(lv));
return 0;
}
if (lv_is_cache(lv)) {
orig = seg_lv(seg, 0);
seg = first_seg(seg->pool_lv);
} else { /* lv_is_cache_pool */
} else if (lv_is_writecache(lv)) {
orig = seg_lv(seg, 0);
seg = first_seg(seg->writecache);
} else if (lv_is_cache_pool(lv) || lv_is_cache_vol(lv)) {
orig = NULL;
if (!dm_list_empty(&seg->lv->segs_using_this_lv)) {
if (!(cache_seg = get_only_segment_using_this_lv(seg->lv)))
@ -406,16 +406,26 @@ static int _move_cache(struct volume_group *vg_from,
}
}
data = seg_lv(seg, 0);
meta = seg->metadata_lv;
if (lv_is_cache_vol(lv)) {
fast = lv;
} else {
data = seg_lv(seg, 0);
meta = seg->metadata_lv;
}
if ((orig && !lv_is_on_pvs(orig, &vg_to->pvs)) &&
!lv_is_on_pvs(data, &vg_to->pvs) &&
!lv_is_on_pvs(meta, &vg_to->pvs))
if (data && meta) {
if ((orig && !lv_is_on_pvs(orig, &vg_to->pvs)) &&
!lv_is_on_pvs(data, &vg_to->pvs) &&
!lv_is_on_pvs(meta, &vg_to->pvs))
continue;
}
if (fast && orig &&
!lv_is_on_pvs(orig, &vg_to->pvs) && !lv_is_on_pvs(fast, &vg_to->pvs))
continue;
/* Ensure all components are coming along */
if (orig) {
if (orig && data && meta) {
is_moving = _lv_is_in_vg(vg_to, orig);
if (_lv_is_in_vg(vg_to, data) != is_moving) {
@ -431,11 +441,17 @@ static int _move_cache(struct volume_group *vg_from,
display_lvname(orig), display_lvname(meta));
return 0;
}
} else if (_lv_is_in_vg(vg_to, data) != _lv_is_in_vg(vg_to, meta)) {
} else if (data && meta && (_lv_is_in_vg(vg_to, data) != _lv_is_in_vg(vg_to, meta))) {
log_error("Cannot split cache pool data %s and its metadata %s "
"into separate VGs.",
display_lvname(data), display_lvname(meta));
return 0;
} else if (orig && fast && (_lv_is_in_vg(vg_to, orig) != _lv_is_in_vg(vg_to, fast))) {
log_error("Cannot split cache origin %s and its cachevol %s into separate VGs.",
display_lvname(orig), display_lvname(fast));
return 0;
}
if (!_move_one_lv(vg_from, vg_to, lvh, &lvht))