Blame SOURCES/0002-libmutipath-don-t-close-fd-on-dm_lib_release.patch

49190a
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
49190a
From: Benjamin Marzinski <bmarzins@redhat.com>
49190a
Date: Sat, 21 Mar 2020 23:49:59 -0500
49190a
Subject: [PATCH] libmutipath: don't close fd on dm_lib_release
49190a
49190a
If dm_hold_control_open() isn't set, when dm_lib_release() is called, it
49190a
will close the control fd. The control fd will get re-opened on the next
49190a
dm_task_run() call, but if there is a dm_task_run() call already
49190a
in progress in another thread, it can fail. Since many of the
49190a
device-mapper callouts happen with the vecs lock held, this wasn't too
49190a
noticeable, but there is code that calls dm_task_run() without the
49190a
vecs lock held, notably the dmevent waiter code.
49190a
49190a
Since, as Martin pointed out, dm_hold_control_open() hasn't always
49190a
existed in libdevmapper, check if it's supported on compilation,
49190a
and update the version requirements if so.
49190a
49190a
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
49190a
---
49190a
 libmultipath/Makefile    | 4 ++++
49190a
 libmultipath/devmapper.c | 7 ++++++-
49190a
 2 files changed, 10 insertions(+), 1 deletion(-)
49190a
49190a
diff --git a/libmultipath/Makefile b/libmultipath/Makefile
49190a
index e5651e49..ad690a49 100644
49190a
--- a/libmultipath/Makefile
49190a
+++ b/libmultipath/Makefile
49190a
@@ -36,6 +36,10 @@ ifneq ($(call check_func,dm_task_deferred_remove,/usr/include/libdevmapper.h),0)
49190a
 	CFLAGS += -DLIBDM_API_DEFERRED
49190a
 endif
49190a
 
49190a
+ifneq ($(call check_func,dm_hold_control_dev,/usr/include/libdevmapper.h),0)
49190a
+	CFLAGS += -DLIBDM_API_HOLD_CONTROL
49190a
+endif
49190a
+
49190a
 OBJS = memory.o parser.o vector.o devmapper.o callout.o \
49190a
 	hwtable.o blacklist.o util.o dmparser.o config.o \
49190a
 	structs.o discovery.o propsel.o dict.o \
49190a
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
49190a
index bed8ddc6..13a1cf53 100644
49190a
--- a/libmultipath/devmapper.c
49190a
+++ b/libmultipath/devmapper.c
49190a
@@ -108,7 +108,9 @@ dm_lib_prereq (void)
49190a
 {
49190a
 	char version[64];
49190a
 	int v[3];
49190a
-#if defined(LIBDM_API_DEFERRED)
49190a
+#if defined(LIBDM_API_HOLD_CONTROL)
49190a
+	int minv[3] = {1, 2, 111};
49190a
+#elif defined(LIBDM_API_DEFERRED)
49190a
 	int minv[3] = {1, 2, 89};
49190a
 #elif defined(DM_SUBSYSTEM_UDEV_FLAG0)
49190a
 	int minv[3] = {1, 2, 82};
49190a
@@ -254,6 +256,9 @@ void libmp_dm_init(void)
49190a
 	memcpy(conf->version, version, sizeof(version));
49190a
 	put_multipath_config(conf);
49190a
 	dm_init(verbosity);
49190a
+#ifdef LIBDM_API_HOLD_CONTROL
49190a
+	dm_hold_control_dev(1);
49190a
+#endif
49190a
 	dm_udev_set_sync_support(libmp_dm_udev_sync);
49190a
 }
49190a
 
49190a
-- 
49190a
2.17.2
49190a