summaryrefslogtreecommitdiffstats
path: root/daemons/dmeventd/plugins/mirror
diff options
context:
space:
mode:
authorAlasdair Kergon <agk@redhat.com>2010-01-21 22:15:45 +0000
committerAlasdair Kergon <agk@redhat.com>2010-01-21 22:15:45 +0000
commitd3d98fdc1e6a8ec1128bf51a522011f5cf2c416b (patch)
tree499b59f87e77b710a83cb8836dd1cd389c8cf9bd /daemons/dmeventd/plugins/mirror
parenta7ca10151795b4c4ed6fa4bf7d3d6b1a687430b0 (diff)
downloadlvm2-d3d98fdc1e6a8ec1128bf51a522011f5cf2c416b.tar.gz
lvm2-d3d98fdc1e6a8ec1128bf51a522011f5cf2c416b.tar.xz
lvm2-d3d98fdc1e6a8ec1128bf51a522011f5cf2c416b.zip
Add libdevmapper-event-lvm2.so to serialise dmeventd plugin liblvm2cmd use.
Diffstat (limited to 'daemons/dmeventd/plugins/mirror')
-rw-r--r--daemons/dmeventd/plugins/mirror/Makefile.in8
-rw-r--r--daemons/dmeventd/plugins/mirror/dmeventd_mirror.c107
2 files changed, 17 insertions, 98 deletions
diff --git a/daemons/dmeventd/plugins/mirror/Makefile.in b/daemons/dmeventd/plugins/mirror/Makefile.in
index 1fcb5c85..2c42e036 100644
--- a/daemons/dmeventd/plugins/mirror/Makefile.in
+++ b/daemons/dmeventd/plugins/mirror/Makefile.in
@@ -1,6 +1,6 @@
#
# Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
-# Copyright (C) 2004-2005, 2008 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2004-2005, 2008-2010 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -17,8 +17,8 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
VPATH = @srcdir@
-INCLUDES += -I${top_srcdir}/tools
-CLDFLAGS += -L${top_builddir}/tools
+INCLUDES += -I${top_srcdir}/tools -I$(top_srcdir)/daemons/dmeventd/plugins/lvm2
+CLDFLAGS += -L${top_builddir}/tools -L${top_builddir}/daemons/dmeventd/plugins/lvm2
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-lvm2
install_lvm2: libdevmapper-event-lvm2mirror.$(LIB_SUFFIX)
$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) $< \
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index d1d9ca62..00e8e1c4 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -12,18 +12,14 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "lib.h"
+
#include "lvm2cmd.h"
#include "errors.h"
+#include "libdevmapper-event.h"
+#include "dmeventd_lvm.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> /* FIXME Replace syslog with multilog */
/* FIXME Missing openlog? */
@@ -34,25 +30,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 +132,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 +142,7 @@ static int _remove_failed_devices(const char *device)
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(dmeventd_lvm2_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 +152,13 @@ static int _remove_failed_devices(const char *device)
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 = dmeventd_lvm2_run(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 +172,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);
- }
+ dmeventd_lvm2_lock();
+
do {
next = dm_get_next_target(dmt, next, &start, &length,
&target_type, &params);
@@ -255,7 +216,7 @@ void process_event(struct dm_task *dmt,
}
} while (next);
- pthread_mutex_unlock(&_event_mutex);
+ dmeventd_lvm2_unlock();
}
int register_device(const char *device,
@@ -264,38 +225,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 dmeventd_lvm2_init();
}
int unregister_device(const char *device,
@@ -304,20 +235,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);
-
+ dmeventd_lvm2_exit();
return 1;
}