1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-07 05:58:00 +03:00

filter: add config setting to skip scanning LVs

devices/scan_lvs (default 1) determines whether lvm
will scan LVs for layered PVs.  The lvm behavior has
always been to scan LVs, but it's rare for LVs to have
layered PVs, and much more common for there to be many
LVs that substantially slow down scanning with no benefit.

This is implemented in the usable filter, and has the
same effect as listing all LVs in the global_filter.
This commit is contained in:
David Teigland 2018-08-29 13:14:18 -05:00
parent a0f6f18841
commit bfcecbbce1
7 changed files with 35 additions and 7 deletions

View File

@ -240,6 +240,7 @@ struct dev_usable_check_params {
unsigned int check_suspended:1;
unsigned int check_error_target:1;
unsigned int check_reserved:1;
unsigned int check_lv:1;
};
/*

View File

@ -648,6 +648,11 @@ int device_is_usable(struct device *dev, struct dev_usable_check_params check)
}
}
if (check.check_lv && uuid && !strncmp(uuid, "LVM-", 4)) {
/* Skip LVs */
goto out;
}
if (check.check_reserved && uuid &&
(!strncmp(uuid, CRYPT_TEMP, sizeof(CRYPT_TEMP) - 1) ||
!strncmp(uuid, STRATIS, sizeof(STRATIS) - 1))) {

View File

@ -1088,7 +1088,7 @@ static struct dev_filter *_init_lvmetad_filter_chain(struct cmd_context *cmd)
nr_filt++;
/* usable device filter. Required. */
if (!(filters[nr_filt] = usable_filter_create(cmd->dev_types, FILTER_MODE_NO_LVMETAD))) {
if (!(filters[nr_filt] = usable_filter_create(cmd, cmd->dev_types, FILTER_MODE_NO_LVMETAD))) {
log_error("Failed to create usabled device filter");
goto bad;
}

View File

@ -337,6 +337,9 @@ cfg(devices_sysfs_scan_CFG, "sysfs_scan", devices_CFG_SECTION, 0, CFG_TYPE_BOOL,
"This is a quick way of filtering out block devices that are not\n"
"present on the system. sysfs must be part of the kernel and mounted.)\n")
cfg(devices_scan_lvs_CFG, "scan_lvs", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_SCAN_LVS, vsn(2, 2, 182), NULL, 0, NULL,
"Scan LVM LVs for layered PVs.\n")
cfg(devices_multipath_component_detection_CFG, "multipath_component_detection", devices_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MULTIPATH_COMPONENT_DETECTION, vsn(2, 2, 89), NULL, 0, NULL,
"Ignore devices that are components of DM multipath devices.\n")

View File

@ -300,4 +300,6 @@
#define DEFAULT_VDO_POOL_AUTOEXTEND_THRESHOLD 100
#define DEFAULT_VDO_POOL_AUTOEXTEND_PERCENT 20
#define DEFAULT_SCAN_LVS 1
#endif /* _LVM_DEFAULTS_H */

View File

@ -21,6 +21,11 @@
#include "lib/device/dev-ext-udev-constants.h"
#endif
struct filter_data {
filter_mode_t mode;
int skip_lvs;
};
static const char *_too_small_to_hold_pv_msg = "Too small to hold a PV";
static int _native_check_pv_min_size(struct device *dev)
@ -102,7 +107,9 @@ static int _check_pv_min_size(struct device *dev)
static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f, struct device *dev)
{
filter_mode_t mode = *((filter_mode_t *) f->private);
struct filter_data *data = f->private;
filter_mode_t mode = data->mode;
int skip_lvs = data->skip_lvs;
struct dev_usable_check_params ucp = {0};
int r = 1;
@ -115,6 +122,7 @@ static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f,
ucp.check_suspended = ignore_suspended_devices();
ucp.check_error_target = 1;
ucp.check_reserved = 1;
ucp.check_lv = skip_lvs;
break;
case FILTER_MODE_PRE_LVMETAD:
ucp.check_empty = 1;
@ -122,6 +130,7 @@ static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f,
ucp.check_suspended = 0;
ucp.check_error_target = 1;
ucp.check_reserved = 1;
ucp.check_lv = skip_lvs;
break;
case FILTER_MODE_POST_LVMETAD:
ucp.check_empty = 0;
@ -129,6 +138,7 @@ static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f,
ucp.check_suspended = ignore_suspended_devices();
ucp.check_error_target = 0;
ucp.check_reserved = 0;
ucp.check_lv = skip_lvs;
break;
}
@ -162,8 +172,9 @@ static void _usable_filter_destroy(struct dev_filter *f)
free(f);
}
struct dev_filter *usable_filter_create(struct dev_types *dt __attribute__((unused)), filter_mode_t mode)
struct dev_filter *usable_filter_create(struct cmd_context *cmd, struct dev_types *dt __attribute__((unused)), filter_mode_t mode)
{
struct filter_data *data;
struct dev_filter *f;
if (!(f = zalloc(sizeof(struct dev_filter)))) {
@ -174,14 +185,20 @@ struct dev_filter *usable_filter_create(struct dev_types *dt __attribute__((unus
f->passes_filter = _passes_usable_filter;
f->destroy = _usable_filter_destroy;
f->use_count = 0;
if (!(f->private = zalloc(sizeof(filter_mode_t)))) {
if (!(data = zalloc(sizeof(struct filter_data)))) {
log_error("Usable device filter mode allocation failed");
free(f);
return NULL;
}
*((filter_mode_t *) f->private) = mode;
log_debug_devs("Usable device filter initialised.");
data->mode = mode;
data->skip_lvs = !find_config_tree_bool(cmd, devices_scan_lvs_CFG, NULL);
f->private = data;
log_debug_devs("Usable device filter initialised (scan_lvs %d).", !data->skip_lvs);
return f;
}

View File

@ -50,6 +50,6 @@ typedef enum {
FILTER_MODE_PRE_LVMETAD,
FILTER_MODE_POST_LVMETAD
} filter_mode_t;
struct dev_filter *usable_filter_create(struct dev_types *dt, filter_mode_t mode);
struct dev_filter *usable_filter_create(struct cmd_context *cmd, struct dev_types *dt, filter_mode_t mode);
#endif /* _LVM_FILTER_H */