1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

dmsetup: Accept vg/lv name format.

If there is exactly one / which is not the first character, check
for /dev/vg/lv (as dm_dir()/../$name i.e. /dev/mapper/../vg/lv.)
This commit is contained in:
Alasdair G Kergon 2015-07-29 12:24:36 +01:00
parent ca0d9a70d1
commit a5491d3698
2 changed files with 42 additions and 19 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.127 - Version 2.02.127 -
================================= =================================
Recognise vg/lv name format in dmsetup.
Fix regression in cache causing some PVs to bypass filters (2.02.105). Fix regression in cache causing some PVs to bypass filters (2.02.105).
Version 2.02.126 - 24th July 2015 Version 2.02.126 - 24th July 2015

View File

@ -546,22 +546,19 @@ static int _dm_task_set_name_from_path(struct dm_task *dmt, const char *path,
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
struct stat st1, st2; struct stat st1, st2;
const char *final_name; const char *final_name = NULL;
size_t len;
if (dmt->type == DM_DEVICE_CREATE) { if (dmt->type == DM_DEVICE_CREATE) {
log_error("Name \"%s\" invalid. It contains \"/\".", path); log_error("Name \"%s\" invalid. It contains \"/\".", path);
return 0; return 0;
} }
if (stat(path, &st1)) { if (!stat(path, &st1)) {
log_error("Device %s not found", path);
return 0;
}
/* /*
* Found directly.
* If supplied path points to same device as last component * If supplied path points to same device as last component
* under /dev/mapper, use that name directly. Otherwise call * under /dev/mapper, use that name directly.
* _find_dm_name_of_device() to scan _dm_dir for a match.
*/ */
if (dm_snprintf(buf, sizeof(buf), "%s/%s", _dm_dir, name) == -1) { if (dm_snprintf(buf, sizeof(buf), "%s/%s", _dm_dir, name) == -1) {
log_error("Couldn't create path for %s", name); log_error("Couldn't create path for %s", name);
@ -570,12 +567,37 @@ static int _dm_task_set_name_from_path(struct dm_task *dmt, const char *path,
if (!stat(buf, &st2) && (st1.st_rdev == st2.st_rdev)) if (!stat(buf, &st2) && (st1.st_rdev == st2.st_rdev))
final_name = name; final_name = name;
else if (_find_dm_name_of_device(st1.st_rdev, buf, sizeof(buf))) } else {
/* Not found. */
/* If there is exactly one '/' try a prefix of /dev */
if ((len = strlen(path)) < 3 || path[0] == '/' ||
dm_count_chars(path, len, '/') != 1) {
log_error("Device %s not found", path);
return 0;
}
if (dm_snprintf(buf, sizeof(buf), "%s/../%s", _dm_dir, path) == -1) {
log_error("Couldn't create /dev path for %s", path);
return 0;
}
if (stat(buf, &st1)) {
log_error("Device %s not found", path);
return 0;
}
/* Found */
}
/*
* If we don't have the dm name yet, Call _find_dm_name_of_device() to
* scan _dm_dir for a match.
*/
if (!final_name) {
if (_find_dm_name_of_device(st1.st_rdev, buf, sizeof(buf)))
final_name = buf; final_name = buf;
else { else {
log_error("Device %s not found", name); log_error("Device %s not found", name);
return 0; return 0;
} }
}
/* This is an already existing path - do not mangle! */ /* This is an already existing path - do not mangle! */
return _dm_task_set_name(dmt, final_name, DM_STRING_MANGLING_NONE); return _dm_task_set_name(dmt, final_name, DM_STRING_MANGLING_NONE);