Skip to contentSkip to conversation

consistent behavior of filter_property()

PATCH In review [email protected] 2 participants 5 messages Feb 2, 2021 – Feb 3, 2021 Device mapper

lore
Share & tools
lore
#0 lore raw

cover consistent behavior of filter_property()

From: Martin Wilck <[email protected]>

This is a spring-off of the previous discussion under the subject "libmultipath: fix NULL dereference in get_be64".

Repeating part of the text of my last post there:

pp->uid_attribute may be set from the hwtable, which
means that vendor/product must be known, which in turn means that uid_attribute can't be set correctly before sysfs_pathinfo() is run. Thus, in order to be consistent, we need to move the filter_property() further down in pathinfo(), after the call to sysfs_pathinfo().

However, that has a side effect. As Ben already stated, pp->uid_attribute currently is *never* set the first time the call chain pathinfo()->filter_property() is run. After the proposed change, it would *always* be set in this call chain, possibly leading to more cases where pathinfo returns PATHINFO_SKIPPED.

This matters e.g. for "multipath -w". When we remove a WWID, we must be sure get_refwwid() fills in the wwid, which won't happen if PATHINFO_SKIPPED is returned.

(While looking at this, I discovered that it didn't work in current upstream either. I guess it has been broken since 0.6.0, or 355291b ("libmultipath: filter for missing property in get_refwwid()" This lead to the addition of patch 3/3).

In order not to break such use cases, we need to make the filter_property() test in pathinfo() dependent on DI_BLACKLIST. That would make a lot of sense, but it'd cause a semantic change.

Comments welcome.

Regards
Martin

Martin Wilck (3):
pathinfo: call filter_property() after sysfs_pathinfo()
libmultipath: pathinfo: call filter_property only with DI_BLACKLIST multipath -w: allow removing blacklisted paths

 libmultipath/configure.c |  4 +-
 libmultipath/discovery.c | 19 +++++++--
 libmultipath/valid.c     |  4 --
 tests/Makefile           |  2 +-
 tests/test-lib.c         | 18 ++++----
 tests/valid.c            | 91 ++++++++++++++++++++++++++++++++++++----
 6 files changed, 111 insertions(+), 27 deletions(-)
Signature · 7 lines
2.29.2


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 1/3 pathinfo: call filter_property() after sysfs_pathinfo()

From: Martin Wilck <[email protected]>

The of filter_property() depends on the value of pp->uid_attribute. This may in turn depend on pp->hwe, which is initialized in sysfs_pathinfo(). To obtain consistent results from pathinfo(), make sure uid_attribute is correctly set before calling filter_property().

filter_property() is now called from pathinfo() with properly set uid_attribute, thus we don't need to call it from is_path_valid() any more.

Thes changes require modifications to the unit tests. The is_path_valid() test now wouldn't need to test filter_property() any more, because is_path_valid() calls filter_property() no more. But that doesn't feel right. Instead, test_filter_property() is modified to test the behavior with the filter_property() test called indirectly from pathinfo().

---
 libmultipath/discovery.c | 21 +++++++++-
 libmultipath/valid.c     |  4 --
 tests/Makefile           |  2 +-
 tests/test-lib.c         |  5 ++-
 tests/valid.c            | 91 ++++++++++++++++++++++++++++++++++++----
 5 files changed, 105 insertions(+), 18 deletions(-)
libmultipath/discovery.c +19 -2
index 15cf641..febcd0a 100644
@@ -2247,9 +2247,17 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 			condlog(4, "%s: hidden", pp->dev);
 			return PATHINFO_SKIPPED;
 		}
-		if (is_claimed_by_foreign(pp->udev) ||
-		    filter_property(conf, pp->udev, 4, pp->uid_attribute) > 0)
+
+		if (is_claimed_by_foreign(pp->udev))
 			return PATHINFO_SKIPPED;
+
+		/*
+		 * uid_attribute is required for filter_property below,
+		 * and needs access to pp->hwe.
+		 */
+		if (!(mask & DI_SYSFS) && !pp->uid_attribute &&
+		    VECTOR_SIZE(pp->hwe) == 0)
+			mask |= DI_SYSFS;
 	}
 
 	if (strlen(pp->dev) != 0 && filter_devnode(conf->blist_devnode,
@@ -2287,6 +2295,15 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 		}
 	}
 
