master - dmeventd: use new macros to init mempool
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a11cd2ca2d4edb...
Commit: a11cd2ca2d4edbf16c61f8066b1f745fa2fe7d4b
Parent: f9926e7e6c102319575c186e8eef0012cb9c36cc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 11:30:37 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:56:03 2015 +0200
dmeventd: use new macros to init mempool
For thin and snapshot use new macros
to simplify mempool init and destroy
---
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 33 +++++++------------
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 19 +++--------
2 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index 8d5bce1..56fb7c2 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -32,7 +32,7 @@ struct dso_state {
struct dm_pool *mem;
int percent_check;
uint64_t known_size;
- char cmd_str[1024];
+ char cmd_lvextend[512];
};
DM_EVENT_LOG_FN("snap")
@@ -184,11 +184,11 @@ void process_event(struct dm_task *dmt,
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
log_warn("WARNING: Snapshot %s is now %i%% full.", device, percent);
+
/* Try to extend the snapshot, in accord with user-set policies */
- if (!_extend(state->cmd_str))
+ if (!_extend(state->cmd_lvextend))
log_error("Failed to extend snapshot %s.", device);
}
-
out:
if (status)
dm_pool_free(state->mem, status);
@@ -201,22 +201,18 @@ int register_device(const char *device,
int minor __attribute__((unused)),
void **user)
{
- struct dm_pool *statemem = NULL;
struct dso_state *state;
- if (!dmeventd_lvm2_init())
- goto out;
-
- if (!(statemem = dm_pool_create("snapshot_state", 512)) ||
- !(state = dm_pool_zalloc(statemem, sizeof(*state))))
- goto bad;
+ if (dmeventd_lvm2_init_with_pool("snapshot_state", state))
+ goto_bad;
- if (!dmeventd_lvm2_command(statemem, state->cmd_str,
- sizeof(state->cmd_str),
- "lvextend --use-policies", device))
- goto bad;
+ if (!dmeventd_lvm2_command(state->mem, state->cmd_lvextend,
+ sizeof(state->cmd_lvextend),
+ "lvextend --use-policies", device)) {
+ dmeventd_lvm2_exit_with_pool(state);
+ goto_bad;
+ }
- state->mem = statemem;
state->percent_check = CHECK_MINIMUM;
*user = state;
@@ -224,10 +220,6 @@ int register_device(const char *device,
return 1;
bad:
- if (statemem)
- dm_pool_destroy(statemem);
- dmeventd_lvm2_exit();
-out:
log_error("Failed to monitor snapshot %s.", device);
return 0;
@@ -241,9 +233,8 @@ int unregister_device(const char *device,
{
struct dso_state *state = *user;
+ dmeventd_lvm2_exit_with_pool(state);
log_info("No longer monitoring snapshot %s.", device);
- dm_pool_destroy(state->mem);
- dmeventd_lvm2_exit();
return 1;
}
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index d21e65b..15af254 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -351,25 +351,19 @@ int register_device(const char *device,
int minor __attribute__((unused)),
void **user)
{
- struct dm_pool *statemem = NULL;
struct dso_state *state;
- if (!dmeventd_lvm2_init())
- goto bad;
+ if (!dmeventd_lvm2_init_with_pool("thin_pool_state", state))
+ goto_bad;
- if (!(statemem = dm_pool_create("thin_pool_state", 2048)) ||
- !(state = dm_pool_zalloc(statemem, sizeof(*state))) ||
- !dmeventd_lvm2_command(statemem, state->cmd_str,
+ if (!dmeventd_lvm2_command(state->mem, state->cmd_str,
sizeof(state->cmd_str),
"lvextend --use-policies",
device)) {
- if (statemem)
- dm_pool_destroy(statemem);
- dmeventd_lvm2_exit();
- goto bad;
+ dmeventd_lvm2_exit_with_pool(state);
+ goto_bad;
}
- state->mem = statemem;
state->metadata_percent_check = CHECK_MINIMUM;
state->data_percent_check = CHECK_MINIMUM;
*user = state;
@@ -391,9 +385,8 @@ int unregister_device(const char *device,
{
struct dso_state *state = *user;
+ dmeventd_lvm2_exit_with_pool(state);
log_info("No longer monitoring thin %s.", device);
- dm_pool_destroy(state->mem);
- dmeventd_lvm2_exit();
return 1;
}
7 years, 7 months
master - dmeventd: introduce macro for init
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f9926e7e6c1023...
Commit: f9926e7e6c102319575c186e8eef0012cb9c36cc
Parent: 76ea01dd207ce185891418c3f8ffdcff14bf2672
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 12 11:37:36 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:56:03 2015 +0200
dmeventd: introduce macro for init
Simplify commonly used pool creation.
---
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h | 34 +++++++++++++++++++++++++-
1 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h
index 5691c87..d193eda 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2010-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -39,4 +39,36 @@ struct dm_pool *dmeventd_lvm2_pool(void);
int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
const char *cmd, const char *device);
+#define dmeventd_lvm2_run_with_lock(cmdline) \
+ ({\
+ int rc;\
+ dmeventd_lvm2_lock();\
+ rc = dmeventd_lvm2_run(cmdline);\
+ dmeventd_lvm2_unlock();\
+ rc;\
+ })
+
+#define dmeventd_lvm2_init_with_pool(name, st) \
+ ({\
+ struct dm_pool *mem;\
+ st = NULL;\
+ if (dmeventd_lvm2_init()) {\
+ if ((mem = dm_pool_create(name, 2048)) &&\
+ (st = dm_pool_zalloc(mem, sizeof(*st))))\
+ st->mem = mem;\
+ else {\
+ if (mem)\
+ dm_pool_destroy(mem);\
+ dmeventd_lvm2_exit();\
+ }\
+ }\
+ st;\
+ })
+
+#define dmeventd_lvm2_exit_with_pool(pool) \
+ do {\
+ dm_pool_destroy(pool->mem);\
+ dmeventd_lvm2_exit();\
+ } while(0)
+
#endif /* _DMEVENTD_LVMWRAP_H */
7 years, 7 months
master - dmeventd: new initialization of plugin threads
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=76ea01dd207ce1...
Commit: 76ea01dd207ce185891418c3f8ffdcff14bf2672
Parent: 362558cd66bc08f8a46ababef66f2df21e8bd6fc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 09:43:09 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:55:05 2015 +0200
dmeventd: new initialization of plugin threads
Rework thread creation code to better use resources.
New code will not leak 'timeout' registered thread on error path.
Also if the thread already exist - avoid creation of thread
object and it's later destruction.
If the race is noticed during adding new monitoring thread,
such thread is put on cleanup list and -EEXIST is reported.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 170 +++++++++++++++++++++---------------------
2 files changed, 86 insertions(+), 85 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index efe8b37..f041ed1 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Reworked thread initialization for dmeventd plugins.
Dmeventd handles snapshot overflow for now equally as invalid.
Convert dmeventd to use common logging macro system from libdm.
Return -ENOMEM when device registration fails instead of 0 (=success).
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 3e54f79..ba7d01c 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -990,91 +990,6 @@ static int _active(struct message_data *message_data)
}
/*
- * Register for an event.
- *
- * Only one caller at a time here, because we use
- * a FIFO and lock it against multiple accesses.
- */
-static int _register_for_event(struct message_data *message_data)
-{
- int ret = 0;
- struct thread_status *thread, *thread_new = NULL;
- struct dso_data *dso_data;
-
- if (!(dso_data = _lookup_dso(message_data)) &&
- !(dso_data = _load_dso(message_data))) {
- stack;
-#ifdef ELIBACC
- ret = -ELIBACC;
-#else
- ret = -ENODEV;
-#endif
- goto out;
- }
-
- /* Preallocate thread status struct to avoid deadlock. */
- if (!(thread_new = _alloc_thread_status(message_data, dso_data))) {
- stack;
- ret = -ENOMEM;
- goto out;
- }
-
- if (!_fill_device_data(thread_new)) {
- stack;
- ret = -ENODEV;
- goto out;
- }
-
- /* If creation of timeout thread fails (as it may), we fail
- here completely. The client is responsible for either
- retrying later or trying to register without timeout
- events. However, if timeout thread cannot be started, it
- usually means we are so starved on resources that we are
- almost as good as dead already... */
- if ((thread_new->events & DM_EVENT_TIMEOUT) &&
- (ret = -_register_for_timeout(thread_new)))
- goto out;
-
- _lock_mutex();
- if (!(thread = _lookup_thread_status(message_data))) {
- _unlock_mutex();
-
- if (!_do_register_device(thread_new)) {
- ret = -ENOMEM;
- goto_out;
- }
-
- thread = thread_new;
- thread_new = NULL;
-
- /* Try to create the monitoring thread for this device. */
- _lock_mutex();
- if ((ret = -_create_thread(thread))) {
- _unlock_mutex();
- _do_unregister_device(thread);
- _free_thread_status(thread);
- goto out;
- }
-
- LINK_THREAD(thread);
- }
-
- /* Or event # into events bitfield. */
- thread->events |= message_data->events_field;
- _unlock_mutex();
-
- out:
- /*
- * Deallocate thread status after releasing
- * the lock in case we haven't used it.
- */
- if (thread_new)
- _free_thread_status(thread_new);
-
- return ret;
-}
-
-/*
* Unregister for an event.
*
* Only one caller at a time here as with register_for_event().
@@ -1128,6 +1043,91 @@ static int _unregister_for_event(struct message_data *message_data)
}
/*
+ * Register for an event.
+ *
+ * Only one caller at a time here, because we use
+ * a FIFO and lock it against multiple accesses.
+ */
+static int _register_for_event(struct message_data *message_data)
+{
+ int ret = 0;
+ struct thread_status *thread;
+ struct dso_data *dso_data;
+
+ if (!(dso_data = _lookup_dso(message_data)) &&
+ !(dso_data = _load_dso(message_data))) {
+ stack;
+#ifdef ELIBACC
+ ret = -ELIBACC;
+#else
+ ret = -ENODEV;
+#endif
+ return ret;
+ }
+
+ _lock_mutex();
+
+ if ((thread = _lookup_thread_status(message_data)))
+ /* Or event # into events bitfield. */
+ thread->events |= message_data->events_field;
+
+ _unlock_mutex();
+
+ if (!thread) {
+ if (!(thread = _alloc_thread_status(message_data, dso_data))) {
+ stack;
+ return -ENOMEM;
+ }
+
+ if (!_fill_device_data(thread)) {
+ ret = -ENODEV;
+ goto_out;
+ }
+
+ if (!_do_register_device(thread)) {
+ ret = -ENOMEM;
+ goto_out;
+ }
+
+ if ((ret = -_create_thread(thread))) {
+ _do_unregister_device(thread);
+ goto_out;
+ }
+
+ _lock_mutex();
+ if (_lookup_thread_status(message_data)) {
+ DEBUGLOG("Race, uuid already registered, marking Thr %x unused.",
+ (int)thread->thread);
+ thread->status = DM_THREAD_SHUTDOWN;
+ thread->events = 0;
+ LINK(thread, &_thread_registry_unused);
+ _unlock_mutex();
+ ret = -EEXIST; /* race ? */
+ goto_out;
+ }
+
+ LINK_THREAD(thread);
+ _unlock_mutex();
+ }
+
+ /* If creation of timeout thread fails (as it may), we fail
+ here completely. The client is responsible for either
+ retrying later or trying to register without timeout
+ events. However, if timeout thread cannot be started, it
+ usually means we are so starved on resources that we are
+ almost as good as dead already... */
+ if ((thread->events & DM_EVENT_TIMEOUT) &&
+ (ret = -_register_for_timeout(thread)))
+ _unregister_for_event(message_data);
+
+ return ret;
+out:
+ _free_thread_status(thread);
+
+ return ret;
+}
+
+/*
* Get registered device.
*
* Only one caller at a time here as with register_for_event().
7 years, 7 months
master - cleanup: typo in comment
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=362558cd66bc08...
Commit: 362558cd66bc08f8a46ababef66f2df21e8bd6fc
Parent: 09a8479cb70ea2761ebd6988926017aa13fc5f5d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 12 11:37:04 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:58 2015 +0200
cleanup: typo in comment
---
libdm/libdm-targets.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-targets.c b/libdm/libdm-targets.c
index f22ad9c..166396c 100644
--- a/libdm/libdm-targets.c
+++ b/libdm/libdm-targets.c
@@ -82,7 +82,7 @@ int dm_get_status_raid(struct dm_pool *mem, const char *params,
return_0;
if (!(s->raid_type = dm_pool_zalloc(mem, p - params)))
- goto_bad; /* memory is freed went pool is destroyed */
+ goto_bad; /* memory is freed when pool is destroyed */
if (!(s->dev_health = dm_pool_zalloc(mem, i + 1)))
goto_bad;
7 years, 7 months
master - cleanup: move system defines before structs
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=09a8479cb70ea2...
Commit: 09a8479cb70ea2761ebd6988926017aa13fc5f5d
Parent: 0a633750f1e43aa655e5e6e05269aeab8650f55d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 12 11:35:33 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:58 2015 +0200
cleanup: move system defines before structs
---
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index 0801adf..d21e65b 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -19,11 +19,19 @@
#include <sys/wait.h>
#include <stdarg.h>
-/* First warning when thin is 80% full. */
+/* TODO - move this mountinfo code into library to be reusable */
+#ifdef __linux__
+# include "kdev_t.h"
+#else
+# define MAJOR(x) major((x))
+# define MINOR(x) minor((x))
+#endif
+
+/* First warning when thin data or metadata is 80% full. */
#define WARNING_THRESH 80
/* Run a check every 5%. */
#define CHECK_STEP 5
-/* Do not bother checking thins less than 50% full. */
+/* Do not bother checking thin data or metadata is less than 50% full. */
#define CHECK_MINIMUM 50
#define UMOUNT_COMMAND "/bin/umount"
@@ -39,16 +47,6 @@ struct dso_state {
char cmd_str[1024];
};
-
-/* TODO - move this mountinfo code into library to be reusable */
-#ifdef __linux__
-# include "kdev_t.h"
-#else
-# define MAJOR(x) major((x))
-# define MINOR(x) minor((x))
-# define MKDEV(x,y) makedev((x),(y))
-#endif
-
DM_EVENT_LOG_FN("thin")
/* Get dependencies for device, and try to find matching device */
7 years, 7 months
master - cleanup: avoid using private
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0a633750f1e43a...
Commit: 0a633750f1e43aa655e5e6e05269aeab8650f55d
Parent: 0e2261dbd1d489dff158fce88a705a680aaaa3da
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 12 11:40:51 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:58 2015 +0200
cleanup: avoid using private
Switch private to user.
---
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 6 +++---
daemons/dmeventd/plugins/raid/dmeventd_raid.c | 6 +++---
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 12 ++++++------
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 12 ++++++------
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index c010794..d418b08 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -156,7 +156,7 @@ static int _remove_failed_devices(const char *device)
void process_event(struct dm_task *dmt,
enum dm_event_mask event __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
void *next = NULL;
uint64_t start, length;
@@ -215,7 +215,7 @@ int register_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
if (!dmeventd_lvm2_init())
return 0;
@@ -229,7 +229,7 @@ int unregister_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
log_info("No longer monitoring mirror device %s for events.",
device);
diff --git a/daemons/dmeventd/plugins/raid/dmeventd_raid.c b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
index 822d7c4..6522556 100644
--- a/daemons/dmeventd/plugins/raid/dmeventd_raid.c
+++ b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
@@ -116,7 +116,7 @@ static int _process_raid_event(char *params, const char *device)
void process_event(struct dm_task *dmt,
enum dm_event_mask event __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
void *next = NULL;
uint64_t start, length;
@@ -152,7 +152,7 @@ int register_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
if (!dmeventd_lvm2_init())
return 0;
@@ -166,7 +166,7 @@ int unregister_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **unused __attribute__((unused)))
+ void **user)
{
log_info("No longer monitoring RAID device %s for events.",
device);
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index ae8e308..8d5bce1 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -126,8 +126,9 @@ static void _umount(const char *device, int major, int minor)
void process_event(struct dm_task *dmt,
enum dm_event_mask event __attribute__((unused)),
- void **private)
+ void **user)
{
+ struct dso_state *state = *user;
void *next = NULL;
uint64_t start, length;
char *target_type = NULL;
@@ -135,7 +136,6 @@ void process_event(struct dm_task *dmt,
struct dm_status_snapshot *status = NULL;
const char *device = dm_task_get_name(dmt);
int percent;
- struct dso_state *state = *private;
/* No longer monitoring, waiting for remove */
if (!state->percent_check)
@@ -199,7 +199,7 @@ int register_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **private)
+ void **user)
{
struct dm_pool *statemem = NULL;
struct dso_state *state;
@@ -218,7 +218,7 @@ int register_device(const char *device,
state->mem = statemem;
state->percent_check = CHECK_MINIMUM;
- *private = state;
+ *user = state;
log_info("Monitoring snapshot %s.", device);
@@ -237,9 +237,9 @@ int unregister_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **private)
+ void **user)
{
- struct dso_state *state = *private;
+ struct dso_state *state = *user;
log_info("No longer monitoring snapshot %s.", device);
dm_pool_destroy(state->mem);
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index f57eb9b..0801adf 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -251,11 +251,11 @@ out:
void process_event(struct dm_task *dmt,
enum dm_event_mask event __attribute__((unused)),
- void **private)
+ void **user)
{
const char *device = dm_task_get_name(dmt);
int percent;
- struct dso_state *state = *private;
+ struct dso_state *state = *user;
struct dm_status_thin_pool *tps = NULL;
void *next = NULL;
uint64_t start, length;
@@ -351,7 +351,7 @@ int register_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **private)
+ void **user)
{
struct dm_pool *statemem = NULL;
struct dso_state *state;
@@ -374,7 +374,7 @@ int register_device(const char *device,
state->mem = statemem;
state->metadata_percent_check = CHECK_MINIMUM;
state->data_percent_check = CHECK_MINIMUM;
- *private = state;
+ *user = state;
log_info("Monitoring thin %s.", device);
@@ -389,9 +389,9 @@ int unregister_device(const char *device,
const char *uuid __attribute__((unused)),
int major __attribute__((unused)),
int minor __attribute__((unused)),
- void **private)
+ void **user)
{
- struct dso_state *state = *private;
+ struct dso_state *state = *user;
log_info("No longer monitoring thin %s.", device);
dm_pool_destroy(state->mem);
7 years, 7 months
master - cleanup: remove multilog
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0e2261dbd1d489...
Commit: 0e2261dbd1d489dff158fce88a705a680aaaa3da
Parent: 842a7a17e3c0ffc0467ef23a3b59e4e8af2c8d74
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 09:40:39 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:57 2015 +0200
cleanup: remove multilog
---
daemons/dmeventd/dmeventd.c | 6 ------
1 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 7ad30b3..3e54f79 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -2152,11 +2152,6 @@ int main(int argc, char *argv[])
_init_thread_signals();
- //multilog_clear_logging();
- //multilog_add_type(std_syslog, &logdata);
- //multilog_init_verbose(std_syslog, _LOG_DEBUG);
- //multilog_async(1);
-
pthread_mutex_init(&_global_mutex, NULL);
if (!_systemd_activation && !_open_fifos(&fifos))
@@ -2191,7 +2186,6 @@ int main(int argc, char *argv[])
_cleanup_unused_threads();
}
-
pthread_mutex_destroy(&_global_mutex);
log_notice("dmeventd shutting down.");
7 years, 7 months
master - cleanup: always set nsec
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=842a7a17e3c0ff...
Commit: 842a7a17e3c0ffc0467ef23a3b59e4e8af2c8d74
Parent: f4fb97c85082b964397a4e7930d7aa809ffd58f9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 09:39:18 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:57 2015 +0200
cleanup: always set nsec
---
daemons/dmeventd/dmeventd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index e2daef4..7ad30b3 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -568,12 +568,12 @@ static void *_timeout_thread(void *unused __attribute__((unused)))
time_t curr_time;
DEBUGLOG("Timeout thread starting.");
- timeout.tv_nsec = 0;
pthread_cleanup_push(_exit_timeout, NULL);
pthread_mutex_lock(&_timeout_mutex);
while (!dm_list_empty(&_timeout_registry)) {
timeout.tv_sec = 0;
+ timeout.tv_nsec = 0;
curr_time = time(NULL);
dm_list_iterate_items_gen(thread, &_timeout_registry, timeout_list) {
7 years, 7 months
master - cleanup: more readable code
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f4fb97c85082b9...
Commit: f4fb97c85082b964397a4e7930d7aa809ffd58f9
Parent: 8b9533f38f32143e73979542161e62801438922a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 9 21:37:12 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:57 2015 +0200
cleanup: more readable code
---
lib/log/log.c | 5 +----
lib/log/lvm-logging.h | 4 ++--
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/lib/log/log.c b/lib/log/log.c
index 7f31361..2f1be72 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -49,10 +49,7 @@ static size_t _lvm_errmsg_len = 0;
void init_log_fn(lvm2_log_fn_t log_fn)
{
- if (log_fn)
- _lvm2_log_fn = log_fn;
- else
- _lvm2_log_fn = NULL;
+ _lvm2_log_fn = log_fn;
}
/*
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 983da5b..84bf3f4 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -16,9 +16,9 @@
#ifndef _LVM_LOGGING_H
#define _LVM_LOGGING_H
+__attribute__ ((format(printf, 5, 6)))
void print_log(int level, const char *file, int line, int dm_errno_or_class,
- const char *format, ...)
- __attribute__ ((format(printf, 5, 6)));
+ const char *format, ...);
#define LOG_LINE(l, x...) \
print_log(l, __FILE__, __LINE__ , 0, ## x)
7 years, 7 months
master - dmeventd: support logging on stdout
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8b9533f38f3214...
Commit: 8b9533f38f32143e73979542161e62801438922a
Parent: 903e9af1b2c1972a897b7dd61e6e463a03cad648
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 15:14:11 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:22:57 2015 +0200
dmeventd: support logging on stdout
Add new supported option '-l' log to stdout/stderr.
It has to be paired with '-f' (foreground run).
---
daemons/dmeventd/dmeventd.c | 33 ++++++++++++++++++++++++++-------
man/dmeventd.8.in | 7 +++++++
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index f775fb9..e2daef4 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -104,7 +104,8 @@ static pthread_mutex_t _global_mutex;
#define THREAD_STACK_SIZE (300*1024)
-int dmeventd_debug = 0;
+static int _debug_level = 0;
+static int _use_syslog = 1;
static int _systemd_activation = 0;
static int _foreground = 0;
static int _restart = 0;
@@ -2051,10 +2052,11 @@ bad:
static void _usage(char *prog, FILE *file)
{
fprintf(file, "Usage:\n"
- "%s [-d [-d [-d]]] [-f] [-h] [-R] [-V] [-?]\n\n"
+ "%s [-d [-d [-d]]] [-f] [-h] [-l] [-R] [-V] [-?]\n\n"
" -d Log debug messages to syslog (-d, -dd, -ddd)\n"
" -f Don't fork, run in the foreground\n"
" -h Show this help information\n"
+ " -l Log to stdout,stderr instead of syslog\n"
" -? Show this help information on stderr\n"
" -R Restart dmeventd\n"
" -V Show version of dmeventd\n\n", prog);
@@ -2075,7 +2077,7 @@ int main(int argc, char *argv[])
opterr = 0;
optind = 0;
- while ((opt = getopt(argc, argv, "?fhVdR")) != EOF) {
+ while ((opt = getopt(argc, argv, "?fhVdlR")) != EOF) {
switch (opt) {
case 'h':
_usage(argv[0], stdout);
@@ -2090,7 +2092,10 @@ int main(int argc, char *argv[])
_foreground++;
break;
case 'd':
- dmeventd_debug++;
+ _debug_level++;
+ break;
+ case 'l':
+ _use_syslog = 0;
break;
case 'V':
printf("dmeventd version: %s\n", DM_LIB_VERSION);
@@ -2098,6 +2103,10 @@ int main(int argc, char *argv[])
}
}
+ if (!_foreground && !_use_syslog) {
+ printf("WARNING: Ignoring logging to stdout, needs options -f\n");
+ _use_syslog = 1;
+ }
/*
* Switch to C locale to avoid reading large locale-archive file
* used by some glibc (on some distributions it takes over 100MB).
@@ -2116,8 +2125,10 @@ int main(int argc, char *argv[])
if (!_foreground)
_daemonize();
- openlog("dmeventd", LOG_PID, LOG_DAEMON);
+ if (_use_syslog)
+ openlog("dmeventd", LOG_PID, LOG_DAEMON);
+ dm_event_log_set(_debug_level, _use_syslog);
dm_log_init(_dmeventd_log);
(void) dm_prepare_selinux_context(DMEVENTD_PIDFILE, S_IFREG);
@@ -2180,12 +2191,20 @@ int main(int argc, char *argv[])
_cleanup_unused_threads();
}
- _exit_dm_lib();
pthread_mutex_destroy(&_global_mutex);
log_notice("dmeventd shutting down.");
- closelog();
+
+ if (close(fifos.client))
+ log_sys_error("client close", fifos.client_path);
+ if (close(fifos.server))
+ log_sys_error("server close", fifos.server_path);
+
+ if (_use_syslog)
+ closelog();
+
+ _exit_dm_lib();
exit(EXIT_SUCCESS);
}
diff --git a/man/dmeventd.8.in b/man/dmeventd.8.in
index 15e003b..aa62451 100644
--- a/man/dmeventd.8.in
+++ b/man/dmeventd.8.in
@@ -12,6 +12,7 @@ dmeventd \(em Device-mapper event daemon
.RB [ \-d ]]]
.RB [ \-f ]
.RB [ \-h ]
+.RB [ \-l ]
.RB [ \-R ]
.RB [ \-V ]
.RB [ \-? ]
@@ -81,6 +82,12 @@ Don't fork, run in the foreground.
Show help information.
.
.HP
+.BR \-l
+.br
+Log through stdout and stderr instead of syslog.
+This option works only with option \-f, otherwise it is ignored.
+.
+.HP
.BR \-?
.br
Show help information on stderr.
7 years, 7 months