1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: dev_node: use lstat instead of stat while removing and renaming nodes

When using udev, the /dev/mapper entries are symlinks - fix the code
to count with this.

This patch also fixes the dmsetup mknodes and vgmknodes to properly
repair /dev/mapper content if it sees dangling symlink in /dev/mapper.
This commit is contained in:
Peter Rajnoha 2015-09-17 13:31:34 +02:00
parent b5022102bb
commit afdae26c71
2 changed files with 17 additions and 5 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.109 - Version 1.02.109 -
====================================== ======================================
Fix /dev/mapper handling to remove dangling entries if symlinks are found.
Make it possible to use blank value as selection for string list report field. Make it possible to use blank value as selection for string list report field.
Version 1.02.108 - 15th September 2015 Version 1.02.108 - 15th September 2015

View File

@ -1038,7 +1038,7 @@ static int _rm_dev_node(const char *dev_name, int warn_if_udev_failed)
if (!_build_dev_path(path, sizeof(path), dev_name)) if (!_build_dev_path(path, sizeof(path), dev_name))
return_0; return_0;
if (stat(path, &info) < 0) if (lstat(path, &info) < 0)
return 1; return 1;
else if (_warn_if_op_needed(warn_if_udev_failed)) else if (_warn_if_op_needed(warn_if_udev_failed))
log_warn("Node %s was not removed by udev. " log_warn("Node %s was not removed by udev. "
@ -1060,20 +1060,31 @@ static int _rename_dev_node(const char *old_name, const char *new_name,
{ {
char oldpath[PATH_MAX]; char oldpath[PATH_MAX];
char newpath[PATH_MAX]; char newpath[PATH_MAX];
struct stat info; struct stat info, info2;
struct stat *info_block_dev;
if (!_build_dev_path(oldpath, sizeof(oldpath), old_name) || if (!_build_dev_path(oldpath, sizeof(oldpath), old_name) ||
!_build_dev_path(newpath, sizeof(newpath), new_name)) !_build_dev_path(newpath, sizeof(newpath), new_name))
return_0; return_0;
if (stat(newpath, &info) == 0) { if (lstat(newpath, &info) == 0) {
if (!S_ISBLK(info.st_mode)) { if (S_ISLNK(info.st_mode)) {
if (stat(newpath, &info2) == 0)
info_block_dev = &info2;
else {
log_sys_error("stat", newpath);
return 0;
}
} else
info_block_dev = &info;
if (!S_ISBLK(info_block_dev->st_mode)) {
log_error("A non-block device file at '%s' " log_error("A non-block device file at '%s' "
"is already present", newpath); "is already present", newpath);
return 0; return 0;
} }
else if (_warn_if_op_needed(warn_if_udev_failed)) { else if (_warn_if_op_needed(warn_if_udev_failed)) {
if (stat(oldpath, &info) < 0 && if (lstat(oldpath, &info) < 0 &&
errno == ENOENT) errno == ENOENT)
/* assume udev already deleted this */ /* assume udev already deleted this */
return 1; return 1;