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

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