diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2016-12-11 12:53:04 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-12-14 11:45:28 +0000 |
commit | aa5c026d6144b9f599fea455acfd3c398f18caaa (patch) | |
tree | b5e9049fcc195b45c6bf944a599e6d187da59dc8 | |
parent | 35791689ba5ef95da45290fd12ce9cff55c86258 (diff) | |
download | lvm2-aa5c026d6144b9f599fea455acfd3c398f18caaa.tar.gz |
libdm: add extent table helpers
Add a pair of helper functions for searching tables of _extent
objects:
/* test whether an extent matching start/len exists */
_extent_in_extents(nr_extents, extents, start, len)
/* return the extent matching star/len or NULL */
_find_extent(nr_extents, extents, start, len)
The filemap remapping support will use these when filtering the
set of extents that need to be updated in order to reflect the
current state of a mapped file.
-rw-r--r-- | libdm/libdm-stats.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index 8d202d21c..038312a50 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -4390,6 +4390,25 @@ bad: return NULL; } +#define MATCH_EXTENT(e, s, l) \ +(((e).start == (s)) && ((e).len == (l))) + +static struct _extent *_find_extent(size_t nr_extents, struct _extent *extents, + uint64_t start, uint64_t len) +{ + size_t i; + for (i = 0; i < nr_extents; i++) + if (MATCH_EXTENT(extents[i], start, len)) + return extents + i; + return NULL; +} + +static int _extent_in_extents(size_t nr_extents, struct _extent *extents, + uint64_t start, uint64_t len) +{ + return (_find_extent(nr_extents, extents, start, len) != NULL); +} + /* * Create a set of regions representing the extents of a file and * return a table of uint64_t region_id values. The number of regions |