+	if (pp->udev) {
+		/* uid_attribute is required for filter_property() */
+		if (!pp->uid_attribute)
+			select_getuid(conf, pp);
+
+		if (filter_property(conf, pp->udev, 4, pp->uid_attribute) > 0)
+			return PATHINFO_SKIPPED;
+	}
+
 	if (mask & DI_BLACKLIST && mask & DI_SYSFS) {
 		if (filter_device(conf->blist_device, conf->elist_device,
 				  pp->vendor_id, pp->product_id, pp->dev) > 0 ||
libmultipath/valid.c +0 -4
index 456b1f6..a6aa921 100644
@@ -89,10 +89,6 @@ is_path_valid(const char *name, struct config *conf, struct path *pp,
 	if (pp->wwid[0] == '\0')
 		return PATH_IS_NOT_VALID;
 
-	if (pp->udev && pp->uid_attribute &&
-	    filter_property(conf, pp->udev, 3, pp->uid_attribute) > 0)
-		return PATH_IS_NOT_VALID;
-
 	r = is_failed_wwid(pp->wwid);
 	if (r != WWID_IS_NOT_FAILED) {
 		if (r == WWID_IS_FAILED)
tests/Makefile +1 -1
index 50673fa..11ca1be 100644
@@ -54,7 +54,7 @@ vpd-test_OBJDEPS :=  ../libmultipath/discovery.o
 vpd-test_LIBDEPS := -ludev -lpthread -ldl
 alias-test_TESTDEPS := test-log.o
 alias-test_LIBDEPS := -lpthread -ldl
-valid-test_OBJDEPS := ../libmultipath/valid.o
+valid-test_OBJDEPS := ../libmultipath/valid.o ../libmultipath/discovery.o
 valid-test_LIBDEPS := -ludev -lpthread -ldl
 devt-test_LIBDEPS := -ludev
 mpathvalid-test_LIBDEPS := -ludev -lpthread -ldl
tests/test-lib.c +3 -2
index e7663f9..960a766 100644
@@ -257,6 +257,9 @@ void mock_pathinfo(int mask, const struct mocked_path *mp)
 	} else
 		will_return(__wrap_udev_device_get_sysattr_value, "0");
 
+	if (mask & DI_SYSFS)
+		mock_sysfs_pathinfo(mp);
+
 	/* filter_property */
 	will_return(__wrap_udev_device_get_sysname, mp->devnode);
 	if (mp->flags & BL_BY_PROPERTY) {
@@ -265,8 +268,6 @@ void mock_pathinfo(int mask, const struct mocked_path *mp)
 	} else
 		will_return(__wrap_udev_list_entry_get_name,
 			    "SCSI_IDENT_LUN_NAA_EXT");
-	if (mask & DI_SYSFS)
-		mock_sysfs_pathinfo(mp);
 
 	if (mp->flags & BL_BY_DEVICE &&
 	    (mask & DI_BLACKLIST && mask & DI_SYSFS))
tests/valid.c +82 -9

149 lines not on this page · raw message

Signature · 7 lines
2.29.2


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#2 lore raw

PATCH 2/3 libmultipath: pathinfo: call filter_property only with DI_BLACKLIST

In reply to [email protected]

From: Martin Wilck <[email protected]>

With the previous change to call filter_property() after sysfs_pathinfo(), it can't happen any more that filter_property() is called from pathinfo with uid_attribute not set. This may cause pathinfo() to return failure in some cases where it should actually proceed (e.g. when called from "multipath -m" -> get_refwwid(). Therefore, don't call filter_property() any more unless DI_BLACKLIST is set.

---
 libmultipath/discovery.c | 16 ++++++----------
 tests/test-lib.c         | 17 +++++++++--------
 2 files changed, 15 insertions(+), 18 deletions(-)
libmultipath/discovery.c +6 -10
index febcd0a..9be94cd 100644
@@ -2255,8 +2255,8 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 		 * uid_attribute is required for filter_property below,
 		 * and needs access to pp->hwe.
 		 */
-		if (!(mask & DI_SYSFS) && !pp->uid_attribute &&
-		    VECTOR_SIZE(pp->hwe) == 0)
+		if (!(mask & DI_SYSFS) && (mask & DI_BLACKLIST) &&
+		    !pp->uid_attribute && VECTOR_SIZE(pp->hwe) == 0)
 			mask |= DI_SYSFS;
 	}
 
@@ -2295,17 +2295,13 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 		}
 	}
 
