124
116
seg = first_seg(lv);
125
mirrors = seg->area_count;
118
if (lv->status & PVMOVE)
119
return seg->area_count;
127
123
for (s = 0; s < seg->area_count; s++) {
128
124
if (seg_type(seg, s) != AREA_LV)
130
126
if (is_temporary_mirror_layer(seg_lv(seg, s)))
131
mirrors += lv_mirror_count(seg_lv(seg, s)) - 1;
127
mirrors += lv_mirror_count(seg_lv(seg, s));
132
return mirrors ? mirrors : 1;
137
135
struct lv_segment *find_mirror_seg(struct lv_segment *seg)
335
336
/* Remove the temporary tags */
336
337
dm_list_iterate_items(sl, tags)
337
if (!str_list_del(&log_lv->tags, sl->str))
338
log_error("Failed to remove tag %s from mirror log.",
338
str_list_del(&log_lv->tags, sl->str);
341
340
if (activation() && !set_lv(cmd, log_lv, log_lv->size,
342
341
in_sync ? -1 : 0)) {
373
372
log_lv->status = orig_status;
375
374
dm_list_iterate_items(sl, tags)
376
if (!str_list_del(&log_lv->tags, sl->str))
377
log_error("Failed to remove tag %s from mirror log.",
375
str_list_del(&log_lv->tags, sl->str);
380
377
if (remove_on_failure && !lv_remove(log_lv)) {
381
378
log_error("Manual intervention may be required to remove "
397
* Activate an LV similarly (i.e. SH or EX) to a given "model" LV
399
static int _activate_lv_like_model(struct logical_volume *model,
400
struct logical_volume *lv)
402
if (lv_is_active_exclusive(model)) {
403
if (!activate_lv_excl(lv->vg->cmd, lv))
406
if (!activate_lv(lv->vg->cmd, lv))
400
413
* Delete independent/orphan LV, it must acquire lock.
402
415
static int _delete_lv(struct logical_volume *mirror_lv, struct logical_volume *lv)
422
if (lv_is_active_exclusive_locally(lv)) {
423
if (!activate_lv_excl(cmd, lv))
426
if (!activate_lv(cmd, lv))
435
// FIXME: shouldn't the activation type be based on mirror_lv, not lv?
436
if (!_activate_lv_like_model(lv, lv))
439
/* FIXME Is this superfluous now? */
440
sync_local_dev_names(cmd);
430
442
if (!deactivate_lv(cmd, lv))
562
574
if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &sync_percent,
564
log_error("Unable to determine mirror sync status of %s/%s.",
565
lv->vg->name, lv->name);
576
if (lv_is_active_but_not_locally(lv))
577
log_error("Unable to determine mirror sync status of"
578
" remotely active LV, %s/%s",
579
lv->vg->name, lv->name);
581
log_error("Unable to determine mirror "
582
"sync status of %s/%s.",
583
lv->vg->name, lv->name);
586
604
struct lv_segment *mirrored_seg = first_seg(lv);
587
605
struct dm_list split_images;
588
606
struct lv_list *lvl;
607
struct cmd_context *cmd = lv->vg->cmd;
590
609
if (!(lv->status & MIRRORED)) {
591
610
log_error("Unable to split non-mirrored LV, %s",
638
* Remove the images from the mirror.
639
* Make them visible, independent LVs (don't change names yet).
640
* Track them in a list for later instantiation.
617
642
dm_list_init(&split_images);
618
643
for (i = 0; i < split_count; i++) {
619
644
mirrored_seg->area_count--;
620
645
sub_lv = seg_lv(mirrored_seg, mirrored_seg->area_count);
622
647
sub_lv->status &= ~MIRROR_IMAGE;
623
lv_set_visible(sub_lv);
624
648
release_lv_segment_area(mirrored_seg, mirrored_seg->area_count,
625
649
mirrored_seg->area_len);
627
651
log_very_verbose("%s assigned to be split", sub_lv->name);
654
lv_set_visible(sub_lv);
631
new_lv->name = dm_pool_strdup(lv->vg->cmd->mem,
634
log_error("Unable to rename newly split LV");
638
lvl = dm_pool_alloc(lv->vg->cmd->mem, sizeof(*lvl));
640
log_error("lv_list alloc failed");
644
dm_list_add(&split_images, &lvl->list);
659
/* If there is more than one image being split, add to list */
660
lvl = dm_pool_alloc(lv->vg->vgmem, sizeof(*lvl));
662
log_error("lv_list alloc failed");
666
dm_list_add(&split_images, &lvl->list);
669
new_lv->name = dm_pool_strdup(lv->vg->vgmem, split_name);
671
log_error("Unable to rename newly split LV");
648
675
if (!dm_list_empty(&split_images)) {
649
676
size_t len = strlen(new_lv->name) + 32;
650
677
char *layer_name, format[len];
652
if (!insert_layer_for_lv(lv->vg->cmd, new_lv,
680
* A number of images have been split and
681
* a new mirror layer must be formed
684
if (!insert_layer_for_lv(cmd, new_lv, 0, "_mimage_%d")) {
654
685
log_error("Failed to build new mirror, %s",
661
692
dm_list_iterate_items(lvl, &split_images) {
662
693
sub_lv = lvl->lv;
664
dm_snprintf(format, len, "%s_mimage_%%d",
667
layer_name = dm_pool_alloc(lv->vg->cmd->mem, len);
695
if (dm_snprintf(format, len, "%s_mimage_%%d",
697
log_error("Failed to build new image name.");
700
layer_name = dm_pool_alloc(lv->vg->vgmem, len);
668
701
if (!layer_name) {
669
702
log_error("Unable to allocate memory");
718
* Suspend the original device and all its sub devices
751
* Suspend the mirror - this includes all the sub-LVs and
752
* soon-to-be-split sub-LVs
720
if (!suspend_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
754
if (!suspend_lv(cmd, mirrored_seg->lv)) {
721
755
log_error("Failed to lock %s", mirrored_seg->lv->name);
722
756
vg_revert(mirrored_seg->lv->vg);
726
760
if (!vg_commit(mirrored_seg->lv->vg)) {
727
resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv);
731
/* Bring newly split-off LV into existence */
732
if (!activate_lv(lv->vg->cmd, new_lv)) {
733
log_error("Failed to activate newly split LV, %s",
738
/* Resume altered original LV */
761
resume_lv(cmd, mirrored_seg->lv);
739
765
log_very_verbose("Updating \"%s\" in kernel", mirrored_seg->lv->name);
740
if (!resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
741
log_error("Problem reactivating %s", mirrored_seg->lv->name);
768
* Resume the mirror - this also activates the visible, independent
769
* soon-to-be-split sub-LVs
771
if (!resume_lv(cmd, mirrored_seg->lv)) {
772
log_error("Problem resuming %s", mirrored_seg->lv->name);
777
* Recycle newly split LV so it is properly renamed.
778
* Cluster requires the extra deactivate/activate calls.
780
if (vg_is_clustered(lv->vg) &&
781
(!deactivate_lv(cmd, new_lv) ||
782
!_activate_lv_like_model(lv, new_lv))) {
783
log_error("Failed to rename newly split LV in the kernel");
786
if (!suspend_lv(cmd, new_lv) || !resume_lv(cmd, new_lv)) {
787
log_error("Failed to rename newly split LV in the kernel");
791
/* Remove original mirror layer if it has been converted to linear */
745
792
if (sub_lv && !_delete_lv(lv, sub_lv))
795
/* Remove the log if it has been converted to linear */
748
796
if (detached_log_lv && !_delete_lv(lv, detached_log_lv))
751
log_very_verbose("%" PRIu32 " image(s) detached from %s",
752
split_count, lv->name);
1176
static int get_mirror_fault_policy(struct cmd_context *cmd __attribute__((unused)),
1221
static int _get_mirror_fault_policy(struct cmd_context *cmd __attribute__((unused)),
1177
1222
int log_policy)
1179
1224
const char *policy;
1181
1226
if (log_policy)
1182
policy = find_config_str(NULL, "activation/mirror_log_fault_policy",
1227
policy = dm_config_find_str(NULL, "activation/mirror_log_fault_policy",
1183
1228
DEFAULT_MIRROR_LOG_FAULT_POLICY);
1185
policy = find_config_str(NULL, "activation/mirror_image_fault_policy",
1230
policy = dm_config_find_str(NULL, "activation/mirror_image_fault_policy",
1188
policy = find_config_str(NULL, "activation/mirror_device_fault_policy",
1233
policy = dm_config_find_str(NULL, "activation/mirror_device_fault_policy",
1189
1234
DEFAULT_MIRROR_IMAGE_FAULT_POLICY);
1204
1249
return MIRROR_REMOVE;
1207
static int get_mirror_log_fault_policy(struct cmd_context *cmd)
1252
static int _get_mirror_log_fault_policy(struct cmd_context *cmd)
1209
return get_mirror_fault_policy(cmd, 1);
1254
return _get_mirror_fault_policy(cmd, 1);
1212
static int get_mirror_device_fault_policy(struct cmd_context *cmd)
1257
static int _get_mirror_device_fault_policy(struct cmd_context *cmd)
1214
return get_mirror_fault_policy(cmd, 0);
1259
return _get_mirror_fault_policy(cmd, 0);
1228
1273
* Returns: 0 on failure, 1 on reconfig, -1 if no reconfig done
1230
static int replace_mirror_images(struct lv_segment *mirrored_seg,
1275
static int _replace_mirror_images(struct lv_segment *mirrored_seg,
1231
1276
uint32_t num_mirrors,
1232
1277
int log_policy, int in_sync)
1298
1343
log_warn("WARNING: Bad device removed from mirror volume, %s/%s",
1299
1344
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
1301
log_policy = get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
1302
dev_policy = get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
1346
log_policy = _get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
1347
dev_policy = _get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
1304
r = replace_mirror_images(mirrored_seg,
1349
r = _replace_mirror_images(mirrored_seg,
1305
1350
(dev_policy != MIRROR_REMOVE) ?
1306
1351
old_num_mirrors : num_mirrors,
1307
1352
log_policy, in_sync);
1892
1942
/* allocate destination extents */
1893
1943
ah = allocate_extents(lv->vg, NULL, segtype,
1894
0, 0, log_count - old_log_count, region_size, 0,
1895
allocatable_pvs, alloc, parallel_areas);
1944
0, 0, log_count - old_log_count, region_size,
1945
lv->le_count, allocatable_pvs,
1946
alloc, parallel_areas);
1897
1948
log_error("Unable to allocate extents for mirror log.");