mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cleanup: refactor apply_lvname_restrictions
Split apply_lvname_restrictions into 2 internal function: _lvname_has_reserved_prefix() _lvname_has_reserved_string()
This commit is contained in:
parent
9eab84aa2b
commit
56175f6ba9
@ -100,46 +100,60 @@ int validate_name(const char *n)
|
||||
return (_validate_name(n) < 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
int apply_lvname_restrictions(const char *name)
|
||||
static const char *_lvname_has_reserved_prefix(const char *lvname)
|
||||
{
|
||||
static const char * const _reserved_prefixes[] = {
|
||||
"snapshot",
|
||||
static const char _prefixes[][12] = {
|
||||
"pvmove",
|
||||
NULL
|
||||
"snapshot"
|
||||
};
|
||||
unsigned i;
|
||||
|
||||
static const char * const _reserved_strings[] = {
|
||||
for (i = 0; i < DM_ARRAY_SIZE(_prefixes); ++i)
|
||||
if (!strncmp(lvname, _prefixes[i], strlen(_prefixes[i])))
|
||||
return _prefixes[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *_lvname_has_reserved_string(const char *lvname)
|
||||
{
|
||||
static const char _strings[][12] = {
|
||||
"_cdata",
|
||||
"_cmeta",
|
||||
"_mlog",
|
||||
"_mimage",
|
||||
"_mlog",
|
||||
"_pmspare",
|
||||
"_rimage",
|
||||
"_rmeta",
|
||||
"_vorigin",
|
||||
"_tdata",
|
||||
"_tmeta",
|
||||
NULL
|
||||
"_vorigin"
|
||||
};
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i)
|
||||
if (strstr(lvname, _strings[i]))
|
||||
return _strings[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int apply_lvname_restrictions(const char *name)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
for (i = 0; (s = _reserved_prefixes[i]); i++) {
|
||||
if (!strncmp(name, s, strlen(s))) {
|
||||
if ((s = _lvname_has_reserved_prefix(name))) {
|
||||
log_error("Names starting \"%s\" are reserved. "
|
||||
"Please choose a different LV name.", s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; (s = _reserved_strings[i]); i++) {
|
||||
if (strstr(name, s)) {
|
||||
if ((s = _lvname_has_reserved_string(name))) {
|
||||
log_error("Names including \"%s\" are reserved. "
|
||||
"Please choose a different LV name.", s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -154,13 +168,8 @@ name_error_t validate_name_detailed(const char *name)
|
||||
|
||||
int is_reserved_lvname(const char *name)
|
||||
{
|
||||
int rc, old_suppress;
|
||||
|
||||
old_suppress = log_suppress(2);
|
||||
rc = !apply_lvname_restrictions(name);
|
||||
log_suppress(old_suppress);
|
||||
|
||||
return rc;
|
||||
return (_lvname_has_reserved_prefix(name) ||
|
||||
_lvname_has_reserved_string(name)) ? 1 : 0;
|
||||
}
|
||||
|
||||
char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
|
||||
|
Loading…
Reference in New Issue
Block a user