Implement a shared store target in libdevmapper. Signed-off-by: Mikulas Patocka --- libdm/.exported_symbols | 1 libdm/libdevmapper.h | 6 +++++ libdm/libdm-deptree.c | 50 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 8 deletions(-) Index: LVM2.2.02.53/libdm/.exported_symbols =================================================================== --- LVM2.2.02.53.orig/libdm/.exported_symbols 2009-10-13 02:32:41.000000000 +0200 +++ LVM2.2.02.53/libdm/.exported_symbols 2009-10-13 02:32:43.000000000 +0200 @@ -68,6 +68,7 @@ dm_tree_suspend_children dm_tree_children_use_uuid dm_tree_node_add_snapshot_origin_target dm_tree_node_add_snapshot_target +dm_tree_node_add_snapshot_shared_target dm_tree_node_add_error_target dm_tree_node_add_zero_target dm_tree_node_add_linear_target Index: LVM2.2.02.53/libdm/libdevmapper.h =================================================================== --- LVM2.2.02.53.orig/libdm/libdevmapper.h 2009-10-13 02:32:41.000000000 +0200 +++ LVM2.2.02.53/libdm/libdevmapper.h 2009-10-13 02:32:43.000000000 +0200 @@ -382,6 +382,12 @@ int dm_tree_node_add_snapshot_target(str const char *cow_uuid, const char *exception_store, uint32_t chunk_size); +int dm_tree_node_add_snapshot_shared_target(struct dm_tree_node *node, + uint64_t size, + const char *origin_uuid, + const char *cow_uuid, + const char *exception_store, + uint32_t chunk_size); int dm_tree_node_add_error_target(struct dm_tree_node *node, uint64_t size); int dm_tree_node_add_zero_target(struct dm_tree_node *node, Index: LVM2.2.02.53/libdm/libdm-deptree.c =================================================================== --- LVM2.2.02.53.orig/libdm/libdm-deptree.c 2009-10-13 02:32:41.000000000 +0200 +++ LVM2.2.02.53/libdm/libdm-deptree.c 2009-10-13 02:33:13.000000000 +0200 @@ -35,6 +35,7 @@ enum { SEG_MIRRORED, SEG_SNAPSHOT, SEG_SNAPSHOT_ORIGIN, + SEG_SNAPSHOT_SHARED, SEG_STRIPED, SEG_ZERO, }; @@ -51,6 +52,7 @@ struct { { SEG_MIRRORED, "mirror" }, { SEG_SNAPSHOT, "snapshot" }, { SEG_SNAPSHOT_ORIGIN, "snapshot-origin" }, + { SEG_SNAPSHOT_SHARED, "multisnapshot" }, { SEG_STRIPED, "striped" }, { SEG_ZERO, "zero"}, }; @@ -1437,6 +1439,14 @@ static int _emit_segment_line(struct dm_ return_0; EMIT_PARAMS(pos, "%s", originbuf); break; + case SEG_SNAPSHOT_SHARED: + if (!_build_dev_string(originbuf, sizeof(originbuf), seg->origin)) + return_0; + if (!_build_dev_string(cowbuf, sizeof(cowbuf), seg->cow)) + return_0; + EMIT_PARAMS(pos, "%s %s %d 0 %s 0", originbuf, cowbuf, + seg->chunk_size, seg->exception_store); + break; case SEG_STRIPED: EMIT_PARAMS(pos, "%u %u ", seg->area_count, seg->stripe_size); break; @@ -1453,6 +1463,7 @@ static int _emit_segment_line(struct dm_ case SEG_ERROR: case SEG_SNAPSHOT: case SEG_SNAPSHOT_ORIGIN: + case SEG_SNAPSHOT_SHARED: case SEG_ZERO: break; case SEG_CRYPT: @@ -1718,17 +1729,18 @@ int dm_tree_node_add_snapshot_origin_tar return 1; } -int dm_tree_node_add_snapshot_target(struct dm_tree_node *node, - uint64_t size, - const char *origin_uuid, - const char *cow_uuid, - const char *exception_store, - uint32_t chunk_size) +static int _add_snapshot_target(struct dm_tree_node *node, + uint64_t size, + const char *origin_uuid, + const char *cow_uuid, + int seg_type, + const char *exception_store, + uint32_t chunk_size) { struct load_segment *seg; struct dm_tree_node *origin_node, *cow_node; - if (!(seg = _add_segment(node, SEG_SNAPSHOT, size))) + if (!(seg = _add_segment(node, seg_type, size))) return_0; if (!(origin_node = dm_tree_find_node_by_uuid(node->dtree, origin_uuid))) { @@ -1741,7 +1753,7 @@ int dm_tree_node_add_snapshot_target(str return_0; if (!(cow_node = dm_tree_find_node_by_uuid(node->dtree, cow_uuid))) { - log_error("Couldn't find snapshot origin uuid %s.", cow_uuid); + log_error("Couldn't find snapshot COW device uuid %s.", cow_uuid); return 0; } @@ -1759,6 +1771,28 @@ int dm_tree_node_add_snapshot_target(str return 1; } +int dm_tree_node_add_snapshot_target(struct dm_tree_node *node, + uint64_t size, + const char *origin_uuid, + const char *cow_uuid, + const char *exception_store, + uint32_t chunk_size) +{ + return _add_snapshot_target(node, size, origin_uuid, cow_uuid, + SEG_SNAPSHOT, exception_store, chunk_size); +} + +int dm_tree_node_add_snapshot_shared_target(struct dm_tree_node *node, + uint64_t size, + const char *origin_uuid, + const char *cow_uuid, + const char *exception_store, + uint32_t chunk_size) +{ + return _add_snapshot_target(node, size, origin_uuid, cow_uuid, + SEG_SNAPSHOT_SHARED, exception_store, chunk_size); +} + int dm_tree_node_add_error_target(struct dm_tree_node *node, uint64_t size) {