master - dmeventd: use dm_hold_control_dev
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=02eb000f5145aa...
Commit: 02eb000f5145aa60578b4591053bff9a797e64cc
Parent: efc76ca33dec99e3b0499ef28fb9236815ad2258
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Oct 21 20:52:29 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:34:27 2015 +0200
dmeventd: use dm_hold_control_dev
Need here to keep control device opened while there is 'any' dso
plugin loaded - otherwise there would a race closing controlfd
inside lvm2 plugin while some other monitoring thread would
tried to execute another WAITEVENT task.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 13 +++++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 2b87e4b..000bddd 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Dmeventd closes control device when no device is monitored.
Thin plugin for dmeventd improved percentage usage.
Snapshot plugin for dmeventd improved percentage usage.
Add dm_hold_control_dev to allow holding of control device open.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 69fe393..885aa9d 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -282,6 +282,13 @@ static void _lib_put(struct dso_data *data)
dlclose(data->dso_handle);
UNLINK_DSO(data);
_free_dso_data(data);
+
+ /* Close control device if there is no plugin in-use */
+ if (dm_list_empty(&_dso_registry)) {
+ DEBUGLOG("Unholding control device.");
+ dm_hold_control_dev(0);
+ dm_lib_release();
+ }
}
}
@@ -344,6 +351,12 @@ static struct dso_data *_load_dso(struct message_data *data)
goto_bad;
}
+ /* Keep control device open until last user closes */
+ if (dm_list_empty(&_dso_registry)) {
+ DEBUGLOG("Holding control device open.");
+ dm_hold_control_dev(1);
+ }
+
/*
* Keep handle to close the library once
* we've got no references to it any more.
8 years, 1 month
master - dmeventd: move dso handling into single code section
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=efc76ca33dec99...
Commit: efc76ca33dec99e3b0499ef28fb9236815ad2258
Parent: 590091a4faa4a4eb66598137576e01e692fb9f8d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 12:22:55 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:33:19 2015 +0200
dmeventd: move dso handling into single code section
Move all DSO related function in front, so they could be easily
referenced from rest of code.
Add proper error paths with logging and error reporting.
Drop mutex locking when releasing DSO - since DSO is always
allocated and released in main 'event' processing thread.
---
daemons/dmeventd/dmeventd.c | 236 ++++++++++++++++++++++---------------------
1 files changed, 122 insertions(+), 114 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 93df32e..69fe393 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -243,29 +243,127 @@ static DM_LIST_INIT(_timeout_registry);
static pthread_mutex_t _timeout_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t _timeout_cond = PTHREAD_COND_INITIALIZER;
-/* Allocate/free the status structure for a monitoring thread. */
-static struct thread_status *_alloc_thread_status(const struct message_data *data,
- struct dso_data *dso_data)
+
+/**********
+ * DSO
+ **********/
+
+/* DSO data allocate/free. */
+static void _free_dso_data(struct dso_data *data)
{
- struct thread_status *ret;
+ dm_free(data->dso_name);
+ dm_free(data);
+}
- if (!(ret = dm_zalloc(sizeof(*ret))))
- return NULL;
+static struct dso_data *_alloc_dso_data(struct message_data *data)
+{
+ struct dso_data *ret = (typeof(ret)) dm_zalloc(sizeof(*ret));
- if (!(ret->device.uuid = dm_strdup(data->device_uuid))) {
+ if (!ret)
+ return_NULL;
+
+ if (!(ret->dso_name = dm_strdup(data->dso_name))) {
dm_free(ret);
- return NULL;
+ return_NULL;
}
- ret->dso_data = dso_data;
- ret->events = data->events_field;
- ret->timeout = data->timeout_secs;
- dm_list_init(&ret->timeout_list);
+ return ret;
+}
+
+/* DSO reference counting. */
+static void _lib_get(struct dso_data *data)
+{
+ data->ref_count++;
+}
+
+static void _lib_put(struct dso_data *data)
+{
+ if (!--data->ref_count) {
+ dlclose(data->dso_handle);
+ UNLINK_DSO(data);
+ _free_dso_data(data);
+ }
+}
+
+/* Find DSO data. */
+static struct dso_data *_lookup_dso(struct message_data *data)
+{
+ struct dso_data *dso_data, *ret = NULL;
+
+ dm_list_iterate_items(dso_data, &_dso_registry)
+ if (!strcmp(data->dso_name, dso_data->dso_name)) {
+ _lib_get(dso_data);
+ ret = dso_data;
+ break;
+ }
+
+ return ret;
+}
+
+/* Lookup DSO symbols we need. */
+static int _lookup_symbol(void *dl, void **symbol, const char *name)
+{
+ if (!(*symbol = dlsym(dl, name)))
+ return_0;
+
+ return 1;
+}
+
+static int _lookup_symbols(void *dl, struct dso_data *data)
+{
+ return _lookup_symbol(dl, (void *) &data->process_event,
+ "process_event") &&
+ _lookup_symbol(dl, (void *) &data->register_device,
+ "register_device") &&
+ _lookup_symbol(dl, (void *) &data->unregister_device,
+ "unregister_device");
+}
+
+/* Load an application specific DSO. */
+static struct dso_data *_load_dso(struct message_data *data)
+{
+ void *dl;
+ struct dso_data *ret;
+ const char *dlerr;
+
+ if (!(dl = dlopen(data->dso_name, RTLD_NOW))) {
+ dlerr = dlerror();
+ goto_bad;
+ }
+
+ if (!(ret = _alloc_dso_data(data))) {
+ dlclose(dl);
+ dlerr = "no memory";
+ goto_bad;
+ }
+
+ if (!(_lookup_symbols(dl, ret))) {
+ _free_dso_data(ret);
+ dlclose(dl);
+ dlerr = "symbols missing";
+ goto_bad;
+ }
+
+ /*
+ * Keep handle to close the library once
+ * we've got no references to it any more.
+ */
+ ret->dso_handle = dl;
+ LINK_DSO(ret);
return ret;
+bad:
+ log_error("dmeventd %s dlopen failed: %s.", data->dso_name, dlerr);
+ data->msg->size = dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s",
+ data->id, data->dso_name, dlerr);
+ return NULL;
}
-static void _lib_put(struct dso_data *data);
+/************
+ * THREAD
+ ************/
+
+/* Allocate/free the thread status structure for a monitoring thread. */
static void _free_thread_status(struct thread_status *thread)
{
_lib_put(thread->dso_data);
@@ -276,19 +374,25 @@ static void _free_thread_status(struct thread_status *thread)
dm_free(thread);
}
-/* Allocate/free DSO data. */
-static struct dso_data *_alloc_dso_data(struct message_data *data)
+/* Allocate/free the status structure for a monitoring thread. */
+static struct thread_status *_alloc_thread_status(const struct message_data *data,
+ struct dso_data *dso_data)
{
- struct dso_data *ret = (typeof(ret)) dm_zalloc(sizeof(*ret));
+ struct thread_status *ret;
- if (!ret)
+ if (!(ret = dm_zalloc(sizeof(*ret))))
return NULL;
- if (!(ret->dso_name = dm_strdup(data->dso_name))) {
+ if (!(ret->device.uuid = dm_strdup(data->device_uuid))) {
dm_free(ret);
return NULL;
}
+ ret->dso_data = dso_data;
+ ret->events = data->events_field;
+ ret->timeout = data->timeout_secs;
+ dm_list_init(&ret->timeout_list);
+
return ret;
}
@@ -331,12 +435,6 @@ static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *
return r;
}
-static void _free_dso_data(struct dso_data *data)
-{
- dm_free(data->dso_name);
- dm_free(data);
-}
-
/*
* Fetch a string off src and duplicate it into *ptr.
* Pay attention to zero-length strings.
@@ -893,96 +991,6 @@ static int _terminate_thread(struct thread_status *thread)
return pthread_kill(thread->thread, SIGALRM);
}
-/* DSO reference counting. Call with _global_mutex locked! */
-static void _lib_get(struct dso_data *data)
-{
- data->ref_count++;
-}
-
-static void _lib_put(struct dso_data *data)
-{
- if (!--data->ref_count) {
- dlclose(data->dso_handle);
- UNLINK_DSO(data);
- _free_dso_data(data);
- }
-}
-
-/* Find DSO data. */
-static struct dso_data *_lookup_dso(struct message_data *data)
-{
- struct dso_data *dso_data, *ret = NULL;
-
- dm_list_iterate_items(dso_data, &_dso_registry)
- if (!strcmp(data->dso_name, dso_data->dso_name)) {
- _lib_get(dso_data);
- ret = dso_data;
- break;
- }
-
- return ret;
-}
-
-/* Lookup DSO symbols we need. */
-static int _lookup_symbol(void *dl, void **symbol, const char *name)
-{
- if ((*symbol = dlsym(dl, name)))
- return 1;
-
- return 0;
-}
-
-static int _lookup_symbols(void *dl, struct dso_data *data)
-{
- return _lookup_symbol(dl, (void *) &data->process_event,
- "process_event") &&
- _lookup_symbol(dl, (void *) &data->register_device,
- "register_device") &&
- _lookup_symbol(dl, (void *) &data->unregister_device,
- "unregister_device");
-}
-
-/* Load an application specific DSO. */
-static struct dso_data *_load_dso(struct message_data *data)
-{
- void *dl;
- struct dso_data *ret;
-
- if (!(dl = dlopen(data->dso_name, RTLD_NOW))) {
- const char *dlerr = dlerror();
- log_error("dmeventd %s dlopen failed: %s.",
- data->dso_name, dlerr);
- data->msg->size =
- dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s",
- data->id, data->dso_name, dlerr);
- return NULL;
- }
-
- if (!(ret = _alloc_dso_data(data))) {
- dlclose(dl);
- return NULL;
- }
-
- if (!(_lookup_symbols(dl, ret))) {
- _free_dso_data(ret);
- dlclose(dl);
- return NULL;
- }
-
- /*
- * Keep handle to close the library once
- * we've got no references to it any more.
- */
- ret->dso_handle = dl;
- _lib_get(ret);
-
- _lock_mutex();
- LINK_DSO(ret);
- _unlock_mutex();
-
- return ret;
-}
-
/* Return success on daemon active check. */
static int _active(struct message_data *message_data)
{
8 years, 1 month
master - dmeventd: using warning level
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=590091a4faa4a4...
Commit: 590091a4faa4a4eb66598137576e01e692fb9f8d
Parent: 9488cbdd0bd3a410ec1e77454c6a18bdfe8612f5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 11:14:12 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:33:19 2015 +0200
dmeventd: using warning level
When dmevend notices problems, but continues to operate normally
change log level to warning.
---
daemons/dmeventd/dmeventd.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index f2c417c..93df32e 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -2155,7 +2155,7 @@ int main(int argc, char *argv[])
#ifdef __linux__
/* Systemd has adjusted oom killer for us already */
if (!_systemd_activation && !_protect_against_oom_killer())
- log_error("Failed to protect against OOM killer.");
+ log_warn("WARNING: Failed to protect against OOM killer.");
#endif
_init_thread_signals();
@@ -2187,8 +2187,8 @@ int main(int argc, char *argv[])
_unlock_mutex();
if (nothreads)
break;
- log_error("There are still devices being monitored.");
- log_error("Refusing to exit.");
+ log_warn("WARNING: There are still devices being monitored.");
+ log_warn("WARNING: Refusing to exit.");
}
_process_request(&fifos);
_cleanup_unused_threads();
8 years, 1 month
master - dmeventd: no registering of 0 event mask
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9488cbdd0bd3a4...
Commit: 9488cbdd0bd3a410ec1e77454c6a18bdfe8612f5
Parent: fa9e41d2e373e7e8017b158f60eb3e77a582f532
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 11:10:57 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:33:19 2015 +0200
dmeventd: no registering of 0 event mask
Whenever user tries to register 0 mask report this as EINVAL.
---
daemons/dmeventd/dmeventd.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 80e6b14..f2c417c 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1472,6 +1472,8 @@ static int _handle_request(struct dm_event_daemon_message *msg,
{
switch (msg->cmd) {
case DM_EVENT_CMD_REGISTER_FOR_EVENT:
+ if (!message_data->events_field)
+ return -EINVAL;
return _register_for_event(message_data);
case DM_EVENT_CMD_UNREGISTER_FOR_EVENT:
return _unregister_for_event(message_data);
8 years, 1 month
master - dmeventd: thin plugin update
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fa9e41d2e373e7...
Commit: fa9e41d2e373e7e8017b158f60eb3e77a582f532
Parent: 6b0bc5b2d9cc2f160b14d34e764bff99cd3c595f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 20 14:19:35 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:33:07 2015 +0200
dmeventd: thin plugin update
Use dm_make_percent for percentage calculation like lvm2 command.
Use a single call for resize.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 86 ++++++++++++------------
2 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index ba22f1e..2b87e4b 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Thin plugin for dmeventd improved percentage usage.
Snapshot plugin for dmeventd improved percentage usage.
Add dm_hold_control_dev to allow holding of control device open.
Add dm_report_compact_given_fields to remove given empty fields from report.
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index 4f08d5b..888cc0c 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -28,11 +28,11 @@
#endif
/* First warning when thin data or metadata is 80% full. */
-#define WARNING_THRESH 80
+#define WARNING_THRESH (DM_PERCENT_1 * 80)
/* Run a check every 5%. */
-#define CHECK_STEP 5
+#define CHECK_STEP (DM_PERCENT_1 * 5)
/* Do not bother checking thin data or metadata is less than 50% full. */
-#define CHECK_MINIMUM 50
+#define CHECK_MINIMUM (DM_PERCENT_1 * 50)
#define UMOUNT_COMMAND "/bin/umount"
@@ -138,14 +138,6 @@ out:
return r;
}
-static int _extend(struct dso_state *state)
-{
-#if THIN_DEBUG
- log_info("dmeventd executes: %s.", state->cmd_str);
-#endif
- return dmeventd_lvm2_run_with_lock(state->cmd_str);
-}
-
static int _run(const char *cmd, ...)
{
va_list ap;
@@ -188,9 +180,9 @@ static int _run(const char *cmd, ...)
}
struct mountinfo_s {
+ const char *device;
struct dm_info info;
dm_bitset_t minors; /* Bitset for active thin pool minors */
- const char *device;
};
static int _umount_device(char *buffer, unsigned major, unsigned minor,
@@ -213,24 +205,24 @@ static int _umount_device(char *buffer, unsigned major, unsigned minor,
* Find all thin pool users and try to umount them.
* TODO: work with read-only thin pool support
*/
-static void _umount(struct dm_task *dmt, const char *device)
+static void _umount(struct dm_task *dmt)
{
/* TODO: Convert to use hash to reduce memory usage */
static const size_t MINORS = (1U << 20); /* 20 bit */
- struct mountinfo_s data = {
- .device = device,
- };
+ struct mountinfo_s data = { NULL };
if (!dm_task_get_info(dmt, &data.info))
return;
+ data.device = dm_task_get_name(dmt);
+
if (!(data.minors = dm_bitset_create(NULL, MINORS))) {
- log_error("Failed to allocate bitset. Not unmounting %s.", device);
+ log_error("Failed to allocate bitset. Not unmounting %s.", data.device);
goto out;
}
if (!_find_all_devs(data.minors, data.info.major, data.info.minor)) {
- log_error("Failed to detect mounted volumes for %s.", device);
+ log_error("Failed to detect mounted volumes for %s.", data.device);
goto out;
}
@@ -244,6 +236,18 @@ out:
dm_bitset_destroy(data.minors);
}
+static void _use_policy(struct dm_task *dmt, struct dso_state *state)
+{
+#if THIN_DEBUG
+ log_info("dmeventd executes: %s.", state->cmd_str);
+#endif
+ if (!dmeventd_lvm2_run_with_lock(state->cmd_str)) {
+ log_error("Failed to extend thin pool %s.",
+ dm_task_get_name(dmt));
+ _umount(dmt);
+ }
+}
+
void process_event(struct dm_task *dmt,
enum dm_event_mask event __attribute__((unused)),
void **user)
@@ -256,12 +260,19 @@ void process_event(struct dm_task *dmt,
uint64_t start, length;
char *target_type = NULL;
char *params;
+ int needs_policy = 0;
#if 0
/* No longer monitoring, waiting for remove */
if (!state->meta_percent_check && !state->data_percent_check)
return;
#endif
+ if (event & DM_EVENT_DEVICE_ERROR) {
+ /* Error -> no need to check and do instant resize */
+ _use_policy(dmt, state);
+ return;
+ }
+
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
if (!target_type || (strcmp(target_type, "thin-pool") != 0)) {
@@ -271,13 +282,13 @@ void process_event(struct dm_task *dmt,
if (!dm_get_status_thin_pool(state->mem, params, &tps)) {
log_error("Failed to parse status.");
- _umount(dmt, device);
+ _umount(dmt);
goto out;
}
#if THIN_DEBUG
- log_debug("%p: Got status " FMTu64 " / " FMTu64 " " FMTu64
- " / " FMTu64 ".", state,
+ log_debug("Thin pool status " FMTu64 "/" FMTu64 " "
+ FMTu64 "/" FMTu64 ".",
tps->used_metadata_blocks, tps->total_metadata_blocks,
tps->used_data_blocks, tps->total_data_blocks);
#endif
@@ -293,7 +304,7 @@ void process_event(struct dm_task *dmt,
state->known_data_size = tps->total_data_blocks;
}
- percent = 100 * tps->used_metadata_blocks / tps->total_metadata_blocks;
+ percent = dm_make_percent(tps->used_metadata_blocks, tps->total_metadata_blocks);
if (percent >= state->metadata_percent_check) {
/*
* Usage has raised more than CHECK_STEP since the last
@@ -303,18 +314,12 @@ void process_event(struct dm_task *dmt,
/* FIXME: extension of metadata needs to be written! */
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- log_warn("WARNING: Thin metadata %s is now %i%% full.",
- device, percent);
- /* Try to extend the metadata, in accord with user-set policies */
- if (!_extend(state)) {
- log_error("Failed to extend thin metadata %s.",
- device);
- _umount(dmt, device);
- }
- /* FIXME: hmm READ-ONLY switch should happen in error path */
+ log_warn("WARNING: Thin pool %s metadata is now %.2f%% full.",
+ device, dm_percent_to_float(percent));
+ needs_policy = 1;
}
- percent = 100 * tps->used_data_blocks / tps->total_data_blocks;
+ percent = dm_make_percent(tps->used_data_blocks, tps->total_data_blocks);
if (percent >= state->data_percent_check) {
/*
* Usage has raised more than CHECK_STEP since
@@ -323,21 +328,16 @@ void process_event(struct dm_task *dmt,
state->data_percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- log_warn("WARNING: Thin %s is now %i%% full.",
- device, percent);
- /* Try to extend the thin data, in accord with user-set policies */
- if (!_extend(state)) {
- log_error("Failed to extend thin %s.", device);
- state->data_percent_check = 0;
- _umount(dmt, device);
- }
- /* FIXME: hmm READ-ONLY switch should happen in error path */
+ log_warn("WARNING: Thin pool %s data is now %.2f%% full.",
+ device, dm_percent_to_float(percent));
+ needs_policy = 1;
}
+
+ if (needs_policy)
+ _use_policy(dmt, state);
out:
if (tps)
dm_pool_free(state->mem, tps);
-
- dmeventd_lvm2_unlock();
}
int register_device(const char *device,
8 years, 1 month
master - dmeventd: snapshot plugin device removal
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b0bc5b2d9cc2f...
Commit: 6b0bc5b2d9cc2f160b14d34e764bff99cd3c595f
Parent: 7ff5b03e5e82b31ed332ee95631cede836224621
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 15:38:24 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:29:53 2015 +0200
dmeventd: snapshot plugin device removal
Add #ifdef-ed code to have ability to even remove unusable device.
For now purely experimental.
---
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 39 ++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index f864bb4..d9bef5c 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -84,6 +84,41 @@ static int _extend(const char *cmd)
return dmeventd_lvm2_run_with_lock(cmd);
}
+#ifdef SNAPSHOT_REMOVE
+/* Remove invalid snapshot from dm-table */
+/* Experimental for now and not used by default */
+static int _remove(const char *uuid)
+{
+ int r = 1;
+ uint32_t cookie = 0;
+ struct dm_task *dmt;
+
+ if (!(dmt = dm_task_create(DM_DEVICE_REMOVE)))
+ return 0;
+
+ if (!dm_task_set_uuid(dmt, uuid)) {
+ r = 0;
+ goto_out;
+ }
+
+ dm_task_retry_remove(dmt);
+
+ if (!dm_task_set_cookie(dmt, &cookie, 0)) {
+ r = 0;
+ goto_out;
+ }
+
+ if (!dm_task_run(dmt)) {
+ r = 0;
+ goto_out;
+ }
+out:
+ dm_task_destroy(dmt);
+
+ return r;
+}
+#endif /* SNAPSHOT_REMOVE */
+
static void _umount(const char *device, int major, int minor)
{
FILE *mounts;
@@ -164,6 +199,10 @@ void process_event(struct dm_task *dmt,
state->percent_check = 0;
if (dm_task_get_info(dmt, &info))
_umount(device, info.major, info.minor);
+#ifdef SNAPSHOT_REMOVE
+ /* Maybe configurable ? */
+ _remove(dm_task_get_uuid(dmt));
+#endif
goto out;
}
8 years, 1 month
master - dmeventd: snapshot plugin updates
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7ff5b03e5e82b3...
Commit: 7ff5b03e5e82b31ed332ee95631cede836224621
Parent: 91350f5c6ad149a565402254688c6bd1700c5bf5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 15:35:55 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:29:50 2015 +0200
dmeventd: snapshot plugin updates
Improve test for invalid snapshot.
Use dm_make_percent() to manipulate with exactly same percentage
as lvm2 command is using.
---
WHATS_NEW_DM | 1 +
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 42 +++++++++----------
2 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 653e32d..ba22f1e 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Snapshot plugin for dmeventd improved percentage usage.
Add dm_hold_control_dev to allow holding of control device open.
Add dm_report_compact_given_fields to remove given empty fields from report.
Use libdm status parsing and local mem raid dmeventd plugin.
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index d5575f3..f864bb4 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -20,17 +20,17 @@
#include <stdarg.h>
/* First warning when snapshot is 80% full. */
-#define WARNING_THRESH 80
+#define WARNING_THRESH (DM_PERCENT_1 * 80)
/* Run a check every 5%. */
-#define CHECK_STEP 5
+#define CHECK_STEP (DM_PERCENT_1 * 5)
/* Do not bother checking snapshots less than 50% full. */
-#define CHECK_MINIMUM 50
+#define CHECK_MINIMUM (DM_PERCENT_1 * 50)
#define UMOUNT_COMMAND "/bin/umount"
struct dso_state {
struct dm_pool *mem;
- int percent_check;
+ dm_percent_t percent_check;
uint64_t known_size;
char cmd_lvextend[512];
};
@@ -137,6 +137,7 @@ void process_event(struct dm_task *dmt,
struct dm_status_snapshot *status = NULL;
const char *device = dm_task_get_name(dmt);
int percent;
+ struct dm_info info;
/* No longer monitoring, waiting for remove */
if (!state->percent_check)
@@ -148,22 +149,9 @@ void process_event(struct dm_task *dmt,
return;
}
- if (!dm_get_status_snapshot(state->mem, params, &status))
+ if (!dm_get_status_snapshot(state->mem, params, &status)) {
+ log_error("Cannot parse snapshot %s state: %s.", device, params);
return;
-
- if (status->invalid || status->overflow) {
- struct dm_info info;
- log_error("Snapshot %s is lost.", device);
- if (dm_task_get_info(dmt, &info)) {
- _umount(device, info.major, info.minor);
- goto_out;
- } /* else; too bad, but this is best-effort thing... */
- }
-
- /* Snapshot size had changed. Clear the threshold. */
- if (state->known_size != status->total_sectors) {
- state->percent_check = CHECK_MINIMUM;
- state->known_size = status->total_sectors;
}
/*
@@ -171,19 +159,29 @@ void process_event(struct dm_task *dmt,
* the status string. Report the full status string to syslog.
*/
if (status->invalid || status->overflow || !status->total_sectors) {
- log_error("Snapshot %s changed state to: %s.", device, params);
+ log_warn("WARNING: Snapshot %s changed state to: %s and should be removed.",
+ device, params);
state->percent_check = 0;
+ if (dm_task_get_info(dmt, &info))
+ _umount(device, info.major, info.minor);
goto out;
}
- percent = (int) (100 * status->used_sectors / status->total_sectors);
+ /* Snapshot size had changed. Clear the threshold. */
+ if (state->known_size != status->total_sectors) {
+ state->percent_check = CHECK_MINIMUM;
+ state->known_size = status->total_sectors;
+ }
+
+ percent = dm_make_percent(status->used_sectors, status->total_sectors);
if (percent >= state->percent_check) {
/* Usage has raised more than CHECK_STEP since the last
time. Run actions. */
state->percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- log_warn("WARNING: Snapshot %s is now %i%% full.", device, percent);
+ log_warn("WARNING: Snapshot %s is now %.2f%% full.",
+ device, dm_percent_to_float(percent));
/* Try to extend the snapshot, in accord with user-set policies */
if (!_extend(state->cmd_lvextend))
8 years, 1 month
master - dmeventd: mirror plugin update
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=91350f5c6ad149...
Commit: 91350f5c6ad149a565402254688c6bd1700c5bf5
Parent: 9c5c9e2355826ad3835f35e494dde9bb8b1e6356
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 17:09:43 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:28:37 2015 +0200
dmeventd: mirror plugin update
Don't use --config - this requires reload of lvm.conf
---
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index 62ad331..e20b249 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -220,8 +220,7 @@ int register_device(const char *device,
}
if (!dmeventd_lvm2_command(state->mem, state->cmd_lvconvert, sizeof(state->cmd_lvconvert),
- "lvconvert --config devices{ignore_suspended_devices=1} "
- "--repair --use-policies", device)) {
+ "lvconvert --repair --use-policies", device)) {
dmeventd_lvm2_exit_with_pool(state);
goto_bad;
}
8 years, 1 month
master - dmeventd: raid plugin reporting
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9c5c9e2355826a...
Commit: 9c5c9e2355826ad3835f35e494dde9bb8b1e6356
Parent: cde12cbe9e4d3cabefc8644846e86b73b6217b6d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 10:38:40 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:28:37 2015 +0200
dmeventd: raid plugin reporting
Fix raid logging introduced with last updating commit.
---
daemons/dmeventd/plugins/raid/dmeventd_raid.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/daemons/dmeventd/plugins/raid/dmeventd_raid.c b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
index f00ffa4..2f200ba 100644
--- a/daemons/dmeventd/plugins/raid/dmeventd_raid.c
+++ b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
@@ -37,14 +37,17 @@ static int _process_raid_event(struct dso_state *state, char *params, const char
return 0;
}
- if ((d = strchr(status->dev_health, 'D')) && !state->failed) {
+ if ((d = strchr(status->dev_health, 'D'))) {
+ if (state->failed)
+ goto out; /* already reported */
+
log_error("Device #%d of %s array, %s, has failed.",
(int)(d - status->dev_health),
status->raid_type, device);
state->failed = 1;
if (!dmeventd_lvm2_run_with_lock(state->cmd_lvscan))
- log_info("Re-scan of RAID device %s failed.", device);
+ log_warn("WARNING: Re-scan of RAID device %s failed.", device);
/* if repair goes OK, report success even if lvscan has failed */
if (!dmeventd_lvm2_run_with_lock(state->cmd_lvconvert)) {
@@ -58,7 +61,7 @@ static int _process_raid_event(struct dso_state *state, char *params, const char
status->raid_type, device,
(status->insync_regions == status->total_regions) ? "now" : "not");
}
-
+out:
dm_pool_free(state->mem, status);
return 1;
8 years, 1 month
master - dmeventd: lvm2 plugin correctly debug
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cde12cbe9e4d3c...
Commit: cde12cbe9e4d3cabefc8644846e86b73b6217b6d
Parent: ab6d16a8a5214ace81b9af346b9c065ec62fb04b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 22 10:38:05 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Oct 22 22:28:37 2015 +0200
dmeventd: lvm2 plugin correctly debug
Fix debug message and report exit when really doing it.
Also add missing '_' to static function.
---
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index 49bfb56..aaf9a49 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -34,8 +34,8 @@ static void *_lvm_handle = NULL;
DM_EVENT_LOG_FN("lvm")
-static void lvm2_print_log(int level, const char *file, int line,
- int dm_errno_or_class, const char *msg)
+static void _lvm2_print_log(int level, const char *file, int line,
+ int dm_errno_or_class, const char *msg)
{
print_log(level, file, line, dm_errno_or_class, "%s", msg);
}
@@ -62,7 +62,7 @@ int dmeventd_lvm2_init(void)
pthread_mutex_lock(&_register_mutex);
if (!_lvm_handle) {
- lvm2_log_fn(lvm2_print_log);
+ lvm2_log_fn(_lvm2_print_log);
if (!(_lvm_handle = lvm2_init()))
goto out;
@@ -103,10 +103,10 @@ void dmeventd_lvm2_exit(void)
log_debug("lvm plugin exiting.");
lvm2_exit(_lvm_handle);
_lvm_handle = NULL;
+ log_debug("lvm plugin exited.");
}
pthread_mutex_unlock(&_register_mutex);
- log_debug("lvm plugin exited.");
}
struct dm_pool *dmeventd_lvm2_pool(void)
8 years, 1 month