1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-12-15 08:23:51 +03:00

libdm: add min_num_bits to dm_bitset_parse_list()

It's useful to be able to specify a minimum number of bits for a
new bitmap parsed from a list, for e.g. to allow for expansing a
group without needing to copy/reallocate the bitmap.

Add a backwards compatible symbol for programs linked against old
versions of the library.
This commit is contained in:
Bryn M. Reeves
2016-12-11 22:41:45 +00:00
parent e8d966bc31
commit 7dff632c11
4 changed files with 27 additions and 4 deletions

View File

@@ -145,7 +145,8 @@ int dm_bit_get_last(dm_bitset_t bs)
/*
* Based on the Linux kernel __bitmap_parselist from lib/bitmap.c
*/
dm_bitset_t dm_bitset_parse_list(const char *str, struct dm_pool *mem)
dm_bitset_t dm_bitset_parse_list(const char *str, struct dm_pool *mem,
size_t min_num_bits)
{
unsigned a, b;
int c, old_c, totaldigits, ndigits, nmaskbits;
@@ -221,6 +222,9 @@ scan:
} while (len && c == ',');
if (!mask) {
if (min_num_bits && (nmaskbits < min_num_bits))
nmaskbits = min_num_bits;
if (!(mask = dm_bitset_create(mem, nmaskbits)))
goto_bad;
str = start;
@@ -237,3 +241,19 @@ bad:
}
return NULL;
}
#if defined(__GNUC__)
/*
* Maintain backward compatibility with older versions that did not
* accept a 'min_num_bits' argument to dm_bitset_parse_list().
*/
dm_bitset_t dm_bitset_parse_list_v1_02_129(const char *str, struct dm_pool *mem);
dm_bitset_t dm_bitset_parse_list_v1_02_129(const char *str, struct dm_pool *mem)
{
return dm_bitset_parse_list(str, mem, 0);
}
DM_EXPORT_SYMBOL(dm_bitset_parse_list, 1_02_129);
#else /* if defined(__GNUC__) */
#endif