Blob Blame History Raw
 daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 2 +-
 tools/lvm2cmd-static.c                       | 7 ++++++-
 tools/lvm2cmd.c                              | 7 ++++++-
 tools/lvm2cmd.h                              | 6 ++++++
 tools/lvm2cmdline.h                          | 4 ++--
 tools/lvmcmdlib.c                            | 4 ++--
 tools/lvmcmdline.c                           | 8 +++++---
 7 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index be58aac..5c52867 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -71,7 +71,7 @@ int dmeventd_lvm2_init(void)
 	if (!_lvm_handle) {
 		lvm2_log_fn(_lvm2_print_log);
 
-		if (!(_lvm_handle = lvm2_init()))
+		if (!(_lvm_handle = lvm2_init_threaded()))
 			goto out;
 
 		/*
diff --git a/tools/lvm2cmd-static.c b/tools/lvm2cmd-static.c
index 4fb109c..31c7515 100644
--- a/tools/lvm2cmd-static.c
+++ b/tools/lvm2cmd-static.c
@@ -17,5 +17,10 @@
 
 void *lvm2_init(void)
 {
-	return cmdlib_lvm2_init(1);
+	return cmdlib_lvm2_init(1, 0);
+}
+
+void *lvm2_init_threaded(void)
+{
+	return cmdlib_lvm2_init(1, 1);
 }
diff --git a/tools/lvm2cmd.c b/tools/lvm2cmd.c
index 235540c..aca3e65 100644
--- a/tools/lvm2cmd.c
+++ b/tools/lvm2cmd.c
@@ -17,7 +17,12 @@
 
 void *lvm2_init(void)
 {
-	return cmdlib_lvm2_init(0);
+	return cmdlib_lvm2_init(0, 0);
+}
+
+void *lvm2_init_threaded(void)
+{
+	return cmdlib_lvm2_init(0, 1);
 }
 
 int lvm_shell(struct cmd_context *cmd __attribute__((unused)),
diff --git a/tools/lvm2cmd.h b/tools/lvm2cmd.h
index cd2e0ec..39a8d60 100644
--- a/tools/lvm2cmd.h
+++ b/tools/lvm2cmd.h
@@ -59,6 +59,12 @@ void lvm2_log_fn(lvm2_log_fn_t log_fn);
 void *lvm2_init(void);
 
 /*
+ * Initialise library for threaded user
+ * Returns a handle so repeated use of lvm2_run is more efficient.
+ */
+void *lvm2_init_threaded(void);
+
+/*
  * Disable any dmeventd calls that the library may otherwise do. Useful to avoid
  * recursive calls from dmeventd to itself.
  */
diff --git a/tools/lvm2cmdline.h b/tools/lvm2cmdline.h
index 0073f90..84cab93 100644
--- a/tools/lvm2cmdline.h
+++ b/tools/lvm2cmdline.h
@@ -28,10 +28,10 @@ struct cmdline_context {
 
 int lvm2_main(int argc, char **argv);
 
-void *cmdlib_lvm2_init(unsigned static_compile);
+void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded);
 void lvm_fin(struct cmd_context *cmd);
 
-struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters);
+struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters, unsigned threaded);
 int lvm_register_commands(struct cmd_context *cmdtool, const char *name);
 int lvm_split(char *str, int *argc, char **argv, int max);
 int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);
diff --git a/tools/lvmcmdlib.c b/tools/lvmcmdlib.c
index 5944576..a2754ea 100644
--- a/tools/lvmcmdlib.c
+++ b/tools/lvmcmdlib.c
@@ -26,12 +26,12 @@
 #include <time.h>
 #include <sys/resource.h>
 
-void *cmdlib_lvm2_init(unsigned static_compile)
+void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded)
 {
 	struct cmd_context *cmd;
 
 	init_is_static(static_compile);
-	if (!(cmd = init_lvm(1, 1)))
+	if (!(cmd = init_lvm(1, 1, threaded)))
 		return NULL;
 
 	if (!lvm_register_commands(cmd, NULL))
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 75a0401..f6814ad 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -3311,7 +3311,9 @@ static int _close_stray_fds(const char *command, struct custom_fds *custom_fds)
 	return 1;
 }
 
-struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
+struct cmd_context *init_lvm(unsigned set_connections,
+			     unsigned set_filters,
+			     unsigned threaded)
 {
 	struct cmd_context *cmd;
 
@@ -3325,7 +3327,7 @@ struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
 	 */
 	dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE);
 
-	if (!(cmd = create_toolcontext(0, NULL, 1, 0,
+	if (!(cmd = create_toolcontext(0, NULL, 1, threaded,
 			set_connections, set_filters))) {
 		udev_fin_library_context();
 		return_NULL;
@@ -3514,7 +3516,7 @@ int lvm2_main(int argc, char **argv)
 	if (!alias && (argc > 2) && !strcmp(argv[2], "-?"))
 		argv[2] = (char *)"-h";
 
-	if (!(cmd = init_lvm(0, 0)))
+	if (!(cmd = init_lvm(0, 0, 0)))
 		return EINIT_FAILED;
 
 	/* Store original argv location so we may customise it if we become a daemon */