diff options
-rw-r--r-- | lib/device/dev-cache.c | 9 | ||||
-rw-r--r-- | lib/device/dev-cache.h | 2 | ||||
-rw-r--r-- | tools/pvscan.c | 15 |
3 files changed, 26 insertions, 0 deletions
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c index 85f9b499a..a8b132d41 100644 --- a/lib/device/dev-cache.c +++ b/lib/device/dev-cache.c @@ -52,6 +52,7 @@ static struct { struct dm_regex *preferred_names_matcher; const char *dev_dir; + int preferred_names_disabled; int has_scanned; long st_dev; struct dm_list dirs; @@ -166,11 +167,19 @@ void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev) if (_cache.preferred_names_matcher) return; + if (_cache.preferred_names_disabled) + return; + log_debug_devs("%s: New preferred name", sl->str); dm_list_del(&sl->list); dm_list_add_h(&dev->aliases, &sl->list); } +void dev_cache_disable_preferred_names(void) +{ + _cache.preferred_names_disabled = 1; +} + /* * Check whether path0 or path1 contains the subpath. The path that * *does not* contain the subpath wins (return 0 or 1). If both paths diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h index 7ffe01152..cee893e6a 100644 --- a/lib/device/dev-cache.h +++ b/lib/device/dev-cache.h @@ -61,6 +61,8 @@ struct device *dev_hash_get(const char *name); void dev_set_preferred_name(struct dm_str_list *sl, struct device *dev); +void dev_cache_disable_preferred_names(void); + /* * Object for iterating through the cache. */ diff --git a/tools/pvscan.c b/tools/pvscan.c index 773862227..670b3d381 100644 --- a/tools/pvscan.c +++ b/tools/pvscan.c @@ -44,6 +44,8 @@ struct pvscan_aa_params { */ static struct volume_group *saved_vg; +static int _found_filter_symlinks; + static int _pvscan_display_pv(struct cmd_context *cmd, struct physical_volume *pv, struct pvscan_params *params) @@ -930,6 +932,7 @@ static int _get_args_devs(struct cmd_context *cmd, struct dm_list *pvscan_args, if (!cmd->enable_devices_file && !cmd->enable_devices_list && (_filter_uses_symlinks(cmd, devices_filter_CFG) || _filter_uses_symlinks(cmd, devices_global_filter_CFG))) { + _found_filter_symlinks = 1; log_print_pvscan(cmd, "finding all devices for filter symlinks."); dev_cache_scan(cmd); } @@ -1550,6 +1553,18 @@ static int _pvscan_cache_args(struct cmd_context *cmd, int argc, char **argv, cmd->filter_nodata_only = 1; + if ((dm_list_size(&pvscan_devs) == 1) && _found_filter_symlinks) { + char *env_str; + struct dm_list *env_aliases; + devl = dm_list_item(dm_list_first(&pvscan_devs), struct device_list); + if ((env_str = getenv("DEVLINKS"))) { + env_aliases = str_to_str_list(cmd->mem, env_str, " ", 0); + dm_list_splice(&devl->dev->aliases, env_aliases); + } + /* A symlink from env may not actually exist so don't try to use it. */ + dev_cache_disable_preferred_names(); + } + dm_list_iterate_items_safe(devl, devl2, &pvscan_devs) { if (!cmd->filter->passes_filter(cmd, cmd->filter, devl->dev, NULL)) { log_print_pvscan(cmd, "%s excluded: %s.", |