Copying code is terrible practice. The code is hard to change for anyone. Because I need to change this code and don't want to copy the change to any place, I moved it to a separate function. Signed-off-by: Mikulas Patocka --- lib/format1/import-export.c | 8 ++------ lib/format_pool/import_export.c | 11 ++--------- lib/format_text/import_vsn1.c | 6 +----- lib/metadata/lv_manip.c | 18 +++++++++++++----- lib/metadata/metadata-exported.h | 1 + 5 files changed, 19 insertions(+), 25 deletions(-) Index: LVM2.2.02.39/lib/format1/import-export.c =================================================================== --- LVM2.2.02.39.orig/lib/format1/import-export.c 2008-04-22 13:47:22.000000000 +0200 +++ LVM2.2.02.39/lib/format1/import-export.c 2008-07-04 20:37:50.000000000 +0200 @@ -340,11 +340,7 @@ int import_lv(struct dm_pool *mem, struc lv->size = lvd->lv_size; lv->le_count = lvd->lv_allocated_le; - lv->snapshot = NULL; - list_init(&lv->snapshot_segs); - list_init(&lv->segments); - list_init(&lv->tags); - list_init(&lv->segs_using_this_lv); + lv_init(lv); return 1; } @@ -620,7 +616,7 @@ int import_snapshots(struct dm_pool *mem /* insert the snapshot */ if (!vg_add_snapshot(NULL, org, cow, NULL, org->le_count, - lvd->lv_chunk_size)) { + lvd->lv_chunk_size, 0)) { log_err("Couldn't add snapshot."); return 0; } Index: LVM2.2.02.39/lib/format_pool/import_export.c =================================================================== --- LVM2.2.02.39.orig/lib/format_pool/import_export.c 2008-06-11 15:14:41.000000000 +0200 +++ LVM2.2.02.39/lib/format_pool/import_export.c 2008-07-03 23:25:24.000000000 +0200 @@ -79,11 +79,7 @@ int import_pool_lvs(struct volume_group lv->name = NULL; lv->le_count = 0; lv->read_ahead = vg->cmd->default_settings.read_ahead; - lv->snapshot = NULL; - list_init(&lv->snapshot_segs); - list_init(&lv->segments); - list_init(&lv->tags); - list_init(&lv->segs_using_this_lv); + lv_init(lv); list_iterate_items(pl, pls) { lv->size += pl->pd.pl_blocks; @@ -108,10 +104,7 @@ int import_pool_lvs(struct volume_group } else { lv->minor = -1; } - lv->snapshot = NULL; - list_init(&lv->snapshot_segs); - list_init(&lv->segments); - list_init(&lv->tags); + lv_init(lv); } lv->le_count = lv->size / POOL_PE_SIZE; Index: LVM2.2.02.39/lib/format_text/import_vsn1.c =================================================================== --- LVM2.2.02.39.orig/lib/format_text/import_vsn1.c 2008-01-31 13:35:31.000000000 +0100 +++ LVM2.2.02.39/lib/format_text/import_vsn1.c 2008-07-03 23:25:24.000000000 +0200 @@ -532,11 +532,7 @@ static int _read_lvnames(struct format_i } } - lv->snapshot = NULL; - list_init(&lv->snapshot_segs); - list_init(&lv->segments); - list_init(&lv->tags); - list_init(&lv->segs_using_this_lv); + lv_init(lv); /* Optional tags */ if ((cn = find_config_node(lvn, "tags")) && Index: LVM2.2.02.39/lib/metadata/lv_manip.c =================================================================== --- LVM2.2.02.39.orig/lib/metadata/lv_manip.c 2008-04-22 14:54:33.000000000 +0200 +++ LVM2.2.02.39/lib/metadata/lv_manip.c 2008-07-06 20:11:30.000000000 +0200 @@ -1790,6 +1790,18 @@ char *generate_lv_name(struct volume_gro } /* + * Initialize common fields in a structure. + */ +void lv_init(struct logical_volume *lv) +{ + lv->snapshot = NULL; + list_init(&lv->snapshot_segs); + list_init(&lv->segments); + list_init(&lv->tags); + list_init(&lv->segs_using_this_lv); +} + +/* * Create a new empty LV. */ struct logical_volume *lv_create_empty(const char *name, @@ -1846,11 +1858,7 @@ struct logical_volume *lv_create_empty(c lv->minor = -1; lv->size = UINT64_C(0); lv->le_count = 0; - lv->snapshot = NULL; - list_init(&lv->snapshot_segs); - list_init(&lv->segments); - list_init(&lv->tags); - list_init(&lv->segs_using_this_lv); + lv_init(lv); if (lvid) lv->lvid = *lvid; Index: LVM2.2.02.39/lib/metadata/metadata-exported.h =================================================================== --- LVM2.2.02.39.orig/lib/metadata/metadata-exported.h 2008-06-24 22:10:31.000000000 +0200 +++ LVM2.2.02.39/lib/metadata/metadata-exported.h 2008-07-06 20:11:32.000000000 +0200 @@ -381,6 +381,7 @@ int vg_split_mdas(struct cmd_context *cm struct volume_group *vg_to); /* Manipulate LVs */ +void lv_init(struct logical_volume *lv); struct logical_volume *lv_create_empty(const char *name, union lvid *lvid, uint32_t status,