mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-30 17:18:21 +03:00
libdm: unlink checks for ENOENT
This commit is contained in:
parent
a763420786
commit
e56e7ed533
@ -247,6 +247,16 @@ static int _control_device_number(uint32_t *major, uint32_t *minor)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _control_unlink(const char *control)
|
||||
{
|
||||
if (unlink(control) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if it exists on returning; 0 if it doesn't; -1 if it's wrong.
|
||||
*/
|
||||
@ -262,10 +272,7 @@ static int _control_exists(const char *control, uint32_t major, uint32_t minor)
|
||||
|
||||
if (!S_ISCHR(buf.st_mode)) {
|
||||
log_verbose("%s: Wrong inode type", control);
|
||||
if (!unlink(control))
|
||||
return 0;
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
return _control_unlink(control);
|
||||
}
|
||||
|
||||
if (major && buf.st_rdev != MKDEV(major, minor)) {
|
||||
@ -273,10 +280,7 @@ static int _control_exists(const char *control, uint32_t major, uint32_t minor)
|
||||
"(%u, %u)", control,
|
||||
MAJOR(buf.st_mode), MINOR(buf.st_mode),
|
||||
major, minor);
|
||||
if (!unlink(control))
|
||||
return 0;
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
return _control_unlink(control);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -1060,9 +1060,8 @@ static int _add_dev_node(const char *dev_name, uint32_t major, uint32_t minor,
|
||||
if (info.st_rdev == dev)
|
||||
return 1;
|
||||
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'",
|
||||
dev_name);
|
||||
if (unlink(path) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", path);
|
||||
return 0;
|
||||
}
|
||||
} else if (_warn_if_op_needed(warn_if_udev_failed))
|
||||
@ -1106,8 +1105,8 @@ static int _rm_dev_node(const char *dev_name, int warn_if_udev_failed)
|
||||
"Falling back to direct node removal.", path);
|
||||
|
||||
/* udev may already have deleted the node. Ignore ENOENT. */
|
||||
if (unlink(path) < 0 && errno != ENOENT) {
|
||||
log_error("Unable to unlink device node for '%s'", dev_name);
|
||||
if (unlink(path) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -246,6 +246,16 @@ static int _control_device_number(uint32_t *major, uint32_t *minor)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _control_unlink(const char *control)
|
||||
{
|
||||
if (unlink(control) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns 1 if it exists on returning; 0 if it doesn't; -1 if it's wrong.
|
||||
*/
|
||||
@ -261,10 +271,7 @@ static int _control_exists(const char *control, uint32_t major, uint32_t minor)
|
||||
|
||||
if (!S_ISCHR(buf.st_mode)) {
|
||||
log_verbose("%s: Wrong inode type", control);
|
||||
if (!unlink(control))
|
||||
return 0;
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
return _control_unlink(control);
|
||||
}
|
||||
|
||||
if (major && buf.st_rdev != MKDEV(major, minor)) {
|
||||
@ -272,10 +279,7 @@ static int _control_exists(const char *control, uint32_t major, uint32_t minor)
|
||||
"(%u, %u)", control,
|
||||
MAJOR(buf.st_mode), MINOR(buf.st_mode),
|
||||
major, minor);
|
||||
if (!unlink(control))
|
||||
return 0;
|
||||
log_sys_error("unlink", control);
|
||||
return -1;
|
||||
return _control_unlink(control);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -1058,9 +1058,8 @@ static int _add_dev_node(const char *dev_name, uint32_t major, uint32_t minor,
|
||||
if (info.st_rdev == dev)
|
||||
return 1;
|
||||
|
||||
if (unlink(path) < 0) {
|
||||
log_error("Unable to unlink device node for '%s'",
|
||||
dev_name);
|
||||
if (unlink(path) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", path);
|
||||
return 0;
|
||||
}
|
||||
} else if (_warn_if_op_needed(warn_if_udev_failed))
|
||||
@ -1104,8 +1103,8 @@ static int _rm_dev_node(const char *dev_name, int warn_if_udev_failed)
|
||||
"Falling back to direct node removal.", path);
|
||||
|
||||
/* udev may already have deleted the node. Ignore ENOENT. */
|
||||
if (unlink(path) < 0 && errno != ENOENT) {
|
||||
log_error("Unable to unlink device node for '%s'", dev_name);
|
||||
if (unlink(path) && (errno != ENOENT)) {
|
||||
log_sys_error("unlink", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user