mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dev-cache: skip VGID/LVID indexing if /sys/dev/block is not present
/sys/dev/block is available since kernel version 2.2.26 (~ 2008): https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-dev The VGID/LVID indexing code relies on this feature so skip indexing if it's not available to avoid error messages about inability to open /sys/dev/block directory. We're not going to provide fallback code to read the /sys/block/ instead in this case as that's not that efficient - it needs extra reads for getting major:minor and reading partitions would also pose further reads and that's not worth it.
This commit is contained in:
parent
9f28eb4c20
commit
42f04a0f77
@ -818,9 +818,8 @@ static int _dev_cache_iterate_devs_for_index(void)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _dev_cache_iterate_sysfs_for_index(void)
|
static int _dev_cache_iterate_sysfs_for_index(const char *path)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
|
||||||
char devname[PATH_MAX];
|
char devname[PATH_MAX];
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
@ -830,11 +829,6 @@ static int _dev_cache_iterate_sysfs_for_index(void)
|
|||||||
int partial_failure = 0;
|
int partial_failure = 0;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
if (dm_snprintf(path, sizeof(path), "%sdev/block", dm_sysfs_dir()) < 0) {
|
|
||||||
log_error("_dev_cache_iterate_sysfs_for_index: dm_snprintf failed.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(d = opendir(path))) {
|
if (!(d = opendir(path))) {
|
||||||
log_sys_error("opendir", path);
|
log_sys_error("opendir", path);
|
||||||
return 0;
|
return 0;
|
||||||
@ -876,11 +870,36 @@ static int _dev_cache_iterate_sysfs_for_index(void)
|
|||||||
|
|
||||||
int dev_cache_index_devs(void)
|
int dev_cache_index_devs(void)
|
||||||
{
|
{
|
||||||
|
static int sysfs_has_dev_block = -1;
|
||||||
|
char path[PATH_MAX];
|
||||||
|
|
||||||
|
if (dm_snprintf(path, sizeof(path), "%sdev/block", dm_sysfs_dir()) < 0) {
|
||||||
|
log_error("dev_cache_index_devs: dm_snprintf failed.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Skip indexing if /sys/dev/block is not available.*/
|
||||||
|
if (sysfs_has_dev_block == -1) {
|
||||||
|
struct stat info;
|
||||||
|
if (stat(path, &info) == 0)
|
||||||
|
sysfs_has_dev_block = 1;
|
||||||
|
else {
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
sysfs_has_dev_block = 0;
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
log_sys_error("stat", path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!sysfs_has_dev_block)
|
||||||
|
return 1;
|
||||||
|
|
||||||
int with_udev = obtain_device_list_from_udev() &&
|
int with_udev = obtain_device_list_from_udev() &&
|
||||||
udev_get_library_context();
|
udev_get_library_context();
|
||||||
|
|
||||||
return with_udev ? _dev_cache_iterate_devs_for_index()
|
return with_udev ? _dev_cache_iterate_devs_for_index()
|
||||||
: _dev_cache_iterate_sysfs_for_index();
|
: _dev_cache_iterate_sysfs_for_index(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UDEV_SYNC_SUPPORT
|
#ifdef UDEV_SYNC_SUPPORT
|
||||||
|
Loading…
Reference in New Issue
Block a user