Refactor some pv library code related to mda balancing.
cover Refactor some pv library code related to mda balancing.
These 3 patches are some simple cleanups and refactorings I found while working on metadata balancing. Should be no functional change.
PATCH 1/3 Correct 'void *' usage in pvcreate_single.
--- lib/metadata/metadata.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
lib/metadata/metadata.c +1 -1
@@ -1348,7 +1348,7 @@ struct physical_volume * pvcreate_single(struct cmd_context *cmd,const char *pv_name, struct pvcreate_params *pp) { - void *pv; + struct physical_volume *pv;struct device *dev;struct dm_list mdas;struct pvcreate_params default_pp;
Signature · 1 line
1.6.0.6
PATCH 2/3 Remove useless memory allocation for pv->vg_name in _alloc_pv().
All this seems to do is provide a memory leak so remove it. The only caller of _alloc_pv() later explicitly sets pv->vg_name = fmt->orphan_vg_name so clearly this allocation should be removed. I also saw no where in the code where strncpy was used to assign pv->vg_name - only direct assignments and strdup's.
--- lib/metadata/metadata.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
lib/metadata/metadata.c +0 -5
@@ -1444,11 +1444,6 @@ static struct physical_volume *_alloc_pv(struct dm_pool *mem, struct device *devif (!pv) return_NULL; -if (!(pv->vg_name =dm_pool_zalloc (mem,NAME_LEN ))) { -dm_pool_free (mem, pv); -return NULL ; - } - pv->pe_size =0 ; pv->pe_start =0 ; pv->pe_count =0 ;
Signature · 1 line
1.6.0.6
PATCH 3/3 Call _alloc_pv() inside _pv_read() and clean up error paths.
We should be consistent with pv constructors so call _alloc_pv() here as we do from pv_create().
--- lib/metadata/metadata.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-)
lib/metadata/metadata.c +8 -7
@@ -3021,29 +3021,30 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,if (label_sector && *label_sector) *label_sector = label->sector; -if (!(pv =dm_pool_zalloc (pvmem,sizeof (*pv)))) { + pv =_alloc_pv (pvmem, dev); +if (!pv) {log_error ("pv allocation for '%s' failed" , pv_name);return NULL ; } -dm_list_init (&pv->tags); -dm_list_init (&pv->segments); -/* FIXME Move more common code up here */ if (!(info->fmt->ops->pv_read (info->fmt, pv_name, pv, mdas, scan_label_only))) {log_error ("Failed to read existing physical volume '%s'" , pv_name); -return NULL ; + goto bad; }if (!pv->size) -return NULL ; + goto bad;if (!alloc_pv_segment_whole_pv (pvmem, pv)) - return_NULL; + goto_bad;return pv; +bad: +_free_pv (pvmem, pv); +return NULL ; }/* May return empty list */
Signature · 1 line
1.6.0.6