From 05d9a013516f23e27b04b6933705c6ae45f9f5b2 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 1 Dec 2021 13:40:09 -0600
Subject: [PATCH] pvscan: fix filter symlink checks

Fixes commit "pvscan: match device arg to filter symlink"
which failed to account for the fact that filter entries
are not just path names but include "a" or "r", etc.

Conflict: context adaptation in tools/pvscan.c
---
 tools/pvscan.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/pvscan.c b/tools/pvscan.c
index 429b5e676..dcf183a46 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -1138,6 +1138,7 @@ static int _filter_uses_symlinks(struct cmd_context *cmd, int filter_cfg)
 {
 	const struct dm_config_node *cn;
 	const struct dm_config_value *cv;
+	const char *fname;
 
 	if ((cn = find_config_tree_array(cmd, filter_cfg, NULL))) {
         	for (cv = cn->v; cv; cv = cv->next) {
@@ -836,19 +837,22 @@ static int _filter_uses_symlinks(struct cmd_context *cmd, int filter_cfg)
 			if (!cv->v.str)
 				continue;
 
-			if (!strncmp(cv->v.str, "/dev/disk/", 10))
+			fname = cv->v.str;
+
+			if (fname[0] != 'a')
+				continue;
+
+			if (strstr(fname, "/dev/disk/"))
 				return 1;
-			if (!strncmp(cv->v.str, "/dev/mapper/", 12))
+			if (strstr(fname, "/dev/mapper/"))
 				return 1;
-			if (cv->v.str[0] == '/')
-				continue;
 
 			/* In case /dev/disk/by was omitted */
-			if (strstr(cv->v.str, "lvm-pv-uuid"))
+			if (strstr(fname, "lvm-pv-uuid"))
 				return 1;
-			if (strstr(cv->v.str, "dm-uuid"))
+			if (strstr(fname, "dm-uuid"))
 				return 1;
-			if (strstr(cv->v.str, "wwn-"))
+			if (strstr(fname, "wwn-"))
 				return 1;
 		}
 	}
-- 
2.33.0

