Activate origin LV as snapshot-merge target and don't activate merging snapshot at all. Using snapshot-origin target would be pointless because the origin contains volatile data while merging is in progress. Signed-off-by: Mikulas Patocka --- lib/activate/dev_manager.c | 33 +++++++++++++++++++++++---------- tools/lvconvert.c | 6 ++++++ 2 files changed, 29 insertions(+), 10 deletions(-) Index: LVM2.2.02.39/lib/activate/dev_manager.c =================================================================== --- LVM2.2.02.39.orig/lib/activate/dev_manager.c 2008-07-11 22:26:14.000000000 +0200 +++ LVM2.2.02.39/lib/activate/dev_manager.c 2008-07-11 22:26:33.000000000 +0200 @@ -749,13 +749,20 @@ static int _add_origin_target_to_dtree(s struct dm_tree_node *dnode, struct logical_volume *lv) { - const char *real_dlid; + const char *real_dlid, *cow_dlid; if (!(real_dlid = build_dlid(dm, lv->lvid.s, "real"))) return_0; - if (!dm_tree_node_add_snapshot_origin_target(dnode, lv->size, real_dlid)) - return_0; + if (!lv->merging_snapshot) { + if (!dm_tree_node_add_snapshot_origin_target(dnode, lv->size, real_dlid)) + return_0; + } else { + if (!(cow_dlid = build_dlid(dm, lv->merging_snapshot->cow->lvid.s, "cow"))) + return_0; + if (!dm_tree_node_add_snapshot_merge_target(dnode, lv->size, real_dlid, cow_dlid, lv->merging_snapshot->chunk_size)) + return_0; + } return 1; } @@ -774,6 +781,10 @@ static int _add_snapshot_target_to_dtree return 0; } + if (snap_seg->status & SNAPSHOT_MERGE) { + return 1; + } + if (!(origin_dlid = build_dlid(dm, snap_seg->origin->lvid.s, "real"))) return_0; @@ -782,13 +793,8 @@ static int _add_snapshot_target_to_dtree size = (uint64_t) snap_seg->len * snap_seg->origin->vg->extent_size; - if (!(snap_seg->status & SNAPSHOT_MERGE)) { - if (!dm_tree_node_add_snapshot_target(dnode, size, origin_dlid, cow_dlid, 1, snap_seg->chunk_size)) - return_0; - } else { - if (!dm_tree_node_add_snapshot_merge_target(dnode, size, origin_dlid, cow_dlid, snap_seg->chunk_size)) - return_0; - } + if (!dm_tree_node_add_snapshot_target(dnode, size, origin_dlid, cow_dlid, 1, snap_seg->chunk_size)) + return_0; return 1; } @@ -850,6 +856,10 @@ static int _add_segment_to_dtree(struct log_error("Clustered snapshots are not yet supported"); return 0; } + if (seg->lv->merging_snapshot) { + if (!_add_new_lv_to_dtree(dm, dtree, seg->lv->merging_snapshot->cow, "cow")) + return_0; + } if (!_add_new_lv_to_dtree(dm, dtree, seg->lv, "real")) return_0; } else if (lv_is_cow(seg->lv) && !layer) { @@ -893,6 +903,9 @@ static int _add_new_lv_to_dtree(struct d uint32_t read_ahead = lv->read_ahead; uint32_t read_ahead_flags = UINT32_C(0); + if (lv_is_cow(lv) && find_cow(lv)->status & SNAPSHOT_MERGE && !layer) + return 1; + if (!(name = build_dm_name(dm->mem, lv->vg->name, lv->name, layer))) return_0; Index: LVM2.2.02.39/tools/lvconvert.c =================================================================== --- LVM2.2.02.39.orig/tools/lvconvert.c 2008-07-11 22:26:24.000000000 +0200 +++ LVM2.2.02.39/tools/lvconvert.c 2008-07-11 22:26:33.000000000 +0200 @@ -734,6 +734,12 @@ static int lvconvert_merge(struct cmd_co return 0; } + if (!deactivate_lv(cmd, lv)) { + log_error("Failed to deactivate merging snapshot %s", lv->name); + vg_revert(lv->vg); + return 0; + } + if (!vg_commit(lv->vg)) return_0;