From 3a841515af623b86be0628ef6568ff74009ea643 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 11 Dec 2017 18:12:47 +0100 Subject: [PATCH] lvm-string: add function to detect component LV suffix Add is_component_lvname() function to recognize component LV name. --- lib/misc/lvm-string.c | 30 +++++++++++++++++++++++++++--- lib/misc/lvm-string.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c index cdcc993d3..a2098fd0f 100644 --- a/lib/misc/lvm-string.c +++ b/lib/misc/lvm-string.c @@ -150,22 +150,41 @@ static const char *_lvname_has_reserved_prefix(const char *lvname) return NULL; } -static const char *_lvname_has_reserved_string(const char *lvname) +static const char *_lvname_has_reserved_component_string(const char *lvname) { static const char _strings[][12] = { + /* Suffixes for compoment LVs */ "_cdata", "_cmeta", "_corig", "_mimage", "_mlog", - "_pmspare", "_rimage", "_rmeta", "_tdata", - "_tmeta", + "_tmeta" + }; + unsigned i; + + for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i) + if (strstr(lvname, _strings[i])) + return _strings[i]; + + return NULL; +} + +static const char *_lvname_has_reserved_string(const char *lvname) +{ + static const char _strings[][12] = { + /* Additional suffixes for non-compoment LVs */ + "_pmspare", "_vorigin" }; unsigned i; + const char *cs; + + if ((cs = _lvname_has_reserved_component_string(lvname))) + return cs; for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i) if (strstr(lvname, _strings[i])) @@ -208,6 +227,11 @@ int is_reserved_lvname(const char *name) _lvname_has_reserved_string(name)) ? 1 : 0; } +int is_component_lvname(const char *name) +{ + return (_lvname_has_reserved_component_string(name)) ? 1 : 0; +} + char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv, const char *layer) { diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h index ebdf95652..4e7404a8d 100644 --- a/lib/misc/lvm-string.h +++ b/lib/misc/lvm-string.h @@ -47,6 +47,7 @@ int validate_tag(const char *n); void copy_systemid_chars(const char *src, char *dst); int apply_lvname_restrictions(const char *name); +int is_component_lvname(const char *name); int is_reserved_lvname(const char *name); /*