From 483a7cb6d56bbe0ec5d123d9764a3fc0b42d7382 Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Sun, 26 Jul 2009 12:41:09 +0000 Subject: [PATCH] Refactor a few report field calculations into separate functions. For liblvm 'get' functions, we should share code with the reporting functions. This means we need common code to return the values for the fields. In this patch we refactor a few of the fields needed in liblvm. Unfortunately, for the simple fields that do derefernces of structure members (for example, vg_extent_count), we cannot call the common function from the reporting infrastructure without more refactoring. The reason is that the dereference of the simple fields is done deep inside the reporting code (to get the generic "data" pointer), and the display function is a generic 'size32' function. We can fix these issues later with more refactoring. Should be no functional change and the testsuite should cover any possible regressions. The only fields in the report affected by this patch are: vg_size, vg_free, and pv_mda_count. Author: Dave Wysochanski --- lib/metadata/metadata-exported.h | 9 +++++++ lib/metadata/metadata.c | 43 ++++++++++++++++++++++++++++++++ lib/report/report.c | 11 ++++---- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 1c6fccda8..142381b9c 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -693,9 +693,18 @@ uint32_t pv_pe_size(const pv_t *pv); uint64_t pv_pe_start(const pv_t *pv); uint32_t pv_pe_count(const pv_t *pv); uint32_t pv_pe_alloc_count(const pv_t *pv); +uint32_t pv_mda_count(const pv_t *pv); + +uint64_t lv_size(const lv_t *lv); int vg_missing_pv_count(const vg_t *vg); uint32_t vg_status(const vg_t *vg); +uint64_t vg_size(const vg_t *vg); +uint64_t vg_free(const vg_t *vg); +uint64_t vg_extent_size(const vg_t *vg); +uint64_t vg_extent_count(const vg_t *vg); +uint64_t vg_free_count(const vg_t *vg); +uint64_t vg_pv_count(const vg_t *vg); #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED) struct vgcreate_params { diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 64231e303..8378612d4 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -3364,11 +3364,54 @@ uint32_t pv_pe_alloc_count(const pv_t *pv) return pv_field(pv, pe_alloc_count); } +uint32_t pv_mda_count(const pv_t *pv) +{ + struct lvmcache_info *info; + + info = info_from_pvid((const char *)&pv->id.uuid, 0); + return info ? dm_list_size(&info->mdas) : UINT64_C(0); +} + uint32_t vg_status(const vg_t *vg) { return vg->status; } +uint64_t vg_size(const vg_t *vg) +{ + return (uint64_t) vg->extent_count * vg->extent_size; +} + +uint64_t vg_free(const vg_t *vg) +{ + return (uint64_t) vg->free_count * vg->extent_size; +} + +uint64_t vg_extent_size(const vg_t *vg) +{ + return (uint64_t) vg->extent_size; +} + +uint64_t vg_extent_count(const vg_t *vg) +{ + return (uint64_t) vg->extent_count; +} + +uint64_t vg_free_count(const vg_t *vg) +{ + return (uint64_t) vg->free_count; +} + +uint64_t vg_pv_count(const vg_t *vg) +{ + return (uint64_t) vg->pv_count; +} + +uint64_t lv_size(const lv_t *lv) +{ + return lv->size; +} + /** * pv_by_path - Given a device path return a PV handle if it is a PV * @cmd - handle to the LVM command instance diff --git a/lib/report/report.c b/lib/report/report.c index 3de63ce78..bfa4b76db 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -672,7 +672,7 @@ static int _vgsize_disp(struct dm_report *rh, struct dm_pool *mem, const struct volume_group *vg = (const struct volume_group *) data; uint64_t size; - size = (uint64_t) vg->extent_count * vg->extent_size; + size = (uint64_t) vg_size(vg); return _size64_disp(rh, mem, field, &size, private); } @@ -812,7 +812,7 @@ static int _vgfree_disp(struct dm_report *rh, struct dm_pool *mem, const struct volume_group *vg = (const struct volume_group *) data; uint64_t freespace; - freespace = (uint64_t) vg->free_count * vg->extent_size; + freespace = (uint64_t) vg_free(vg); return _size64_disp(rh, mem, field, &freespace, private); } @@ -853,12 +853,11 @@ static int _pvmdas_disp(struct dm_report *rh, struct dm_pool *mem, struct dm_report_field *field, const void *data, void *private) { - struct lvmcache_info *info; uint32_t count; - const char *pvid = (const char *)(&((struct id *) data)->uuid); + const struct physical_volume *pv = + (const struct physical_volume *) data; - info = info_from_pvid(pvid, 0); - count = info ? dm_list_size(&info->mdas) : 0; + count = pv_mda_count(pv); return _uint32_disp(rh, mem, field, &count, private); } -- 2.43.5