Implement a shared store target in libdevmapper. Signed-off-by: Mikulas Patocka --- libdm/.exported_symbols | 1 + libdm/libdevmapper.h | 6 ++++++ libdm/libdm-deptree.c | 32 +++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) Index: LVM2.2.02.60/libdm/.exported_symbols =================================================================== --- LVM2.2.02.60.orig/libdm/.exported_symbols 2010-02-08 18:23:21.000000000 +0100 +++ LVM2.2.02.60/libdm/.exported_symbols 2010-02-08 18:32:31.000000000 +0100 @@ -72,6 +72,7 @@ dm_tree_children_use_uuid dm_tree_node_add_snapshot_origin_target dm_tree_node_add_snapshot_target dm_tree_node_add_snapshot_merge_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.60/libdm/libdevmapper.h =================================================================== --- LVM2.2.02.60.orig/libdm/libdevmapper.h 2010-02-08 13:28:50.000000000 +0100 +++ LVM2.2.02.60/libdm/libdevmapper.h 2010-02-08 18:32:31.000000000 +0100 @@ -400,6 +400,12 @@ int dm_tree_node_add_snapshot_merge_targ const char *cow_uuid, const char *merge_uuid, 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.60/libdm/libdm-deptree.c =================================================================== --- LVM2.2.02.60.orig/libdm/libdm-deptree.c 2010-02-08 13:47:42.000000000 +0100 +++ LVM2.2.02.60/libdm/libdm-deptree.c 2010-02-08 19:53:51.000000000 +0100 @@ -36,6 +36,7 @@ enum { SEG_SNAPSHOT, SEG_SNAPSHOT_ORIGIN, SEG_SNAPSHOT_MERGE, + SEG_SNAPSHOT_SHARED, SEG_STRIPED, SEG_ZERO, }; @@ -53,6 +54,7 @@ struct { { SEG_SNAPSHOT, "snapshot" }, { SEG_SNAPSHOT_ORIGIN, "snapshot-origin" }, { SEG_SNAPSHOT_MERGE, "snapshot-merge" }, + { SEG_SNAPSHOT_SHARED, "multisnapshot" }, { SEG_STRIPED, "striped" }, { SEG_ZERO, "zero"}, }; @@ -1490,6 +1492,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; @@ -1507,6 +1517,7 @@ static int _emit_segment_line(struct dm_ case SEG_SNAPSHOT: case SEG_SNAPSHOT_ORIGIN: case SEG_SNAPSHOT_MERGE: + case SEG_SNAPSHOT_SHARED: case SEG_ZERO: break; case SEG_CRYPT: @@ -1781,14 +1792,12 @@ static int _add_snapshot_target(struct d const char *origin_uuid, const char *cow_uuid, const char *merge_uuid, + unsigned seg_type, const char *exception_store, uint32_t chunk_size) { struct load_segment *seg; struct dm_tree_node *origin_node, *cow_node, *merge_node; - unsigned seg_type; - - seg_type = !merge_uuid ? SEG_SNAPSHOT : SEG_SNAPSHOT_MERGE; if (!(seg = _add_segment(node, seg_type, size))) return_0; @@ -1847,7 +1856,8 @@ int dm_tree_node_add_snapshot_target(str uint32_t chunk_size) { return _add_snapshot_target(node, size, origin_uuid, cow_uuid, - NULL, exception_store, chunk_size); + NULL, SEG_SNAPSHOT, exception_store, + chunk_size); } int dm_tree_node_add_snapshot_merge_target(struct dm_tree_node *node, @@ -1858,7 +1868,19 @@ int dm_tree_node_add_snapshot_merge_targ uint32_t chunk_size) { return _add_snapshot_target(node, size, origin_uuid, cow_uuid, - merge_uuid, "P", chunk_size); + merge_uuid, SEG_SNAPSHOT_MERGE, "P", + 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, NULL, + SEG_SNAPSHOT_SHARED, exception_store, chunk_size); } int dm_tree_node_add_error_target(struct dm_tree_node *node,