675
699
/* Log device holds both header and bitset. */
676
700
log_size = dm_round_up((MIRROR_LOG_OFFSET << SECTOR_SHIFT) + bitset_size, 1 << SECTOR_SHIFT);
677
701
log_size >>= SECTOR_SHIFT;
702
log_size = dm_div_up(log_size, pe_size);
679
return dm_div_up(log_size, pe_size);
705
* Kernel requires a mirror to be at least 1 region large. So,
706
* if our mirror log is itself a mirror, it must be at least
707
* 1 region large. This restriction may not be necessary for
708
* non-mirrored logs, but we apply the rule anyway.
710
* (The other option is to make the region size of the log
711
* mirror smaller than the mirror it is acting as a log for,
712
* but that really complicates things. It's much easier to
713
* keep the region_size the same for both.)
715
return (log_size > (region_size / pe_size)) ? log_size :
716
(region_size / pe_size);
712
749
area_count = stripes;
714
751
size = sizeof(*ah);
715
alloc_count = area_count + segtype->parity_devs;
754
* It is a requirement that RAID 4/5/6 are created with a number of
755
* stripes that is greater than the number of parity devices. (e.g
756
* RAID4/5 must have at least 2 stripes and RAID6 must have at least
757
* 3.) It is also a constraint that, when replacing individual devices
758
* in a RAID 4/5/6 array, no more devices can be replaced than
759
* there are parity devices. (Otherwise, there would not be enough
760
* redundancy to maintain the array.) Understanding these two
761
* constraints allows us to infer whether the caller of this function
762
* is intending to allocate an entire array or just replacement
763
* component devices. In the former case, we must account for the
764
* necessary parity_count. In the later case, we do not need to
765
* account for the extra parity devices because the array already
766
* exists and they only want replacement drives.
768
parity_count = (area_count <= segtype->parity_devs) ? 0 :
769
segtype->parity_devs;
770
alloc_count = area_count + parity_count;
716
771
if (segtype_is_raid(segtype) && metadata_area_count)
717
772
/* RAID has a meta area for each device */
718
773
alloc_count *= 2;
764
824
* RAID device's metadata_area
766
826
ah->new_extents += (ah->log_len * ah->area_multiple);
828
ah->log_area_count = 0;
831
} else if (segtype_is_thin_pool(segtype)) {
832
ah->log_area_count = metadata_area_count;
833
/* thin_pool uses region_size to pass metadata size in extents */
834
ah->log_len = ah->region_size;
836
ah->mirror_logs_separate =
837
find_config_tree_bool(cmd, "allocation/thin_pool_metadata_require_separate_pvs",
838
DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS);
769
840
ah->log_area_count = metadata_area_count;
770
841
ah->log_len = !metadata_area_count ? 0 :
771
842
mirror_log_extents(ah->region_size, extent_size,
772
ah->new_extents / ah->area_multiple);
843
new_extents / ah->area_multiple);
775
846
for (s = 0; s < alloc_count; s++)
915
984
area_multiple = _calc_area_multiple(segtype, area_count, 0);
917
if (!(seg = alloc_lv_segment(lv->vg->cmd->mem, segtype, lv,
986
if (!(seg = alloc_lv_segment(segtype, lv, lv->le_count,
919
987
aa[0].len * area_multiple,
920
status, stripe_size, NULL,
988
status, stripe_size, NULL, NULL,
922
990
aa[0].len, 0u, region_size, 0u, NULL))) {
923
991
log_error("Couldn't allocate new LV segment.");
1479
1545
uint32_t required = max_to_allocate / ah->area_multiple;
1481
/* FIXME Maintain unreserved all the time, so other policies can split areas too. */
1548
* Update amount unreserved - effectively splitting an area
1549
* into two or more parts. If the whole stripe doesn't fit,
1550
* reduce amount we're looking for.
1483
1552
if (alloc == ALLOC_ANYWHERE) {
1485
* Update amount unreserved - effectively splitting an area
1486
* into two or more parts. If the whole stripe doesn't fit,
1487
* reduce amount we're looking for.
1489
1553
if (ix_pva - 1 >= ah->area_count)
1490
1554
required = ah->log_len;
1491
if (required >= pva->unreserved) {
1492
required = pva->unreserved;
1493
pva->unreserved = 0;
1495
pva->unreserved -= required;
1496
reinsert_reduced_pv_area(pva);
1555
} else if (required < ah->log_len)
1556
required = ah->log_len;
1558
if (required >= pva->unreserved) {
1559
required = pva->unreserved;
1560
pva->unreserved = 0;
1499
if (required < ah->log_len)
1500
required = ah->log_len;
1501
if (required > pva->count)
1502
required = pva->count;
1562
pva->unreserved -= required;
1563
reinsert_changed_pv_area(pva);
1505
1566
return required;
1989
2064
int lv_add_virtual_segment(struct logical_volume *lv, uint64_t status,
1990
uint32_t extents, const struct segment_type *segtype)
2065
uint32_t extents, const struct segment_type *segtype,
2066
const char *thin_pool_name)
1992
2068
struct lv_segment *seg;
1994
if (!(seg = alloc_lv_segment(lv->vg->cmd->mem, segtype, lv,
1995
lv->le_count, extents, status, 0,
1996
NULL, 0, extents, 0, 0, 0, NULL))) {
1997
log_error("Couldn't allocate new zero segment.");
2001
dm_list_add(&lv->segments, &seg->list);
2069
struct logical_volume *thin_pool_lv = NULL;
2070
struct lv_list *lvl;
2073
if (thin_pool_name) {
2074
if (!(lvl = find_lv_in_vg(lv->vg, thin_pool_name))) {
2075
log_error("Unable to find existing pool LV %s in VG %s.",
2076
thin_pool_name, lv->vg->name);
2079
thin_pool_lv = lvl->lv;
2080
size = first_seg(thin_pool_lv)->chunk_size;
2081
if (lv->vg->extent_size < size) {
2082
/* Align extents on chunk boundary size */
2083
size = ((uint64_t)lv->vg->extent_size * extents + size - 1) /
2084
size * size / lv->vg->extent_size;
2085
if (size != extents) {
2086
log_print("Rounding size (%d extents) up to chunk boundary "
2087
"size (%d extents).", extents, size);
2093
if (!dm_list_empty(&lv->segments) &&
2094
(seg = last_seg(lv)) && (seg->segtype == segtype)) {
2095
seg->area_len += extents;
2096
seg->len += extents;
2098
if (!(seg = alloc_lv_segment(segtype, lv, lv->le_count, extents,
2099
status, 0, NULL, thin_pool_lv, 0,
2100
extents, 0, 0, 0, NULL))) {
2101
log_error("Couldn't allocate new zero segment.");
2104
lv->status |= VIRTUAL;
2105
dm_list_add(&lv->segments, &seg->list);
2003
2108
lv->le_count += extents;
2004
2109
lv->size += (uint64_t) extents *lv->vg->extent_size;
2006
lv->status |= VIRTUAL;
2335
2442
for (i = 0; i < devices; i++) {
2337
if (dm_snprintf(img_name, len, "%s_%s_%u",
2338
lv->name, layer_name, i) < 0)
2341
sub_lv = lv_create_empty(img_name, NULL,
2342
LVM_READ | LVM_WRITE | status,
2347
if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, status))
2349
if (!segtype_is_raid(segtype))
2445
if (dm_snprintf(img_name, len, "%s_%s_%u",
2446
lv->name, layer_name, i) < 0)
2449
if (dm_snprintf(img_name, len, "%s_%s",
2450
lv->name, layer_name) < 0)
2454
/* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
2455
if (!(sub_lv = lv_create_empty(img_name, NULL,
2456
LVM_READ | LVM_WRITE,
2457
lv->alloc, lv->vg)))
2460
if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, sub_lv_status))
2463
/* Metadata LVs for raid */
2464
if (segtype_is_raid(segtype)) {
2465
if (dm_snprintf(img_name, len, "%s_rmeta_%u", lv->name, i) < 0)
2353
if (dm_snprintf(img_name, len, "%s_rmeta_%u", lv->name, i) < 0)
2470
/* FIXME Should use ALLOC_INHERIT here and inherit from parent LV */
2471
if (!(sub_lv = lv_create_empty(img_name, NULL,
2472
LVM_READ | LVM_WRITE,
2473
lv->alloc, lv->vg)))
2356
sub_lv = lv_create_empty(img_name, NULL,
2357
LVM_READ | LVM_WRITE | RAID_META,
2361
2476
if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, RAID_META))
2364
2480
dm_list_add(&lv->segments, &mapseg->list);
2481
2597
const struct segment_type *segtype,
2482
2598
uint32_t stripes, uint32_t stripe_size,
2483
2599
uint32_t mirrors, uint32_t region_size,
2600
uint32_t extents, const char *thin_pool_name,
2485
2601
struct dm_list *allocatable_pvs, alloc_policy_t alloc)
2489
2605
struct alloc_handle *ah;
2490
uint32_t dev_count = mirrors * stripes + segtype->parity_devs;
2606
uint32_t sub_lv_count;
2492
2608
log_very_verbose("Extending segment type, %s", segtype->name);
2494
2610
if (segtype_is_virtual(segtype))
2495
return lv_add_virtual_segment(lv, 0u, extents, segtype);
2611
return lv_add_virtual_segment(lv, 0u, extents, segtype, thin_pool_name);
2497
if (segtype_is_raid(segtype) && !lv->le_count)
2498
raid_logs = mirrors * stripes;
2613
if (!lv->le_count && segtype_is_thin_pool(segtype)) {
2614
/* Thin pool allocation treats its metadata device like a mirror log. */
2615
/* FIXME Allow pool and data on same device with NORMAL */
2616
/* FIXME Support striped metadata pool */
2618
} else if (segtype_is_raid(segtype) && !lv->le_count)
2619
log_count = mirrors * stripes;
2620
/* FIXME log_count should be 1 for mirrors */
2500
2622
if (!(ah = allocate_extents(lv->vg, lv, segtype, stripes, mirrors,
2501
raid_logs, region_size, extents,
2623
log_count, region_size, extents,
2502
2624
allocatable_pvs, alloc, NULL)))
2505
if (!segtype_is_mirrored(segtype) && !segtype_is_raid(segtype))
2506
r = lv_add_segment(ah, 0, ah->area_count, lv, segtype,
2507
stripe_size, 0u, 0);
2627
if (segtype_is_thin_pool(segtype)) {
2628
if (!lv->le_count) {
2629
if (!(r = extend_pool(lv, segtype, ah, stripes, stripe_size)))
2631
} else if (!(r = _lv_extend_layered_lv(ah, lv, extents, 0,
2632
stripes, stripe_size)))
2634
} else if (!segtype_is_mirrored(segtype) && !segtype_is_raid(segtype)) {
2635
if (!(r = lv_add_segment(ah, 0, ah->area_count, lv, segtype,
2636
stripe_size, 0u, 0)))
2510
2640
* For RAID, all the devices are AREA_LV.
2511
2641
* However, for 'mirror on stripe' using non-RAID targets,
2512
2642
* the mirror legs are AREA_LV while the stripes underneath
2513
* are AREA_PV. So if this is not RAID, reset dev_count to
2514
* just 'mirrors' - the necessary sub_lv count.
2516
if (!segtype_is_raid(segtype))
2517
dev_count = mirrors;
2645
if (segtype_is_raid(segtype))
2646
sub_lv_count = mirrors * stripes + segtype->parity_devs;
2648
sub_lv_count = mirrors;
2519
2650
if (!lv->le_count &&
2520
!_lv_insert_empty_sublvs(lv, segtype, stripe_size,
2521
region_size, dev_count)) {
2651
!(r = _lv_insert_empty_sublvs(lv, segtype, stripe_size,
2652
region_size, sub_lv_count))) {
2522
2653
log_error("Failed to insert layer for %s", lv->name);
2527
r = _lv_extend_layered_lv(ah, lv, extents, 0,
2528
stripes, stripe_size);
2657
if (!(r = _lv_extend_layered_lv(ah, lv, extents, 0,
2658
stripes, stripe_size)))
2662
* If we are expanding an existing mirror, we can skip the
2663
* resync of the extension if the LV is currently in-sync
2664
* and the LV has the LV_NOTSYNCED flag set.
2666
if ((lv->le_count != extents) &&
2667
segtype_is_mirrored(segtype) &&
2668
(lv->status & LV_NOTSYNCED)) {
2669
percent_t sync_percent = PERCENT_INVALID;
2671
if (!lv_is_active(lv)) {
2672
log_print("%s/%s is not active."
2673
" Unable to get sync percent.",
2674
lv->vg->name, lv->name);
2675
if (yes_no_prompt("Do full resync of extended "
2676
"portion of %s/%s? [y/n]: ",
2677
lv->vg->name, lv->name) == 'y')
2683
if (!(r = lv_mirror_percent(lv->vg->cmd, lv, 0,
2684
&sync_percent, NULL))) {
2685
log_error("Failed to get sync percent for %s/%s",
2686
lv->vg->name, lv->name);
2688
} else if (sync_percent == PERCENT_100) {
2689
log_verbose("Skipping initial resync for "
2690
"extended portion of %s/%s",
2691
lv->vg->name, lv->name);
2692
init_mirror_in_sync(1);
2693
lv->status |= LV_NOTSYNCED;
2695
log_error("%s/%s cannot be extended while"
2696
" it is recovering.",
2697
lv->vg->name, lv->name);
2530
2705
alloc_destroy(ah);
2624
2799
struct lv_segment *seg;
2627
if (lv_is_cow(lv) && lv_is_virtual_origin(org = origin_from_cow(lv)))
2802
if (lv_is_cow(lv) && lv_is_virtual_origin(org = origin_from_cow(lv))) {
2628
2803
if (!fn(cmd, org, data))
2805
if (!for_each_sub_lv(cmd, org, fn, data))
2631
2809
dm_list_iterate_items(seg, &lv->segments) {
2632
if (seg->log_lv && !fn(cmd, seg->log_lv, data))
2811
if (!fn(cmd, seg->log_lv, data))
2813
if (!for_each_sub_lv(cmd, seg->log_lv, fn, data))
2818
if (!fn(cmd, seg->pool_lv, data))
2820
if (!for_each_sub_lv(cmd, seg->pool_lv, fn, data))
2824
if (seg->metadata_lv) {
2825
if (!fn(cmd, seg->metadata_lv, data))
2827
if (!for_each_sub_lv(cmd, seg->metadata_lv, fn, data))
2634
2831
for (s = 0; s < seg->area_count; s++) {
2635
2832
if (seg_type(seg, s) != AREA_LV)
3268
/* Clear thin pool stacked messages */
3269
if (pool_lv && !pool_has_message(first_seg(pool_lv), lv, 0) &&
3270
!update_pool_lv(pool_lv, 1)) {
3271
log_error("Failed to update thin pool %s.", pool_lv->name);
3275
visible = lv_is_visible(lv);
3055
3277
log_verbose("Releasing logical volume \"%s\"", lv->name);
3056
3278
if (!lv_remove(lv)) {
3057
3279
log_error("Error releasing logical volume \"%s\"", lv->name);
3284
* Old format1 code: If no snapshots left reload without -real.
3286
if (format1_origin && !lv_is_origin(format1_origin)) {
3287
log_warn("WARNING: Support for snapshots with old LVM1-style metadata is deprecated.");
3288
log_warn("WARNING: Please use lvconvert to update to lvm2 metadata at your convenience.");
3289
format1_reload_required = 1;
3061
3292
/* store it on disks */
3062
3293
if (!vg_write(vg))
3297
if (format1_reload_required && !suspend_lv(cmd, format1_origin))
3298
log_error("Failed to refresh %s without snapshot.", format1_origin->name);
3065
3300
if (!vg_commit(vg))
3304
if (format1_reload_required && !resume_lv(cmd, format1_origin)) {
3305
log_error("Failed to resume %s.", format1_origin->name);
3309
/* Release unneeded blocks in thin pool */
3310
/* TODO: defer when multiple LVs relased at once */
3311
if (pool_lv && !update_pool_lv(pool_lv, 1)) {
3312
log_error("Failed to update thin pool %s.", pool_lv->name);
3070
if (lv_is_visible(lv))
3071
3319
log_print("Logical volume \"%s\" successfully removed", lv->name);
3079
3327
int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *lv,
3080
3328
const force_t force, unsigned level)
3330
percent_t snap_percent;
3082
3331
struct dm_list *snh, *snht;
3332
struct seg_list *sl, *tsl;
3084
3335
if (lv_is_cow(lv)) {
3085
/* A merging snapshot cannot be removed directly */
3337
* A merging snapshot cannot be removed directly unless
3338
* it has been invalidated or failed merge removal is requested.
3086
3340
if (lv_is_merging_cow(lv) && !level) {
3087
log_error("Can't remove merging snapshot logical volume \"%s\"",
3341
if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) &&
3342
info.exists && info.live_table) {
3343
if (!lv_snapshot_percent(lv, &snap_percent)) {
3344
log_error("Failed to obtain merging snapshot progress percentage for logical volume %s.",
3348
if ((snap_percent != PERCENT_INVALID) &&
3349
(snap_percent != PERCENT_MERGE_FAILED)) {
3350
log_error("Can't remove merging snapshot logical volume \"%s\"",
3353
} else if ((snap_percent == PERCENT_MERGE_FAILED) &&
3354
(force == PROMPT) &&
3355
yes_no_prompt("Removing snapshot \"%s\" that failed to merge may leave origin \"%s\" inconsistent. "
3356
"Proceed? [y/n]: ", lv->name, origin_from_cow(lv)->name) == 'n') {
3357
log_error("Logical volume %s not removed.", lv->name);
3093
3364
if (lv_is_origin(lv)) {
3094
/* remove snapshot LVs first */
3095
dm_list_iterate_safe(snh, snht, &lv->snapshot_segs) {
3365
/* Remove snapshot LVs first */
3366
if ((force == PROMPT) &&
3367
/* Active snapshot already needs to confirm each active LV */
3368
!lv_is_active(lv) &&
3369
yes_no_prompt("Removing origin %s will also remove %u "
3370
"snapshots(s). Proceed? [y/n]: ",
3371
lv->name, lv->origin_count) == 'n') {
3372
log_error("Logical volume %s not removed.", lv->name);
3376
dm_list_iterate_safe(snh, snht, &lv->snapshot_segs)
3096
3377
if (!lv_remove_with_dependencies(cmd, dm_list_struct_base(snh, struct lv_segment,
3097
3378
origin_list)->cow,
3098
3379
force, level + 1))
3383
if (lv_is_used_thin_pool(lv)) {
3384
/* Remove thin LVs first */
3385
if ((force == PROMPT) &&
3386
yes_no_prompt("Removing pool %s will also remove %u "
3387
"thin volume(s). OK? [y/n]: ", lv->name,
3388
/* Note: Snaphosts not included */
3389
dm_list_size(&lv->segs_using_this_lv)) == 'n') {
3390
log_error("Logical volume %s not removed.", lv->name);
3394
dm_list_iterate_items_safe(sl, tsl, &lv->segs_using_this_lv)
3395
if (!lv_remove_with_dependencies(cmd, sl->seg->lv,
3103
3400
return lv_remove_single(cmd, lv, force);
3304
static int _move_lv_segments(struct logical_volume *lv_to,
3305
struct logical_volume *lv_from,
3306
uint64_t set_status, uint64_t reset_status)
3601
int move_lv_segments(struct logical_volume *lv_to,
3602
struct logical_volume *lv_from,
3603
uint64_t set_status, uint64_t reset_status)
3308
3605
struct lv_segment *seg;
3310
dm_list_iterate_items(seg, &lv_to->segments) {
3607
dm_list_iterate_items(seg, &lv_to->segments)
3311
3608
if (seg->origin) {
3312
log_error("Can't move snapshot segment");
3609
log_error("Can't move snapshot segment.");
3317
if (!dm_list_empty(&lv_from->segments))
3318
lv_to->segments = lv_from->segments;
3319
lv_to->segments.n->p = &lv_to->segments;
3320
lv_to->segments.p->n = &lv_to->segments;
3613
dm_list_init(&lv_to->segments);
3614
dm_list_splice(&lv_to->segments, &lv_from->segments);
3322
3616
dm_list_iterate_items(seg, &lv_to->segments) {
3323
3617
seg->lv = lv_to;
3457
3749
log_very_verbose("Inserting layer %s for %s",
3458
3750
layer_lv->name, lv_where->name);
3460
if (!_move_lv_segments(layer_lv, lv_where, 0, 0))
3752
if (!move_lv_segments(layer_lv, lv_where, 0, 0))
3463
3755
if (!(segtype = get_segtype_from_string(cmd, "striped")))
3466
3758
/* allocate a new linear segment */
3467
if (!(mapseg = alloc_lv_segment(cmd->mem, segtype,
3468
lv_where, 0, layer_lv->le_count,
3469
status, 0, NULL, 1, layer_lv->le_count,
3759
if (!(mapseg = alloc_lv_segment(segtype, lv_where, 0, layer_lv->le_count,
3760
status, 0, NULL, NULL, 1, layer_lv->le_count,
3470
3761
0, 0, 0, NULL)))
3507
3798
seg->lv->vg->name, seg->lv->name);
3509
3800
/* allocate a new segment */
3510
if (!(mapseg = alloc_lv_segment(layer_lv->vg->cmd->mem, segtype,
3511
layer_lv, layer_lv->le_count,
3801
if (!(mapseg = alloc_lv_segment(segtype, layer_lv, layer_lv->le_count,
3512
3802
seg->area_len, status, 0,
3513
NULL, 1, seg->area_len, 0, 0, 0, seg)))
3803
NULL, NULL, 1, seg->area_len, 0, 0, 0, seg)))
3516
3806
/* map the new segment to the original underlying are */
3781
int lv_create_single(struct volume_group *vg,
3782
struct lvcreate_params *lp)
4071
* If lp->thin OR lp->activate is AY*, activate the pool if not already active.
4072
* If lp->thin, create thin LV within the pool - as a snapshot if lp->snapshot.
4073
* If lp->activate is AY*, activate it.
4074
* If lp->activate was AN* and the pool was originally inactive, deactivate it.
4076
static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct lvcreate_params *lp,
4077
const char *new_lv_name)
3784
4079
struct cmd_context *cmd = vg->cmd;
3785
4080
uint32_t size_rest;
3786
4081
uint64_t status = UINT64_C(0);
3787
4082
struct logical_volume *lv, *org = NULL;
4083
struct logical_volume *pool_lv;
4084
struct lv_list *lvl;
3788
4085
int origin_active = 0;
3789
4086
struct lvinfo info;
3791
if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) {
4088
if (new_lv_name && find_lv_in_vg(vg, new_lv_name)) {
3792
4089
log_error("Logical volume \"%s\" already exists in "
3793
"volume group \"%s\"", lp->lv_name, lp->vg_name);
4090
"volume group \"%s\"", new_lv_name, lp->vg_name);
3797
4094
if (vg_max_lv_reached(vg)) {
3798
4095
log_error("Maximum number of logical volumes (%u) reached "
3799
4096
"in volume group %s", vg->max_lv, vg->name);
3803
4100
if ((segtype_is_mirrored(lp->segtype) ||
3804
segtype_is_raid(lp->segtype)) &&
4101
segtype_is_raid(lp->segtype) || segtype_is_thin(lp->segtype)) &&
3805
4102
!(vg->fid->fmt->features & FMT_SEGMENTS)) {
3806
log_error("Metadata does not support %s.",
3807
segtype_is_raid(lp->segtype) ? "RAID" : "mirroring");
4103
log_error("Metadata does not support %s segments.",
3811
4108
if (lp->read_ahead != DM_READ_AHEAD_AUTO &&
3840
4137
lp->extents = lp->extents - size_rest + lp->stripes;
3843
if (lp->zero && !activation()) {
4140
/* Does LV need to be zeroed? Thin handles this as a per-pool in-kernel setting. */
4141
if (lp->zero && !segtype_is_thin(lp->segtype) && !activation()) {
3844
4142
log_error("Can't wipe start of new LV without using "
3845
4143
"device-mapper kernel driver");
3849
4147
status |= lp->permission | VISIBLE_LV;
4149
if (lp->snapshot && lp->thin) {
4150
if (!(org = find_lv(vg, lp->origin))) {
4151
log_error("Couldn't find origin volume '%s'.",
4156
if (org->status & LOCKED) {
4157
log_error("Snapshots of locked devices are not supported.");
4161
lp->voriginextents = org->le_count;
4162
} else if (lp->snapshot) {
3852
4163
if (!activation()) {
3853
4164
log_error("Can't create snapshot without using "
3854
4165
"device-mapper kernel driver");
3858
4169
/* Must zero cow */
3865
4176
if (!(org = find_lv(vg, lp->origin))) {
3866
4177
log_error("Couldn't find origin volume '%s'.",
3870
4181
if (lv_is_virtual_origin(org)) {
3871
4182
log_error("Can't share virtual origins. "
3872
4183
"Use --virtualsize.");
3875
4186
if (lv_is_cow(org)) {
3876
4187
log_error("Snapshots of snapshots are not "
3877
4188
"supported yet.");
3880
4191
if (org->status & LOCKED) {
3881
4192
log_error("Snapshots of locked devices are not "
3882
4193
"supported yet");
3885
4196
if (lv_is_merging_origin(org)) {
3886
4197
log_error("Snapshots of an origin that has a "
3887
4198
"merging snapshot is not supported");
4202
if (lv_is_thin_type(org) && !lv_is_thin_volume(org)) {
4203
log_error("Snapshots of thin pool %sdevices "
4204
"are not supported.",
4205
lv_is_thin_pool_data(org) ? "data " :
4206
lv_is_thin_pool_metadata(org) ?
3890
4211
if ((org->status & MIRROR_IMAGE) ||
3891
4212
(org->status & MIRROR_LOG)) {
3892
4213
log_error("Snapshots of mirror %ss "
3893
4214
"are not supported",
3894
4215
(org->status & MIRROR_LOG) ?
3895
4216
"log" : "image");
3899
4220
if (!lv_info(cmd, org, 0, &info, 0, 0)) {
3900
log_error("Check for existence of snapshot "
4221
log_error("Check for existence of active snapshot "
3901
4222
"origin '%s' failed.", org->name);
3904
4225
origin_active = info.exists;
3927
4254
log_error("Volume group \"%s\" has insufficient free space "
3928
4255
"(%u extents): %u required.",
3929
4256
vg->name, vg->free_count, lp->extents);
3933
4260
if (lp->stripes > dm_list_size(lp->pvh) && lp->alloc != ALLOC_ANYWHERE) {
3934
4261
log_error("Number of stripes (%u) must not exceed "
3935
4262
"number of physical volumes (%d)", lp->stripes,
3936
4263
dm_list_size(lp->pvh));
3940
if ((segtype_is_mirrored(lp->segtype) ||
3941
segtype_is_raid(lp->segtype)) && !activation()) {
4267
if (!activation() &&
4268
(seg_is_mirrored(lp) ||
4270
seg_is_thin_pool(lp))) {
4272
* FIXME: For thin pool add some code to allow delayed
4273
* initialization of empty thin pool volume.
4274
* i.e. using some LV flag, fake message,...
4275
* and testing for metadata pool header signature?
3942
4277
log_error("Can't create %s without using "
3943
4278
"device-mapper kernel driver.",
3944
4279
segtype_is_raid(lp->segtype) ? lp->segtype->name :
4280
segtype_is_mirrored(lp->segtype) ? "mirror" :
4281
"thin pool volume");
3949
4285
/* The snapshot segment gets created later */
4286
if (lp->snapshot && !lp->thin &&
3951
4287
!(lp->segtype = get_segtype_from_string(cmd, "striped")))
3954
4290
if (!archive(vg))
3957
4293
if (!dm_list_empty(&lp->tags)) {
3958
4294
if (!(vg->fid->fmt->features & FMT_TAGS)) {
3959
4295
log_error("Volume group %s does not support tags",
4301
if (seg_is_thin_volume(lp) &&
4302
((lp->activate == CHANGE_AY) ||
4303
(lp->activate == CHANGE_AE) ||
4304
(lp->activate == CHANGE_ALY))) {
4305
/* Ensure all stacked messages are submitted */
4306
if (!(lvl = find_lv_in_vg(vg, lp->pool))) {
4307
log_error("Unable to find existing pool LV %s in VG %s.",
4308
lp->pool, vg->name);
4311
if (!update_pool_lv(lvl->lv, 1))
3965
4315
if (segtype_is_mirrored(lp->segtype) || segtype_is_raid(lp->segtype)) {
3993
if (!dm_list_empty(&lp->tags))
3994
dm_list_splice(&lv->tags, &lp->tags);
3996
lp->region_size = adjusted_mirror_region_size(vg->extent_size,
4347
dm_list_splice(&lv->tags, &lp->tags);
4000
4349
if (!lv_extend(lv, lp->segtype,
4001
4350
lp->stripes, lp->stripe_size,
4002
lp->mirrors, lp->region_size,
4003
lp->extents, lp->pvh, lp->alloc))
4352
seg_is_thin_pool(lp) ? lp->poolmetadataextents : lp->region_size,
4353
seg_is_thin_volume(lp) ? lp->voriginextents : lp->extents,
4354
seg_is_thin_volume(lp) ? (org ? org->name : lp->pool) : NULL, lp->pvh, lp->alloc))
4357
if (seg_is_thin_pool(lp)) {
4358
first_seg(lv)->zero_new_blocks = lp->zero ? 1 : 0;
4359
first_seg(lv)->chunk_size = lp->chunk_size;
4360
/* FIXME: use lowwatermark via lvm.conf global for all thinpools ? */
4361
first_seg(lv)->low_water_mark = 0;
4362
} else if (seg_is_thin_volume(lp)) {
4363
pool_lv = first_seg(lv)->pool_lv;
4365
if (!(first_seg(lv)->device_id =
4366
get_free_pool_device_id(first_seg(pool_lv)))) {
4371
if (!attach_pool_message(first_seg(pool_lv),
4372
DM_THIN_MESSAGE_CREATE_THIN, lv, 0, 0)) {
4378
/* FIXME Log allocation and attachment should have happened inside lv_extend. */
4006
4379
if (lp->log_count &&
4007
4380
!seg_is_raid(first_seg(lv)) && seg_is_mirrored(first_seg(lv))) {
4008
4381
if (!add_mirror_log(cmd, lv, lp->log_count,
4027
init_dmeventd_monitor(lp->activation_monitoring);
4400
if (seg_is_thin(lp)) {
4401
/* For snapshot, suspend active thin origin first */
4402
if (org && lv_is_active(org)) {
4403
if (!pool_below_threshold(first_seg(first_seg(org)->pool_lv))) {
4404
log_error("Cannot create thin snapshot. Pool %s/%s is filled "
4405
"over the autoextend threshold.",
4406
org->vg->name, first_seg(org)->pool_lv->name);
4409
if (!suspend_lv_origin(cmd, org)) {
4410
log_error("Failed to suspend thin snapshot origin %s/%s.",
4411
org->vg->name, org->name);
4414
if (!resume_lv_origin(cmd, org)) { /* deptree updates thin-pool */
4415
log_error("Failed to resume thin snapshot origin %s/%s.",
4416
org->vg->name, org->name);
4419
/* At this point remove pool messages, snapshot is active */
4420
if (!update_pool_lv(first_seg(org)->pool_lv, 0)) {
4422
goto deactivate_and_revert_new_lv;
4425
if (((lp->activate == CHANGE_AY) ||
4426
(lp->activate == CHANGE_AE) ||
4427
(lp->activate == CHANGE_ALY))) {
4428
/* At this point send message to kernel thin mda */
4429
pool_lv = lv_is_thin_pool(lv) ? lv : first_seg(lv)->pool_lv;
4430
if (!update_pool_lv(pool_lv, 1)) {
4432
goto deactivate_and_revert_new_lv;
4434
if (!activate_lv_excl(cmd, lv)) {
4435
log_error("Aborting. Failed to activate thin %s.",
4437
goto deactivate_and_revert_new_lv;
4440
} else if (lp->snapshot) {
4030
4441
if (!activate_lv_excl(cmd, lv)) {
4031
4442
log_error("Aborting. Failed to activate snapshot "
4032
4443
"exception store.");
4038
4449
log_error("Failed to activate new LV.");
4040
4451
goto deactivate_and_revert_new_lv;
4044
if (!lp->zero && !lp->snapshot)
4455
if (!seg_is_thin(lp) && !lp->zero && !lp->snapshot)
4045
4456
log_warn("WARNING: \"%s\" not zeroed", lv->name);
4046
else if (!set_lv(cmd, lv, UINT64_C(0), 0)) {
4457
else if ((!seg_is_thin(lp) ||
4458
(lv_is_thin_volume(lv) &&
4459
!first_seg(first_seg(lv)->pool_lv)->zero_new_blocks)) &&
4460
!set_lv(cmd, lv, UINT64_C(0), 0)) {
4047
4461
log_error("Aborting. Failed to wipe %s.",
4048
4462
lp->snapshot ? "snapshot exception store" :
4049
4463
"start of new LV");
4050
4464
goto deactivate_and_revert_new_lv;
4467
if (lp->snapshot && !lp->thin) {
4054
4468
/* Reset permission after zeroing */
4055
4469
if (!(lp->permission & LVM_WRITE))
4056
4470
lv->status &= ~LVM_WRITE;