1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

libdm: add dm_stats_get_{current_}area_offset()

Add a method to retrieve the offset of an area within the
containing region (rather than the offset within the containing
device returned by dm_stats_get_area_start()).

Although users of the library can calculate this themselves it is
better to provide this through a method call to avoid users making
assumptions about the structure of regions and areas.
This commit is contained in:
Bryn M. Reeves 2015-08-14 20:30:05 +01:00
parent 77fae3d852
commit 00ed523659
3 changed files with 31 additions and 3 deletions

View File

@ -1 +1,3 @@
dm_report_is_empty
dm_stats_get_area_offset
dm_stats_get_current_area_offset

View File

@ -705,19 +705,27 @@ uint64_t dm_stats_get_region_area_len(const struct dm_stats *dms,
uint64_t *area_len, uint64_t region_id);
/*
* Area properties: start and length.
* Area properties: start, offset and length.
*
* The area length is always equal to the area length of the region
* that contains it and is obtained from dm_stats_get_region_area_len().
*
* The start offset of an area is a function of the area_id and the
* containing region's start and area length.
* The start of an area is a function of the area_id and the containing
* region's start and area length: it gives the absolute offset into the
* containing device of the beginning of the area.
*
* The offset expresses the area's relative offset into the current
* region. I.e. the area start minus the start offset of the containing
* region.
*
* All values are returned in units of 512b sectors.
*/
uint64_t dm_stats_get_area_start(const struct dm_stats *dms, uint64_t *start,
uint64_t region_id, uint64_t area_id);
uint64_t dm_stats_get_area_offset(const struct dm_stats *dms, uint64_t *offset,
uint64_t region_id, uint64_t area_id);
/*
* Retrieve program_id and aux_data for a specific region. Only valid
* following a call to dm_stats_list(). The returned pointer does not
@ -876,6 +884,9 @@ uint64_t dm_stats_get_current_region_area_len(const struct dm_stats *dms,
uint64_t dm_stats_get_current_area_start(const struct dm_stats *dms,
uint64_t *start);
uint64_t dm_stats_get_current_area_offset(const struct dm_stats *dms,
uint64_t *offset);
uint64_t dm_stats_get_current_area_len(const struct dm_stats *dms,
uint64_t *start);

View File

@ -1335,6 +1335,14 @@ uint64_t dm_stats_get_area_start(const struct dm_stats *dms, uint64_t *start,
return 1;
}
uint64_t dm_stats_get_area_offset(const struct dm_stats *dms, uint64_t *offset,
uint64_t region_id, uint64_t area_id)
{
if (!dms || !dms->regions)
return_0;
*offset = dms->regions[region_id].step * area_id;
}
uint64_t dm_stats_get_current_area_start(const struct dm_stats *dms,
uint64_t *start)
{
@ -1342,6 +1350,13 @@ uint64_t dm_stats_get_current_area_start(const struct dm_stats *dms,
dms->cur_region, dms->cur_area);
}
uint64_t dm_stats_get_current_area_offset(const struct dm_stats *dms,
uint64_t *offset)
{
return dm_stats_get_area_offset(dms, offset,
dms->cur_region, dms->cur_area);
}
uint64_t dm_stats_get_current_area_len(const struct dm_stats *dms,
uint64_t *len)
{