diff --git a/WHATS_NEW b/WHATS_NEW index 9e8bfbea1..ff0874541 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.54 - ===================================== + Consolidate LV allocation into alloc_lv(). Treat input units of both 's' and 'S' as 512-byte sectors. (2.02.49) Use standard output units for 'PE Size' and 'Stripe size' in pv/lvdisplay. Add configure --enable-units-compat to set si_unit_consistency off by default. diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index 1160d09ba..b0c0cd47f 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -337,12 +337,6 @@ int import_lv(struct cmd_context *cmd, struct dm_pool *mem, lv->size = lvd->lv_size; lv->le_count = lvd->lv_allocated_le; - lv->snapshot = NULL; - dm_list_init(&lv->snapshot_segs); - dm_list_init(&lv->segments); - dm_list_init(&lv->tags); - dm_list_init(&lv->segs_using_this_lv); - return 1; } @@ -457,7 +451,7 @@ static struct logical_volume *_add_lv(struct dm_pool *mem, { struct logical_volume *lv; - if (!(lv = dm_pool_zalloc(mem, sizeof(*lv)))) + if (!(lv = alloc_lv(mem))) return_NULL; lvid_from_lvnum(&lv->lvid, &vg->id, lvd->lv_number); diff --git a/lib/format_pool/import_export.c b/lib/format_pool/import_export.c index 0ddf8812d..b38355747 100644 --- a/lib/format_pool/import_export.c +++ b/lib/format_pool/import_export.c @@ -59,10 +59,8 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list struct pool_list *pl; struct logical_volume *lv; - if (!(lv = dm_pool_zalloc(mem, sizeof(*lv)))) { - log_error("Unable to allocate logical volume structure"); - return 0; - } + if (!(lv = alloc_lv(mem))) + return_0; lv->status = 0; lv->alloc = ALLOC_NORMAL; @@ -70,11 +68,6 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list lv->name = NULL; lv->le_count = 0; lv->read_ahead = vg->cmd->default_settings.read_ahead; - lv->snapshot = NULL; - dm_list_init(&lv->snapshot_segs); - dm_list_init(&lv->segments); - dm_list_init(&lv->tags); - dm_list_init(&lv->segs_using_this_lv); dm_list_iterate_items(pl, pls) { lv->size += pl->pd.pl_blocks; @@ -99,10 +92,6 @@ int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem, struct dm_list } else { lv->minor = -1; } - lv->snapshot = NULL; - dm_list_init(&lv->snapshot_segs); - dm_list_init(&lv->segments); - dm_list_init(&lv->tags); } lv->le_count = lv->size / POOL_PE_SIZE; diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index 3c416757b..3c9a98e99 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -495,7 +495,7 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)), struct logical_volume *lv; struct config_node *cn; - if (!(lv = dm_pool_zalloc(mem, sizeof(*lv)))) + if (!(lv = alloc_lv(mem))) return_0; if (!(lv->name = dm_pool_strdup(mem, lvn->key))) @@ -541,12 +541,6 @@ static int _read_lvnames(struct format_instance *fid __attribute((unused)), } } - lv->snapshot = NULL; - dm_list_init(&lv->snapshot_segs); - dm_list_init(&lv->segments); - dm_list_init(&lv->tags); - dm_list_init(&lv->segs_using_this_lv); - /* Optional tags */ if ((cn = find_config_node(lvn, "tags")) && !(read_tags(mem, &lv->tags, cn->v))) { diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 70d9da2db..7bcd64fed 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -1862,6 +1862,24 @@ int vg_max_lv_reached(struct volume_group *vg) return 1; } +struct logical_volume *alloc_lv(struct dm_pool *mem) +{ + struct logical_volume *lv; + + if (!(lv = dm_pool_zalloc(mem, sizeof(*lv)))) { + log_error("Unable to allocate logical volume structure"); + return NULL; + } + + lv->snapshot = NULL; + dm_list_init(&lv->snapshot_segs); + dm_list_init(&lv->segments); + dm_list_init(&lv->tags); + dm_list_init(&lv->segs_using_this_lv); + + return lv; +} + /* * Create a new empty LV. */ @@ -1891,7 +1909,7 @@ struct logical_volume *lv_create_empty(const char *name, log_verbose("Creating logical volume %s", name); - if (!(lv = dm_pool_zalloc(vg->vgmem, sizeof(*lv)))) + if (!(lv = alloc_lv(vg->vgmem))) return_NULL; if (!(lv->name = dm_pool_strdup(vg->vgmem, name))) @@ -1904,11 +1922,6 @@ struct logical_volume *lv_create_empty(const char *name, lv->minor = -1; lv->size = UINT64_C(0); lv->le_count = 0; - lv->snapshot = NULL; - dm_list_init(&lv->snapshot_segs); - dm_list_init(&lv->segments); - dm_list_init(&lv->tags); - dm_list_init(&lv->segs_using_this_lv); if (lvid) lv->lvid = *lvid; diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index b04e7e21e..391734bd2 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -316,6 +316,8 @@ struct pv_segment *find_peg_by_pe(const struct physical_volume *pv, uint32_t pe) */ const char *strip_dir(const char *vg_name, const char *dir); +struct logical_volume *alloc_lv(struct dm_pool *mem); + /* * Checks that an lv has no gaps or overlapping segments. * Set complete_vg to perform additional VG level checks.