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,45 +100,59 @@ int validate_name(const char *n)
|
|||||||
return (_validate_name(n) < 0 ? 0 : 1);
|
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[] = {
|
static const char _prefixes[][12] = {
|
||||||
"snapshot",
|
|
||||||
"pvmove",
|
"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",
|
"_cdata",
|
||||||
"_cmeta",
|
"_cmeta",
|
||||||
"_mlog",
|
|
||||||
"_mimage",
|
"_mimage",
|
||||||
|
"_mlog",
|
||||||
"_pmspare",
|
"_pmspare",
|
||||||
"_rimage",
|
"_rimage",
|
||||||
"_rmeta",
|
"_rmeta",
|
||||||
"_vorigin",
|
|
||||||
"_tdata",
|
"_tdata",
|
||||||
"_tmeta",
|
"_tmeta",
|
||||||
NULL
|
"_vorigin"
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned i;
|
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;
|
const char *s;
|
||||||
|
|
||||||
for (i = 0; (s = _reserved_prefixes[i]); i++) {
|
if ((s = _lvname_has_reserved_prefix(name))) {
|
||||||
if (!strncmp(name, s, strlen(s))) {
|
log_error("Names starting \"%s\" are reserved. "
|
||||||
log_error("Names starting \"%s\" are reserved. "
|
"Please choose a different LV name.", s);
|
||||||
"Please choose a different LV name.", s);
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; (s = _reserved_strings[i]); i++) {
|
if ((s = _lvname_has_reserved_string(name))) {
|
||||||
if (strstr(name, s)) {
|
log_error("Names including \"%s\" are reserved. "
|
||||||
log_error("Names including \"%s\" are reserved. "
|
"Please choose a different LV name.", s);
|
||||||
"Please choose a different LV name.", s);
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -154,13 +168,8 @@ name_error_t validate_name_detailed(const char *name)
|
|||||||
|
|
||||||
int is_reserved_lvname(const char *name)
|
int is_reserved_lvname(const char *name)
|
||||||
{
|
{
|
||||||
int rc, old_suppress;
|
return (_lvname_has_reserved_prefix(name) ||
|
||||||
|
_lvname_has_reserved_string(name)) ? 1 : 0;
|
||||||
old_suppress = log_suppress(2);
|
|
||||||
rc = !apply_lvname_restrictions(name);
|
|
||||||
log_suppress(old_suppress);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
|
char *build_dm_uuid(struct dm_pool *mem, const struct logical_volume *lv,
|
||||||
|
Loading…
Reference in New Issue
Block a user