mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
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 <dwysocha@redhat.com>
This commit is contained in:
parent
8c38c9642c
commit
483a7cb6d5
@ -693,9 +693,18 @@ uint32_t pv_pe_size(const pv_t *pv);
|
|||||||
uint64_t pv_pe_start(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_count(const pv_t *pv);
|
||||||
uint32_t pv_pe_alloc_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);
|
int vg_missing_pv_count(const vg_t *vg);
|
||||||
uint32_t vg_status(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)
|
#define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
|
||||||
|
|
||||||
struct vgcreate_params {
|
struct vgcreate_params {
|
||||||
|
@ -3364,11 +3364,54 @@ uint32_t pv_pe_alloc_count(const pv_t *pv)
|
|||||||
return pv_field(pv, pe_alloc_count);
|
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)
|
uint32_t vg_status(const vg_t *vg)
|
||||||
{
|
{
|
||||||
return vg->status;
|
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
|
* pv_by_path - Given a device path return a PV handle if it is a PV
|
||||||
* @cmd - handle to the LVM command instance
|
* @cmd - handle to the LVM command instance
|
||||||
|
@ -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;
|
const struct volume_group *vg = (const struct volume_group *) data;
|
||||||
uint64_t size;
|
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);
|
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;
|
const struct volume_group *vg = (const struct volume_group *) data;
|
||||||
uint64_t freespace;
|
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);
|
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,
|
struct dm_report_field *field,
|
||||||
const void *data, void *private)
|
const void *data, void *private)
|
||||||
{
|
{
|
||||||
struct lvmcache_info *info;
|
|
||||||
uint32_t count;
|
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 = pv_mda_count(pv);
|
||||||
count = info ? dm_list_size(&info->mdas) : 0;
|
|
||||||
|
|
||||||
return _uint32_disp(rh, mem, field, &count, private);
|
return _uint32_disp(rh, mem, field, &count, private);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user