mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
libdm: improve detection of mounted fs
To detect mounted device, use also /proc/self/mountinfo as so far the check was only able to detect ext4 mounted filesystem. TODO: Once proper testing for this feature is added, it may appear, mountinfo check is enough and covers all cases and sysfs check could be removed.
This commit is contained in:
parent
1f30e5a052
commit
7fab9a9dda
@ -1,5 +1,6 @@
|
||||
Version 1.02.78 -
|
||||
===================================
|
||||
Detecte mounted fs also via reading /proc/self/mountinfo.
|
||||
Add dm_mountinfo_read() for parsing /proc/self/mountinfo.
|
||||
Report error for nonexisting devices in dmeventd communication.
|
||||
Prevent double free error after dmeventd call of _fill_device_data().
|
||||
|
@ -1842,10 +1842,48 @@ static int _mounted_fs_on_device(const char *kernel_dev_name)
|
||||
return r;
|
||||
}
|
||||
|
||||
struct mountinfo_s {
|
||||
unsigned maj;
|
||||
unsigned min;
|
||||
int mounted;
|
||||
};
|
||||
|
||||
static int _device_has_mounted_fs(char *buffer, unsigned major, unsigned minor,
|
||||
char *target, void *cb_data)
|
||||
{
|
||||
struct mountinfo_s *data = cb_data;
|
||||
char kernel_dev_name[PATH_MAX];
|
||||
|
||||
if ((major == data->maj) && (minor == data->min)) {
|
||||
if (!dm_device_get_name(major, minor, 1, kernel_dev_name, PATH_MAX)) {
|
||||
stack;
|
||||
*kernel_dev_name = '\0';
|
||||
}
|
||||
log_verbose("Device %s (%u:%u) appears to be mounted on %s.",
|
||||
kernel_dev_name, major, minor, target);
|
||||
data->mounted = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dm_device_has_mounted_fs(uint32_t major, uint32_t minor)
|
||||
{
|
||||
char kernel_dev_name[PATH_MAX];
|
||||
struct mountinfo_s data = {
|
||||
.maj = major,
|
||||
.min = minor,
|
||||
};
|
||||
|
||||
if (!dm_mountinfo_read(_device_has_mounted_fs, &data))
|
||||
stack;
|
||||
|
||||
if (data.mounted)
|
||||
return 1;
|
||||
/*
|
||||
* TODO: Verify dm_mountinfo_read() is superset
|
||||
* and remove sysfs check (namespaces)
|
||||
*/
|
||||
/* Get kernel device name first */
|
||||
if (!dm_device_get_name(major, minor, 1, kernel_dev_name, PATH_MAX))
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user