From e6c6713a1baeadb485e2200fd7333edd8f78a71c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 16 Oct 2023 14:08:28 -0500 Subject: [PATCH] hints: correct fix for hints with device ids Fixes commit 63b469c1609fe5d3395b7757eebaf35a4a77ea7a "device_id: fix hints with device ids" It's not correct for internal filtering to be a factor in validating the set of devs that are the basis for hints. Instead, look for inconsistencies between a hint entry and the corresponding devices file entry. --- lib/label/hints.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/label/hints.c b/lib/label/hints.c index 1e382198b..d6682617a 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -507,17 +507,6 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints) if (!(hint = _find_hint_name(hints, dev_name(dev)))) continue; - /* - * If this dev is excluded by any filter then hints invalid. - * use cmd->filter->passes_filter(cmd, cmd->filter, dev, "persistent") ? - */ - if (dev->filtered_flags) { - log_debug("Hints invalid for filtered %s: %s", - dev_name(dev), dev_filtered_reason(dev)); - ret = 0; - break; - } - /* The cmd hasn't needed this hint's dev so it's not been scanned. */ if (!hint->chosen) continue; @@ -705,8 +694,9 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * char devpath[PATH_MAX]; FILE *fp; struct dev_iter *iter; + struct dev_use *du; struct hint hint; - struct hint *alloc_hint; + struct hint *alloc_hint, *hp; struct device *dev; char *split[HINT_LINE_WORDS]; char *name, *pvid, *devn, *vgname, *p, *filter_str = NULL; @@ -910,6 +900,32 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * return 1; } + /* + * Check that the dev in each hint is a dev that's matched to a + * devices file entry. + */ + if (cmd->enable_devices_file) { + dm_list_iterate_items(hp, hints) { + if (!(du = get_du_for_devname(cmd, hp->name))) { + log_debug("ignore hints: no devices file entry for %s", hp->name); + *needs_refresh = 1; + return 1; + } + if (!du->dev) { + log_debug("ignore hints: no device matches devices file entry for %s", hp->name); + *needs_refresh = 1; + return 1; + } + if (hp->devt != du->dev->dev) { + log_debug("ignore hints: devno %d:%d does not match %d:%d for %s", + (int)MAJOR(hp->devt), (int)MINOR(hp->devt), + (int)MAJOR(du->dev->dev), (int)MINOR(du->dev->dev), hp->name); + *needs_refresh = 1; + return 1; + } + } + } + log_debug("accept hints found %d", dm_list_size(hints)); return 1; }