-	if (pp->udev) {
+	if (mask & DI_BLACKLIST && mask & DI_SYSFS) {
 		/* uid_attribute is required for filter_property() */
-		if (!pp->uid_attribute)
+		if (pp->udev && !pp->uid_attribute)
 			select_getuid(conf, pp);
 
-		if (filter_property(conf, pp->udev, 4, pp->uid_attribute) > 0)
-			return PATHINFO_SKIPPED;
-	}
-
-	if (mask & DI_BLACKLIST && mask & DI_SYSFS) {
-		if (filter_device(conf->blist_device, conf->elist_device,
+		if (filter_property(conf, pp->udev, 4, pp->uid_attribute) > 0 ||
+		    filter_device(conf->blist_device, conf->elist_device,
 				  pp->vendor_id, pp->product_id, pp->dev) > 0 ||
 		    filter_protocol(conf->blist_protocol, conf->elist_protocol,
 				    pp) > 0)
tests/test-lib.c +9 -8
index 960a766..f5542ed 100644
@@ -260,14 +260,15 @@ void mock_pathinfo(int mask, const struct mocked_path *mp)
 	if (mask & DI_SYSFS)
 		mock_sysfs_pathinfo(mp);
 
-	/* filter_property */
-	will_return(__wrap_udev_device_get_sysname, mp->devnode);
-	if (mp->flags & BL_BY_PROPERTY) {
-		will_return(__wrap_udev_list_entry_get_name, "BAZ");
-		return;
-	} else
-		will_return(__wrap_udev_list_entry_get_name,
-			    "SCSI_IDENT_LUN_NAA_EXT");
+	if (mask & DI_BLACKLIST) {
+		will_return(__wrap_udev_device_get_sysname, mp->devnode);
+		if (mp->flags & BL_BY_PROPERTY) {
+			will_return(__wrap_udev_list_entry_get_name, "BAZ");
+			return;
+		} else
+			will_return(__wrap_udev_list_entry_get_name,
+				    "SCSI_IDENT_LUN_NAA_EXT");
+	}
 
 	if (mp->flags & BL_BY_DEVICE &&
 	    (mask & DI_BLACKLIST && mask & DI_SYSFS))
Signature · 7 lines
2.29.2


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
#3 lore raw

PATCH 3/3 multipath -w: allow removing blacklisted paths

In reply to [email protected]

From: Martin Wilck <[email protected]>

multipath should allow removing WWIDs of paths even if they are blacklisted.

---
 libmultipath/configure.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/configure.c +2 -2
index 3263bb0..598efe0 100644
@@ -1441,7 +1441,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev,
 				return ret;
 			}
 		}
-		if (pp->udev && pp->uid_attribute &&
+		if (flags & DI_BLACKLIST &&
 		    filter_property(conf, pp->udev, 3, pp->uid_attribute) > 0)
 			return PATHINFO_SKIPPED;
 		refwwid = pp->wwid;
@@ -1466,7 +1466,7 @@ static int _get_refwwid(enum mpath_cmds cmd, const char *dev,
 				refwwid = dev;
 		}
 
-		if (refwwid && strlen(refwwid) &&
+		if (flags & DI_BLACKLIST && refwwid && strlen(refwwid) &&
 		    filter_wwid(conf->blist_wwid, conf->elist_wwid, refwwid,
 				NULL) > 0)
 			return PATHINFO_SKIPPED;
Signature · 7 lines
2.29.2


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on the v1 series
#4 lore raw
In reply to [email protected]
Quoted 28 lines · On Tue, Feb 02, 2021 at 10:27:26PM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

This is a spring-off of the previous discussion under the subject "libmultipath: fix NULL dereference in get_be64".

Repeating part of the text of my last post there:

pp->uid_attribute may be set from the hwtable, which
means that vendor/product must be known, which in turn means that uid_attribute can't be set correctly before sysfs_pathinfo() is run. Thus, in order to be consistent, we need to move the filter_property() further down in pathinfo(), after the call to sysfs_pathinfo().

However, that has a side effect. As Ben already stated, pp->uid_attribute currently is *never* set the first time the call chain pathinfo()->filter_property() is run. After the proposed change, it would *always* be set in this call chain, possibly leading to more cases where pathinfo returns PATHINFO_SKIPPED.

This matters e.g. for "multipath -w". When we remove a WWID, we must be sure get_refwwid() fills in the wwid, which won't happen if PATHINFO_SKIPPED is returned.

(While looking at this, I discovered that it didn't work in current upstream either. I guess it has been broken since 0.6.0, or 355291b ("libmultipath: filter for missing property in get_refwwid()" This lead to the addition of patch 3/3).

Quoted 5 lines

In order not to break such use cases, we need to make the filter_property() test in pathinfo() dependent on DI_BLACKLIST. That would make a lot of sense, but it'd cause a semantic change.

Comments welcome.

For the set.

Quoted 10 lines

Regards
Martin

Martin Wilck (3):
pathinfo: call filter_property() after sysfs_pathinfo()
libmultipath: pathinfo: call filter_property only with DI_BLACKLIST multipath -w: allow removing blacklisted paths

Quoted 10 lines
 libmultipath/configure.c |  4 +-
 libmultipath/discovery.c | 19 +++++++--
 libmultipath/valid.c     |  4 --
 tests/Makefile           |  2 +-
 tests/test-lib.c         | 18 ++++----
 tests/valid.c            | 91 ++++++++++++++++++++++++++++++++++++----
 6 files changed, 111 insertions(+), 27 deletions(-)
Signature · 1 line
2.29.2

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel