[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] dmeventd plugins v. LVM mutexing



Hi,

the attached patch should address RHBZ 557104, in the following way:

- a common library for lvm-based dmeventd plugins is added that proxies
  the access to lvm library
- this supersedes the per-plugin mutexing we have been using and which
  breaks as soon as multiple plugins try to use lvm simultaneously

It should not affect backwards compatibility and the change is confined
to dmeventd plugins only.

Not very well tested yet (just basic check that things link and load).

The patch applies on top of the debug patch I have sent previously and
undoes part of it (but it keeps the basic (non-debug) logging, and also
extends it to the snapshot monitoring plugin).

Yours,
   Petr.

Index: daemons/dmeventd/dmeventd.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/dmeventd.c,v
retrieving revision 1.54
diff -u -p -r1.54 dmeventd.c
--- daemons/dmeventd/dmeventd.c	4 Nov 2008 15:07:44 -0000	1.54
+++ daemons/dmeventd/dmeventd.c	20 Jan 2010 17:06:20 -0000
@@ -54,7 +54,7 @@
 
 static volatile sig_atomic_t _exit_now = 0;	/* set to '1' when signal is given to exit */
 static volatile sig_atomic_t _thread_registries_empty = 1;	/* registries are empty initially */
-static int _debug = 0;
+int _dmeventd_debug = 0;
 
 /* List (un)link macros. */
 #define	LINK(x, head)		dm_list_add(head, &(x)->list)
@@ -204,7 +204,7 @@ static void _debuglog(const char *fmt, .
         time_t P;
         va_list ap;
  
-        if (!_debug)
+        if (!_dmeventd_debug)
                 return;
  
         va_start(ap,fmt);
@@ -1679,7 +1679,7 @@ int main(int argc, char *argv[])
 	opterr = 0;
 	optind = 0;
 
-	while ((opt = getopt(argc, argv, "?hVd")) != EOF) {
+	while ((opt = getopt(argc, argv, "?hVdD")) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage(argv[0], stdout);
@@ -1688,7 +1688,10 @@ int main(int argc, char *argv[])
 			usage(argv[0], stderr);
 			exit(0);
 		case 'd':
-			_debug++;
+			_dmeventd_debug = 2;
+			break;
+		case 'D':
+			_dmeventd_debug = 1;
 			break;
 		case 'V':
 			printf("dmeventd version: %s\n", DM_LIB_VERSION);
@@ -1697,7 +1700,7 @@ int main(int argc, char *argv[])
 		}
 	}
 
-	if (!_debug)
+	if (_dmeventd_debug < 2)
 		_daemonize();
 
 	openlog("dmeventd", LOG_PID, LOG_DAEMON);
Index: daemons/dmeventd/plugins/Makefile.in
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/Makefile.in,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile.in
--- daemons/dmeventd/plugins/Makefile.in	2 Oct 2009 19:10:33 -0000	1.4
+++ daemons/dmeventd/plugins/Makefile.in	20 Jan 2010 17:06:20 -0000
@@ -17,7 +17,7 @@ top_srcdir = @top_srcdir@
 top_builddir = @top_builddir@
 VPATH = @srcdir@
 
-SUBDIRS += mirror snapshot
+SUBDIRS += lvm-common mirror snapshot
 
 include ../../../make.tmpl
 
Index: daemons/dmeventd/plugins/lvm-common/.exported_symbols
===================================================================
RCS file: daemons/dmeventd/plugins/lvm-common/.exported_symbols
diff -N daemons/dmeventd/plugins/lvm-common/.exported_symbols
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ daemons/dmeventd/plugins/lvm-common/.exported_symbols	20 Jan 2010 17:06:20 -0000
@@ -0,0 +1,6 @@
+init_lvm
+fini_lvm
+lock_lvm
+unlock_lvm
+lvm_pool
+lvm_handle
Index: daemons/dmeventd/plugins/lvm-common/Makefile.in
===================================================================
RCS file: daemons/dmeventd/plugins/lvm-common/Makefile.in
diff -N daemons/dmeventd/plugins/lvm-common/Makefile.in
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ daemons/dmeventd/plugins/lvm-common/Makefile.in	20 Jan 2010 17:06:20 -0000
@@ -0,0 +1,41 @@
+#
+# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
+# Copyright (C) 2004-2005, 2008 Red Hat, Inc. All rights reserved.
+#
+# This file is part of LVM2.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+VPATH = @srcdir@
+
+INCLUDES += -I${top_srcdir}/tools
+CLDFLAGS += -L${top_builddir}/tools
+
+SOURCES = lvm-common.c
+
+ifeq ("@LIB_SUFFIX@","dylib")
+  LIB_SHARED = libdevmapper-event-lvm2common.dylib
+else
+  LIB_SHARED = libdevmapper-event-lvm2common.so
+endif
+LIB_VERSION = $(LIB_VERSION_LVM)
+
+include $(top_builddir)/make.tmpl
+
+LIBS += -ldevmapper @LIB_PTHREAD@ @LVM2CMD_LIB@
+
+install_lvm2: libdevmapper-event-lvm2common.$(LIB_SUFFIX)
+	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
+		$(libdir)/$<.$(LIB_VERSION)
+	$(LN_S) -f $<.$(LIB_VERSION) $(libdir)/$<
+
+install: install_lvm2
Index: daemons/dmeventd/plugins/lvm-common/lvm-common.c
===================================================================
RCS file: daemons/dmeventd/plugins/lvm-common/lvm-common.c
diff -N daemons/dmeventd/plugins/lvm-common/lvm-common.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ daemons/dmeventd/plugins/lvm-common/lvm-common.c	20 Jan 2010 17:06:20 -0000
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "lvm2cmd.h"
+#include "log.h"
+#include "errors.h"
+
+#include "lvm-common.h"
+
+#include <libdevmapper.h>
+#include <libdevmapper-event.h>
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
+
+#include <syslog.h>
+
+/*
+ * register_device() is called first and performs initialisation.
+ * Only one device may be registered or unregistered at a time.
+ */
+static pthread_mutex_t _register_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/*
+ * Number of active registrations.
+ */
+static int _register_count = 0;
+static struct dm_pool *_mem_pool = NULL;
+static void *_lvm_handle = NULL;
+
+/*
+ * Currently only one event can be processed at a time.
+ */
+static pthread_mutex_t _event_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void _log_fn(int level,
+		    const char *file __attribute((unused)),
+		    int line __attribute((unused)),
+		    int dm_errno __attribute((unused)),
+		    const char *message)
+{
+	switch (level) {
+	    case _LOG_DEBUG:
+	    case _LOG_INFO:
+	    case _LOG_NOTICE:
+		    /* syslog(LOG_DEBUG, "%s", message); */
+		    break;
+	    case _LOG_WARN:
+		    syslog(LOG_WARNING, "%s", message);
+		    break;
+	    case _LOG_ERR:
+		    syslog(LOG_ERR, "%s", message);
+		    break;
+	    default:
+		    syslog(LOG_CRIT, "%s", message);
+	}
+}
+
+void lock_lvm()
+{
+	if (pthread_mutex_trylock(&_event_mutex)) {
+		syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
+		pthread_mutex_lock(&_event_mutex);
+	}
+}
+
+void unlock_lvm()
+{
+	pthread_mutex_unlock(&_event_mutex);
+}
+
+int init_lvm()
+{
+	int r = 0;
+
+	pthread_mutex_lock(&_register_mutex);
+
+	/*
+	 * Need some space for allocations.  1024 should be more
+	 * than enough for what we need (device mapper name splitting)
+	 */
+	if (!_mem_pool && !(_mem_pool = dm_pool_create("mirror_dso", 1024)))
+		goto out;
+
+	if (!_lvm_handle) {
+		lvm2_log_fn(_log_fn);
+		if (!(_lvm_handle = lvm2_init())) {
+			dm_pool_destroy(_mem_pool);
+			_mem_pool = NULL;
+			goto out;
+		}
+		/* FIXME Temporary: move to dmeventd core */
+		lvm2_run(_lvm_handle, "_memlock_inc");
+	}
+
+	_register_count++;
+	r = 1;
+
+out:
+	pthread_mutex_unlock(&_register_mutex);
+	return r;
+}
+
+void fini_lvm()
+{
+	pthread_mutex_lock(&_register_mutex);
+
+	if (!--_register_count) {
+		dm_pool_destroy(_mem_pool);
+		_mem_pool = NULL;
+		lvm2_run(_lvm_handle, "_memlock_dec");
+		lvm2_exit(_lvm_handle);
+		_lvm_handle = NULL;
+	}
+
+	pthread_mutex_unlock(&_register_mutex);
+}
+
+struct dm_pool *lvm_pool(void)
+{
+	return _mem_pool;
+}
+
+void *lvm_handle(void)
+{
+	return _lvm_handle;
+}
Index: daemons/dmeventd/plugins/lvm-common/lvm-common.h
===================================================================
RCS file: daemons/dmeventd/plugins/lvm-common/lvm-common.h
diff -N daemons/dmeventd/plugins/lvm-common/lvm-common.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ daemons/dmeventd/plugins/lvm-common/lvm-common.h	20 Jan 2010 17:06:20 -0000
@@ -0,0 +1,16 @@
+#ifndef DMEVENTD_LVM_COMMON
+#define DMEVENTD_LVM_COMMON
+
+#include "lvm2cmd.h"
+#include <libdevmapper.h>
+#include <libdevmapper-event.h>
+
+void fini_lvm(void);
+int init_lvm(void);
+void unlock_lvm(void);
+void lock_lvm(void);
+
+struct dm_pool *lvm_pool(void);
+void *lvm_handle(void);
+
+#endif
Index: daemons/dmeventd/plugins/mirror/Makefile.in
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/mirror/Makefile.in,v
retrieving revision 1.12
diff -u -p -r1.12 Makefile.in
--- daemons/dmeventd/plugins/mirror/Makefile.in	9 Oct 2009 16:04:54 -0000	1.12
+++ daemons/dmeventd/plugins/mirror/Makefile.in	20 Jan 2010 17:06:20 -0000
@@ -18,7 +18,7 @@ top_builddir = @top_builddir@
 VPATH = @srcdir@
 
 INCLUDES += -I${top_srcdir}/tools
-CLDFLAGS += -L${top_builddir}/tools
+CLDFLAGS += -L${top_builddir}/tools -L../lvm-common
 
 SOURCES = dmeventd_mirror.c
 
@@ -32,7 +32,7 @@ LIB_VERSION = $(LIB_VERSION_LVM)
 
 include $(top_builddir)/make.tmpl
 
-LIBS += -ldevmapper @LIB_PTHREAD@ @LVM2CMD_LIB@
+LIBS += -ldevmapper @LIB_PTHREAD@ @LVM2CMD_LIB@ -ldevmapper-event-lvm2common
 
 install_lvm2: libdevmapper-event-lvm2mirror.$(LIB_SUFFIX)
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
Index: daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c,v
retrieving revision 1.29
diff -u -p -r1.29 dmeventd_mirror.c
--- daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	6 Jan 2010 13:26:21 -0000	1.29
+++ daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	20 Jan 2010 17:06:20 -0000
@@ -13,8 +13,11 @@
  */
 
 #include "lvm2cmd.h"
+#include "log.h"
 #include "errors.h"
 
+#include "../lvm-common/lvm-common.h"
+
 #include <libdevmapper.h>
 #include <libdevmapper-event.h>
 #include <errno.h>
@@ -34,25 +37,6 @@
 #define ME_INSYNC    1
 #define ME_FAILURE   2
 
-/*
- * register_device() is called first and performs initialisation.
- * Only one device may be registered or unregistered at a time.
- */
-static pthread_mutex_t _register_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/*
- * Number of active registrations.
- */
-static int _register_count = 0;
-
-static struct dm_pool *_mem_pool = NULL;
-static void *_lvm_handle = NULL;
-
-/*
- * Currently only one event can be processed at a time.
- */
-static pthread_mutex_t _event_mutex = PTHREAD_MUTEX_INITIALIZER;
-
 static int _process_status_code(const char status_code, const char *dev_name,
 				const char *dev_type, int r)
 {
@@ -155,18 +139,6 @@ out_parse:
 	return ME_IGNORE;
 }
 
-static void _temporary_log_fn(int level,
-			      const char *file __attribute((unused)),
-			      int line __attribute((unused)),
-			      int dm_errno __attribute((unused)),
-			      const char *format)
-{
-	if (!strncmp(format, "WARNING: ", 9) && (level < 5))
-		syslog(LOG_CRIT, "%s", format);
-	else
-		syslog(LOG_DEBUG, "%s", format);
-}
-
 static int _remove_failed_devices(const char *device)
 {
 	int r;
@@ -177,7 +149,7 @@ static int _remove_failed_devices(const 
 	if (strlen(device) > 200)  /* FIXME Use real restriction */
 		return -ENAMETOOLONG;	/* FIXME These return code distinctions are not used so remove them! */
 
-	if (!dm_split_lvm_name(_mem_pool, device, &vg, &lv, &layer)) {
+	if (!dm_split_lvm_name(lvm_pool(), device, &vg, &lv, &layer)) {
 		syslog(LOG_ERR, "Unable to determine VG name from %s",
 		       device);
 		return -ENOMEM;	/* FIXME Replace with generic error return - reason for failure has already got logged */
@@ -187,15 +159,13 @@ static int _remove_failed_devices(const 
 	if (CMD_SIZE <= snprintf(cmd_str, CMD_SIZE, "lvconvert --config devices{ignore_suspended_devices=1} --repair --use-policies %s/%s", vg, lv)) {
 		/* this error should be caught above, but doesn't hurt to check again */
 		syslog(LOG_ERR, "Unable to form LVM command: Device name too long");
-		dm_pool_empty(_mem_pool);  /* FIXME: not safe with multiple threads */
 		return -ENAMETOOLONG; /* FIXME Replace with generic error return - reason for failure has already got logged */
 	}
 
-	r = lvm2_run(_lvm_handle, cmd_str);
+	r = lvm2_run(lvm_handle(), cmd_str);
 
 	syslog(LOG_INFO, "Repair of mirrored LV %s/%s %s.", vg, lv, (r == ECMD_PROCESSED) ? "finished successfully" : "failed");
 
-	dm_pool_empty(_mem_pool);  /* FIXME: not safe with multiple threads */
 	return (r == ECMD_PROCESSED) ? 0 : -1;
 }
 
@@ -209,10 +179,8 @@ void process_event(struct dm_task *dmt,
 	char *params;
 	const char *device = dm_task_get_name(dmt);
 
-	if (pthread_mutex_trylock(&_event_mutex)) {
-		syslog(LOG_NOTICE, "Another thread is handling an event.  Waiting...");
-		pthread_mutex_lock(&_event_mutex);
-	}
+	lock_lvm();
+
 	do {
 		next = dm_get_next_target(dmt, next, &start, &length,
 					  &target_type, &params);
@@ -255,7 +223,7 @@ void process_event(struct dm_task *dmt,
 		}
 	} while (next);
 
-	pthread_mutex_unlock(&_event_mutex);
+	unlock_lvm();
 }
 
 int register_device(const char *device,
@@ -264,38 +232,8 @@ int register_device(const char *device,
 		    int minor __attribute((unused)),
 		    void **unused __attribute((unused)))
 {
-	int r = 0;
-
-	pthread_mutex_lock(&_register_mutex);
-
-	/*
-	 * Need some space for allocations.  1024 should be more
-	 * than enough for what we need (device mapper name splitting)
-	 */
-	if (!_mem_pool && !(_mem_pool = dm_pool_create("mirror_dso", 1024)))
-		goto out;
-
-	if (!_lvm_handle) {
-		lvm2_log_fn(_temporary_log_fn);
-		if (!(_lvm_handle = lvm2_init())) {
-			dm_pool_destroy(_mem_pool);
-			_mem_pool = NULL;
-			goto out;
-		}
-		lvm2_log_level(_lvm_handle, LVM2_LOG_SUPPRESS);
-		/* FIXME Temporary: move to dmeventd core */
-		lvm2_run(_lvm_handle, "_memlock_inc");
-	}
-
-	syslog(LOG_INFO, "Monitoring mirror device %s for events\n", device);
-
-	_register_count++;
-	r = 1;
-
-out:
-	pthread_mutex_unlock(&_register_mutex);
-
-	return r;
+	syslog(LOG_INFO, "Monitoring mirror device %s for events", device);
+	return init_lvm();
 }
 
 int unregister_device(const char *device,
@@ -304,20 +242,8 @@ int unregister_device(const char *device
 		      int minor __attribute((unused)),
 		      void **unused __attribute((unused)))
 {
-	pthread_mutex_lock(&_register_mutex);
-
 	syslog(LOG_INFO, "No longer monitoring mirror device %s for events\n",
 	       device);
-
-	if (!--_register_count) {
-		dm_pool_destroy(_mem_pool);
-		_mem_pool = NULL;
-		lvm2_run(_lvm_handle, "_memlock_dec");
-		lvm2_exit(_lvm_handle);
-		_lvm_handle = NULL;
-	}
-
-	pthread_mutex_unlock(&_register_mutex);
-
+	fini_lvm();
 	return 1;
 }
Index: daemons/dmeventd/plugins/snapshot/Makefile.in
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/snapshot/Makefile.in,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile.in
--- daemons/dmeventd/plugins/snapshot/Makefile.in	9 Oct 2009 16:04:54 -0000	1.8
+++ daemons/dmeventd/plugins/snapshot/Makefile.in	20 Jan 2010 17:06:20 -0000
@@ -18,7 +18,7 @@ top_builddir = @top_builddir@
 VPATH = @srcdir@
 
 INCLUDES += -I${top_srcdir}/tools
-CLDFLAGS += -L${top_builddir}/tools
+CLDFLAGS += -L${top_builddir}/tools -L../lvm-common
 
 SOURCES = dmeventd_snapshot.c
 
@@ -32,7 +32,7 @@ LIB_VERSION = $(LIB_VERSION_LVM)
 
 include $(top_builddir)/make.tmpl
 
-LIBS += -ldevmapper @LIB_PTHREAD@ @LVM2CMD_LIB@
+LIBS += -ldevmapper @LIB_PTHREAD@ @LVM2CMD_LIB@ -ldevmapper-event-lvm2common
 
 install_lvm2: libdevmapper-event-lvm2snapshot.$(LIB_SUFFIX)
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
Index: daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
===================================================================
RCS file: /cvs/lvm2/LVM2/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c,v
retrieving revision 1.4
diff -u -p -r1.4 dmeventd_snapshot.c
--- daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c	17 Sep 2009 10:37:24 -0000	1.4
+++ daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c	20 Jan 2010 17:06:20 -0000
@@ -17,6 +17,8 @@
 #include "lvm2cmd.h"
 #include "lvm-string.h"
 
+#include "../lvm-common/lvm-common.h"
+
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
@@ -33,39 +35,12 @@
 /* Further warnings at 85%, 90% and 95% fullness. */
 #define WARNING_STEP 5
 
-static pthread_mutex_t _register_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/*
- * Number of active registrations.
- */
-static int _register_count = 0;
-
-static struct dm_pool *_mem_pool = NULL;
-static void *_lvm_handle = NULL;
-
 struct snap_status {
 	int invalid;
 	int used;
 	int max;
 };
 
-/*
- * Currently only one event can be processed at a time.
- */
-static pthread_mutex_t _event_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-static void _temporary_log_fn(int level,
-			      const char *file __attribute((unused)),
-			      int line __attribute((unused)),
-			      int dm_errno __attribute((unused)),
-			      const char *format)
-{
-	if (!strncmp(format, "WARNING: ", 9) && (level < 5))
-		syslog(LOG_CRIT, "%s", format);
-	else
-		syslog(LOG_DEBUG, "%s", format);
-}
-
 /* FIXME possibly reconcile this with target_percent when we gain
    access to regular LVM library here. */
 static void _parse_snapshot_params(char *params, struct snap_status *stat)
@@ -116,10 +91,7 @@ void process_event(struct dm_task *dmt,
 	if (!*percent_warning)
 		return;
 
-	if (pthread_mutex_trylock(&_event_mutex)) {
-		syslog(LOG_NOTICE, "Another thread is handling an event.  Waiting...");
-		pthread_mutex_lock(&_event_mutex);
-	}
+	lock_lvm();
 
 	dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
 	if (!target_type)
@@ -143,7 +115,7 @@ void process_event(struct dm_task *dmt,
 		*percent_warning = (percent / WARNING_STEP) * WARNING_STEP + WARNING_STEP;
 	}
 out:
-	pthread_mutex_unlock(&_event_mutex);
+	unlock_lvm();
 }
 
 int register_device(const char *device,
@@ -152,41 +124,12 @@ int register_device(const char *device,
 		    int minor __attribute((unused)),
 		    void **private)
 {
-	int r = 0;
 	int *percent_warning = (int*)private;
 
-	pthread_mutex_lock(&_register_mutex);
-
-	/*
-	 * Need some space for allocations.  1024 should be more
-	 * than enough for what we need (device mapper name splitting)
-	 */
-	if (!_mem_pool && !(_mem_pool = dm_pool_create("snapshot_dso", 1024)))
-		goto out;
-
 	*percent_warning = WARNING_THRESH; /* Print warning if snapshot is full */
 
-	if (!_lvm_handle) {
-		lvm2_log_fn(_temporary_log_fn);
-		if (!(_lvm_handle = lvm2_init())) {
-			dm_pool_destroy(_mem_pool);
-			_mem_pool = NULL;
-			goto out;
-		}
-		lvm2_log_level(_lvm_handle, LVM2_LOG_SUPPRESS);
-		/* FIXME Temporary: move to dmeventd core */
-		lvm2_run(_lvm_handle, "_memlock_inc");
-	}
-
 	syslog(LOG_INFO, "Monitoring snapshot %s\n", device);
-
-	_register_count++;
-	r = 1;
-
-out:
-	pthread_mutex_unlock(&_register_mutex);
-
-	return r;
+	return init_lvm();
 }
 
 int unregister_device(const char *device,
@@ -195,20 +138,8 @@ int unregister_device(const char *device
 		      int minor __attribute((unused)),
 		      void **unused __attribute((unused)))
 {
-	pthread_mutex_lock(&_register_mutex);
-
 	syslog(LOG_INFO, "No longer monitoring snapshot %s\n",
 	       device);
-
-	if (!--_register_count) {
-		dm_pool_destroy(_mem_pool);
-		_mem_pool = NULL;
-		lvm2_run(_lvm_handle, "_memlock_dec");
-		lvm2_exit(_lvm_handle);
-		_lvm_handle = NULL;
-	}
-
-	pthread_mutex_unlock(&_register_mutex);
-
+	fini_lvm();
 	return 1;
 }

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]