diff mbox series

[v3,10/12] libmultipath: assume device is in use if dm_get_opencount fails

Message ID 20241126184224.855459-11-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: Benjamin Marzinski
Headers show
Series multipath-tools: Handle tableless DM devices | expand

Commit Message

Benjamin Marzinski Nov. 26, 2024, 6:42 p.m. UTC
If dm_get_opencount() fails, open_count will be negative, which means
mpath_in_use() will never fail. However, dm_flush_map__() will
eventually fail. There are multiple callers of dm_get_opencount() that
run when trying to remove a device. All the others treat a failed call
as if the device was in use, including one that will later be called
directly on this device. So save ourselves the work, and exit early

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/devmapper.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 751b45d8..3667c51b 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -961,6 +961,11 @@  int mpath_in_use(const char *name)
 {
 	int open_count = dm_get_opencount(name);
 
+	if (open_count < 0) {
+		condlog(0, "%s: %s: failed to get open count, assuming in use",
+			__func__, name);
+		return 1;
+	}
 	if (open_count) {
 		int part_count = 0;