64
61
return seg->area_count;
65
* Resume sub-LVs first, then top-level LV
67
static int _bottom_up_resume(struct logical_volume *lv)
70
struct lv_segment *seg = first_seg(lv);
72
if (seg_is_raid(seg) && (seg->area_count > 1)) {
73
for (s = 0; s < seg->area_count; s++)
74
if (!resume_lv(lv->vg->cmd, seg_lv(seg, s)) ||
75
!resume_lv(lv->vg->cmd, seg_metalv(seg, s)))
79
return resume_lv(lv->vg->cmd, lv);
67
82
static int _activate_sublv_preserving_excl(struct logical_volume *top_lv,
68
83
struct logical_volume *sub_lv)
621
639
struct lv_list *lvl;
622
640
struct lv_segment_area *new_areas;
642
if (lv->status & LV_NOTSYNCED) {
643
log_error("Can't add image to out-of-sync RAID LV:"
644
" use 'lvchange --resync' first.");
648
if (!_raid_in_sync(lv)) {
649
log_error("Can't add image to RAID LV that"
650
" is still initializing.");
624
654
dm_list_init(&meta_lvs); /* For image addition */
625
655
dm_list_init(&data_lvs); /* For image addition */
643
673
dm_list_add(&meta_lvs, &lvl->list);
644
674
} else if (!seg_is_raid(seg)) {
645
675
log_error("Unable to add RAID images to %s of segment type %s",
646
lv->name, seg->segtype->name);
676
lv->name, seg->segtype->ops->name(seg));
678
} else if (!_raid_in_sync(lv)) {
679
log_error("Unable to add RAID images until %s is in-sync",
697
731
seg = first_seg(lv);
698
732
seg_lv(seg, 0)->status |= RAID_IMAGE | LVM_READ | LVM_WRITE;
699
733
seg->region_size = RAID_REGION_SIZE;
734
/* MD's bitmap is limited to tracking 2^21 regions */
735
while (seg->region_size < (lv->size / (1 << 21))) {
736
seg->region_size *= 2;
737
log_very_verbose("Setting RAID1 region_size to %uS",
700
740
seg->segtype = get_segtype_from_string(lv->vg->cmd, "raid1");
701
741
if (!seg->segtype)
990
1030
/* Convert to linear? */
991
if ((new_count == 1) && !_raid_remove_top_layer(lv, &removal_list)) {
992
log_error("Failed to remove RAID layer after linear conversion");
1031
if (new_count == 1) {
1032
if (!_raid_remove_top_layer(lv, &removal_list)) {
1033
log_error("Failed to remove RAID layer"
1034
" after linear conversion");
1037
lv->status &= ~LV_NOTSYNCED;
996
1040
if (!vg_write(lv->vg)) {
1015
* Resume original LV
1016
* This also resumes all other sub-lvs (including the extracted)
1018
if (!resume_lv(lv->vg->cmd, lv)) {
1059
* We resume the extracted sub-LVs first so they are renamed
1060
* and won't conflict with the remaining (possibly shifted)
1063
dm_list_iterate_items(lvl, &removal_list) {
1064
if (!resume_lv(lv->vg->cmd, lvl->lv)) {
1065
log_error("Failed to resume extracted LVs");
1071
* Resume the remaining LVs
1072
* We must start by resuming the sub-LVs first (which would
1073
* otherwise be handled automatically) because the shifting
1074
* of positions could otherwise cause name collisions. For
1075
* example, if position 0 of a 3-way array is removed, position
1076
* 1 and 2 must be shifted and renamed 0 and 1. If position 2
1077
* tries to rename first, it will collide with the existing
1080
if (!_bottom_up_resume(lv)) {
1019
1081
log_error("Failed to resume %s/%s after committing changes",
1020
1082
lv->vg->name, lv->name);
1074
1136
int lv_raid_split(struct logical_volume *lv, const char *split_name,
1075
1137
uint32_t new_count, struct dm_list *splittable_pvs)
1077
const char *old_name;
1078
1139
struct lv_list *lvl;
1079
1140
struct dm_list removal_list, data_list;
1080
1141
struct cmd_context *cmd = lv->vg->cmd;
1094
1155
if (!seg_is_mirrored(first_seg(lv))) {
1095
1156
log_error("Unable to split logical volume of segment type, %s",
1096
first_seg(lv)->segtype->name);
1157
first_seg(lv)->segtype->ops->name(first_seg(lv)));
1170
* Resume original LV
1171
* This also resumes all other sub-lvs (including the extracted)
1173
if (!resume_lv(cmd, lv)) {
1230
* First resume the newly split LV and LVs on the removal list.
1231
* This is necessary so that there are no name collisions due to
1232
* the original RAID LV having possibly had sub-LVs that have been
1233
* shifted and renamed.
1235
if (!resume_lv(cmd, lvl->lv))
1237
dm_list_iterate_items(lvl, &removal_list)
1238
if (!resume_lv(cmd, lvl->lv))
1242
* Resume the remaining LVs
1243
* We must start by resuming the sub-LVs first (which would
1244
* otherwise be handled automatically) because the shifting
1245
* of positions could otherwise cause name collisions. For
1246
* example, if position 0 of a 3-way array is split, position
1247
* 1 and 2 must be shifted and renamed 0 and 1. If position 2
1248
* tries to rename first, it will collide with the existing
1251
if (!_bottom_up_resume(lv)) {
1174
1252
log_error("Failed to resume %s/%s after committing changes",
1175
1253
lv->vg->name, lv->name);
1179
/* Recycle newly split LV so it is properly renamed */
1180
if (!suspend_lv(cmd, lvl->lv) || !resume_lv(cmd, lvl->lv)) {
1181
log_error("Failed to rename %s to %s after committing changes",
1182
old_name, split_name);
1187
1258
* Eliminate the residual LVs
1270
log_print("%s split from %s for read-only purposes.",
1271
seg_lv(seg, s)->name, lv->name);
1341
log_print_unless_silent("%s split from %s for read-only purposes.",
1342
seg_lv(seg, s)->name, lv->name);
1273
1344
/* Resume original LV */
1274
1345
if (!resume_lv(lv->vg->cmd, lv)) {
1281
1352
if (!_activate_sublv_preserving_excl(lv, seg_lv(seg, s)))
1284
log_print("Use 'lvconvert --merge %s/%s' to merge back into %s",
1285
lv->vg->name, seg_lv(seg, s)->name, lv->name);
1355
log_print_unless_silent("Use 'lvconvert --merge %s/%s' to merge back into %s",
1356
lv->vg->name, seg_lv(seg, s)->name, lv->name);
1369
log_print("%s/%s successfully merged back into %s/%s",
1370
vg->name, image_lv->name,
1371
vg->name, lv->name);
1440
log_print_unless_silent("%s/%s successfully merged back into %s/%s",
1441
vg->name, image_lv->name, vg->name, lv->name);
1519
1589
log_error("Converting the segment type for %s/%s from %s to %s"
1520
1590
" is not yet supported.", lv->vg->name, lv->name,
1521
seg->segtype->name, new_segtype->name);
1591
seg->segtype->ops->name(seg), new_segtype->name);
1574
1644
(match_count > raid_seg->segtype->parity_devs)) {
1575
1645
log_error("Unable to replace more than %u PVs from (%s) %s/%s",
1576
1646
raid_seg->segtype->parity_devs,
1577
raid_seg->segtype->name, lv->vg->name, lv->name);
1647
raid_seg->segtype->ops->name(raid_seg),
1648
lv->vg->name, lv->name);
1650
} else if (!strcmp(raid_seg->segtype->name, "raid10")) {
1651
uint32_t i, rebuilds_per_group = 0;
1652
/* FIXME: We only support 2-way mirrors in RAID10 currently */
1653
uint32_t copies = 2;
1655
for (i = 0; i < raid_seg->area_count * copies; i++) {
1656
s = i % raid_seg->area_count;
1658
rebuilds_per_group = 0;
1659
if (_lv_is_on_pvs(seg_lv(raid_seg, s), remove_pvs) ||
1660
_lv_is_on_pvs(seg_metalv(raid_seg, s), remove_pvs))
1661
rebuilds_per_group++;
1662
if (rebuilds_per_group >= copies) {
1663
log_error("Unable to replace all the devices "
1664
"in a RAID10 mirror group.");
1586
1675
* - We need to change the LV names when we insert them.
1588
1678
if (!_alloc_image_components(lv, allocate_pvs, match_count,
1589
1679
&new_meta_lvs, &new_data_lvs)) {
1590
1680
log_error("Failed to allocate replacement images for %s/%s",
1591
1681
lv->vg->name, lv->name);
1684
* If this is a repair, then try to
1685
* do better than all-or-nothing
1687
if (match_count > 1) {
1688
log_error("Attempting replacement of %u devices"
1689
" instead of %u", match_count - 1, match_count);
1693
* Since we are replacing some but not all of the bad
1694
* devices, we must set partial_activation
1696
lv->vg->cmd->partial_activation = 1;
1669
if (!suspend_lv(lv->vg->cmd, lv)) {
1776
if (!suspend_lv_origin(lv->vg->cmd, lv)) {
1670
1777
log_error("Failed to suspend %s/%s before committing changes",
1671
1778
lv->vg->name, lv->name);
1681
if (!resume_lv(lv->vg->cmd, lv)) {
1788
if (!resume_lv_origin(lv->vg->cmd, lv)) {
1682
1789
log_error("Failed to resume %s/%s after committing changes",
1683
1790
lv->vg->name, lv->name);
1717
if (!suspend_lv(lv->vg->cmd, lv)) {
1824
if (!suspend_lv_origin(lv->vg->cmd, lv)) {
1718
1825
log_error("Failed to suspend %s/%s before committing changes",
1719
1826
lv->vg->name, lv->name);
1729
if (!resume_lv(lv->vg->cmd, lv)) {
1836
if (!resume_lv_origin(lv->vg->cmd, lv)) {
1730
1837
log_error("Failed to resume %s/%s after committing changes",
1731
1838
lv->vg->name, lv->name);