master - cleanup: decode dso path just once
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e113df129ebc4c2b4fc...
Commit: e113df129ebc4c2b4fca2a973ac6e06630e1a470
Parent: 6dff5dc653a6f31c2e995beb1c5ca5c58e83515e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Feb 9 23:40:37 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:15:03 2018 +0100
cleanup: decode dso path just once
Build dso plugin name during segtype initialisation and just
use the string during command life-time.
Also slightlt update message verbosity and make it very_verbose
when operation is going to be made and 'verbose' when it's done.
---
lib/activate/activate.c | 6 ++++--
lib/metadata/segtype.h | 1 +
lib/mirror/mirrored.c | 14 ++++++--------
lib/raid/raid.c | 31 ++++++++++++++-----------------
lib/snapshot/snapshot.c | 15 ++++++---------
lib/thin/thin.c | 14 ++++++--------
6 files changed, 37 insertions(+), 44 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index d8e1ccd..b39f314 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1831,7 +1831,7 @@ int target_register_events(struct cmd_context *cmd, const char *dso, const struc
if (!r)
return_0;
- log_very_verbose("%s %s for events", set ? "Monitored" : "Unmonitored", uuid);
+ log_verbose("%s %s for events", set ? "Monitored" : "Unmonitored", uuid);
return 1;
}
@@ -2016,7 +2016,9 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
if (monitored)
log_verbose("%s already monitored.", display_lvname(lv));
else if (seg->segtype->ops->target_monitor_events) {
- log_verbose("Monitoring %s%s", display_lvname(lv), test_mode() ? " [Test mode: skipping this]" : "");
+ log_very_verbose("Monitoring %s with %s.%s", display_lvname(lv),
+ seg->segtype->dso,
+ test_mode() ? " [Test mode: skipping this]" : "");
monitor_fn = seg->segtype->ops->target_monitor_events;
}
} else {
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index fd8646c..3941612 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -217,6 +217,7 @@ struct segment_type {
struct segtype_handler *ops;
const char *name;
+ const char *dso;
void *library; /* lvm_register_segtype() sets this. */
void *private; /* For the segtype handler to use. */
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index 012501e..16a5852 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -480,22 +480,17 @@ static int _mirrored_target_present(struct cmd_context *cmd,
}
# ifdef DMEVENTD
-static const char *_get_mirror_dso_path(struct cmd_context *cmd)
-{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_mirror_library_CFG, NULL));
-}
-
/* FIXME Cache this */
static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
- return target_registered_with_dmeventd(seg->lv->vg->cmd, _get_mirror_dso_path(seg->lv->vg->cmd),
+ return target_registered_with_dmeventd(seg->lv->vg->cmd, seg->segtype->dso,
seg->lv, pending, monitored);
}
/* FIXME This gets run while suspended and performs banned operations. */
static int _target_set_events(struct lv_segment *seg, int evmask, int set)
{
- return target_register_events(seg->lv->vg->cmd, _get_mirror_dso_path(seg->lv->vg->cmd),
+ return target_register_events(seg->lv->vg->cmd, seg->segtype->dso,
seg->lv, evmask, set, 0);
}
@@ -577,7 +572,10 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
#ifdef DEVMAPPER_SUPPORT
# ifdef DMEVENTD
- if (_get_mirror_dso_path(cmd))
+ segtype->dso = get_monitor_dso_path(cmd,
+ find_config_tree_str(cmd, dmeventd_mirror_library_CFG, NULL));
+
+ if (segtype->dso)
segtype->flags |= SEG_MONITORED;
# endif /* DMEVENTD */
#endif
diff --git a/lib/raid/raid.c b/lib/raid/raid.c
index 9b85373..eb75c1b 100644
--- a/lib/raid/raid.c
+++ b/lib/raid/raid.c
@@ -538,26 +538,16 @@ static int _raid_modules_needed(struct dm_pool *mem,
}
# ifdef DMEVENTD
-static const char *_get_raid_dso_path(struct cmd_context *cmd)
-{
- const char *config_str = find_config_tree_str(cmd, dmeventd_raid_library_CFG, NULL);
- return get_monitor_dso_path(cmd, config_str);
-}
-
static int _raid_target_monitored(struct lv_segment *seg, int *pending, int *monitored)
{
- struct cmd_context *cmd = seg->lv->vg->cmd;
- const char *dso_path = _get_raid_dso_path(cmd);
-
- return target_registered_with_dmeventd(cmd, dso_path, seg->lv, pending, monitored);
+ return target_registered_with_dmeventd(seg->lv->vg->cmd, seg->segtype->dso,
+ seg->lv, pending, monitored);
}
static int _raid_set_events(struct lv_segment *seg, int evmask, int set)
{
- struct cmd_context *cmd = seg->lv->vg->cmd;
- const char *dso_path = _get_raid_dso_path(cmd);
-
- return target_register_events(cmd, dso_path, seg->lv, evmask, set, 0);
+ return target_register_events(seg->lv->vg->cmd, seg->segtype->dso,
+ seg->lv, evmask, set, 0);
}
static int _raid_target_monitor_events(struct lv_segment *seg, int events)
@@ -623,6 +613,7 @@ static const struct raid_type {
static struct segment_type *_init_raid_segtype(struct cmd_context *cmd,
const struct raid_type *rt,
+ const char *dso,
uint64_t monitored)
{
struct segment_type *segtype = dm_zalloc(sizeof(*segtype));
@@ -638,8 +629,10 @@ static struct segment_type *_init_raid_segtype(struct cmd_context *cmd,
segtype->flags = SEG_RAID | SEG_ONLY_EXCLUSIVE | rt->extra_flags;
/* Never monitor raid0 or raid0_meta LVs */
- if (!segtype_is_any_raid0(segtype))
+ if (!segtype_is_any_raid0(segtype)) {
+ segtype->dso = dso;
segtype->flags |= monitored;
+ }
segtype->parity_devs = rt->parity;
@@ -657,18 +650,22 @@ int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *segl
#endif
{
struct segment_type *segtype;
+ const char *dso;
unsigned i;
uint64_t monitored = 0;
#ifdef DEVMAPPER_SUPPORT
# ifdef DMEVENTD
- if (_get_raid_dso_path(cmd))
+ dso = get_monitor_dso_path(cmd,
+ find_config_tree_str(cmd, dmeventd_raid_library_CFG, NULL));
+
+ if (dso)
monitored = SEG_MONITORED;
# endif
#endif
for (i = 0; i < DM_ARRAY_SIZE(_raid_types); ++i)
- if ((segtype = _init_raid_segtype(cmd, &_raid_types[i], monitored)) &&
+ if ((segtype = _init_raid_segtype(cmd, &_raid_types[i], dso, monitored)) &&
!lvm_register_segtype(seglib, segtype))
/* segtype is already destroyed */
return_0;
diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c
index 68e01f5..e44a49a 100644
--- a/lib/snapshot/snapshot.c
+++ b/lib/snapshot/snapshot.c
@@ -179,17 +179,11 @@ static int _snap_target_present(struct cmd_context *cmd,
}
# ifdef DMEVENTD
-
-static const char *_get_snapshot_dso_path(struct cmd_context *cmd)
-{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_snapshot_library_CFG, NULL));
-}
-
/* FIXME Cache this */
static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
return target_registered_with_dmeventd(seg->lv->vg->cmd,
- _get_snapshot_dso_path(seg->lv->vg->cmd),
+ seg->segtype->dso,
seg->cow, pending, monitored);
}
@@ -197,7 +191,7 @@ static int _target_registered(struct lv_segment *seg, int *pending, int *monitor
static int _target_set_events(struct lv_segment *seg, int evmask, int set)
{
/* FIXME Make timeout (10) configurable */
- return target_register_events(seg->lv->vg->cmd, _get_snapshot_dso_path(seg->lv->vg->cmd),
+ return target_register_events(seg->lv->vg->cmd, seg->segtype->dso,
seg->cow, evmask, set, 10);
}
@@ -269,7 +263,10 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
#ifdef DEVMAPPER_SUPPORT
# ifdef DMEVENTD
- if (_get_snapshot_dso_path(cmd))
+ segtype->dso = get_monitor_dso_path(cmd,
+ find_config_tree_str(cmd, dmeventd_snapshot_library_CFG, NULL));
+
+ if (segtype->dso)
segtype->flags |= SEG_MONITORED;
# endif /* DMEVENTD */
#endif
diff --git a/lib/thin/thin.c b/lib/thin/thin.c
index 9cb1ee0..06854ed 100644
--- a/lib/thin/thin.c
+++ b/lib/thin/thin.c
@@ -431,16 +431,11 @@ static int _thin_pool_target_percent(void **target_state __attribute__((unused))
}
# ifdef DMEVENTD
-static const char *_get_thin_dso_path(struct cmd_context *cmd)
-{
- return get_monitor_dso_path(cmd, find_config_tree_str(cmd, dmeventd_thin_library_CFG, NULL));
-}
-
/* FIXME Cache this */
static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
return target_registered_with_dmeventd(seg->lv->vg->cmd,
- _get_thin_dso_path(seg->lv->vg->cmd),
+ seg->segtype->dso,
seg->lv, pending, monitored);
}
@@ -449,7 +444,7 @@ static int _target_set_events(struct lv_segment *seg, int evmask, int set)
{
/* FIXME Make timeout (10) configurable */
return target_register_events(seg->lv->vg->cmd,
- _get_thin_dso_path(seg->lv->vg->cmd),
+ seg->segtype->dso,
seg->lv, evmask, set, 10);
}
@@ -821,8 +816,11 @@ int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *segl
#ifdef DEVMAPPER_SUPPORT
# ifdef DMEVENTD
+ segtype->dso = get_monitor_dso_path(cmd,
+ find_config_tree_str(cmd, dmeventd_thin_library_CFG, NULL));
+
if ((reg_segtypes[i].flags & SEG_THIN_POOL) &&
- _get_thin_dso_path(cmd))
+ segtype->dso)
segtype->flags |= SEG_MONITORED;
# endif /* DMEVENTD */
#endif
6 years, 2 months
master - activation: cleanup error to warning
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6dff5dc653a6f31c2e9...
Commit: 6dff5dc653a6f31c2e995beb1c5ca5c58e83515e
Parent: d90a6478026dc2810947d552d6165ec7f0534894
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 12 16:15:35 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:15:03 2018 +0100
activation: cleanup error to warning
Since for the code it's not fatal to fail on monitoring,
issue correct warning message instead of error.
---
lib/activate/activate.c | 17 +++++++----------
1 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 6a4bc32..d8e1ccd 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1955,9 +1955,7 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
continue;
if (!monitor_dev_for_events(cmd, seg_lv(seg, s), NULL,
monitor)) {
- log_error("Failed to %smonitor %s",
- monitor ? "" : "un",
- display_lvname(seg_lv(seg, s)));
+ stack;
r = 0;
}
}
@@ -2040,16 +2038,15 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
if (new_unmonitor) {
if (!target_register_events(cmd, dso, seg_is_snapshot(seg) ? seg->cow : lv, 0, 0, 10)) {
- log_error("%s: segment unmonitoring failed.",
- display_lvname(lv));
-
+ log_warn("WARNING: %s: segment unmonitoring failed.",
+ display_lvname(lv));
return 0;
}
} else if (monitor_fn) {
/* FIXME specify events */
if (!monitor_fn(seg, 0)) {
- log_error("%s: %s segment monitoring function failed.",
- display_lvname(lv), lvseg_name(seg));
+ log_warn("WARNING: %s: %s segment monitoring function failed.",
+ display_lvname(lv), lvseg_name(seg));
return 0;
}
} else
@@ -2076,8 +2073,8 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
}
if (!r && !error_message_produced())
- log_error("%sonitoring %s failed.", monitor ? "M" : "Not m",
- display_lvname(lv));
+ log_warn("WARNING: %sonitoring %s failed.", monitor ? "M" : "Not m",
+ display_lvname(lv));
return r;
#else
return 1;
6 years, 2 months
master - activation: separate reporting of error and monitoring status
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d90a6478026dc281094...
Commit: d90a6478026dc2810947d552d6165ec7f0534894
Parent: 12fba201be314dd16ea01fc756e39c04c8ba50c3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jan 29 16:28:57 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:14:59 2018 +0100
activation: separate reporting of error and monitoring status
Avoid using same return code for reporting 2 different things
and stricly report error code by return value and add new
parameter for reporting monitoring status.
This makes easier to recognize which error we got from dm_event
and continue only with ENOENT.
---
WHATS_NEW | 1 +
daemons/dmeventd/libdevmapper-event.c | 7 +--
lib/activate/activate.c | 84 ++++++++++++++++++++++++--------
lib/activate/activate.h | 2 +-
lib/metadata/lv.c | 14 +++--
lib/metadata/segtype.h | 2 +-
lib/mirror/mirrored.c | 4 +-
lib/raid/raid.c | 4 +-
lib/snapshot/snapshot.c | 7 ++-
lib/thin/thin.c | 4 +-
10 files changed, 87 insertions(+), 42 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 1ffa3db..2bded4d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.178 -
=====================================
+ Separate reporting of monitoring status and error status.
Improve validation of created strings in vgimportclone.
Add missing initialisation of mem pool in systemd generator.
Do not reopen output streams for multithreaded users of liblvm.
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 210e384..9aeb4c5 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -754,11 +754,10 @@ int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next)
uuid = dm_task_get_uuid(dmt);
/* FIXME Distinguish errors connecting to daemon */
- if (_do_event(next ? DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE :
- DM_EVENT_CMD_GET_REGISTERED_DEVICE, dmevh->dmeventd_path,
- &msg, dmevh->dso, uuid, dmevh->mask, 0)) {
+ if ((ret = _do_event(next ? DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE :
+ DM_EVENT_CMD_GET_REGISTERED_DEVICE, dmevh->dmeventd_path,
+ &msg, dmevh->dso, uuid, dmevh->mask, 0))) {
log_debug("%s: device not registered.", dm_task_get_name(dmt));
- ret = -ENOENT;
goto fail;
}
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 58e6873..6a4bc32 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1681,6 +1681,7 @@ static struct dm_event_handler *_create_dm_event_handler(struct cmd_context *cmd
bad:
dm_event_handler_destroy(dmevh);
+
return NULL;
}
@@ -1712,13 +1713,18 @@ static char *_build_target_uuid(struct cmd_context *cmd, const struct logical_vo
return build_dm_uuid(cmd->mem, lv, layer);
}
-static int _device_registered_with_dmeventd(struct cmd_context *cmd, const struct logical_volume *lv, int *pending, const char **dso)
+static int _device_registered_with_dmeventd(struct cmd_context *cmd,
+ const struct logical_volume *lv,
+ const char **dso,
+ int *pending, int *monitored)
{
char *uuid;
- enum dm_event_mask evmask = 0;
+ enum dm_event_mask evmask;
struct dm_event_handler *dmevh;
+ int r;
*pending = 0;
+ *monitored = 0;
if (!(uuid = _build_target_uuid(cmd, lv)))
return_0;
@@ -1726,9 +1732,20 @@ static int _device_registered_with_dmeventd(struct cmd_context *cmd, const struc
if (!(dmevh = _create_dm_event_handler(cmd, uuid, NULL, 0, DM_EVENT_ALL_ERRORS)))
return_0;
- if (dm_event_get_registered_device(dmevh, 0)) {
- dm_event_handler_destroy(dmevh);
- return 0;
+ if ((r = dm_event_get_registered_device(dmevh, 0))) {
+ if (r == -ENOENT) {
+ r = 1;
+ goto out;
+ }
+ r = 0;
+ goto_out;
+ }
+
+ /* FIXME: why do we care which 'dso' is monitoring? */
+ if (dso && (*dso = dm_event_handler_get_dso(dmevh)) &&
+ !(*dso = dm_pool_strdup(cmd->mem, *dso))) {
+ r = 0;
+ goto_out;
}
evmask = dm_event_handler_get_event_mask(dmevh);
@@ -1737,21 +1754,25 @@ static int _device_registered_with_dmeventd(struct cmd_context *cmd, const struc
evmask &= ~DM_EVENT_REGISTRATION_PENDING;
}
- if (dso && (*dso = dm_event_handler_get_dso(dmevh)) && !(*dso = dm_pool_strdup(cmd->mem, *dso)))
- log_error("Failed to duplicate dso name.");
-
+ *monitored = evmask;
+ r = 1;
+out:
dm_event_handler_destroy(dmevh);
- return evmask;
+ return r;
}
int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
- const struct logical_volume *lv, int *pending)
+ const struct logical_volume *lv,
+ int *pending, int *monitored)
{
char *uuid;
- enum dm_event_mask evmask = 0;
+ enum dm_event_mask evmask;
struct dm_event_handler *dmevh;
+ int r;
+
*pending = 0;
+ *monitored = 0;
if (!dso)
return_0;
@@ -1762,9 +1783,13 @@ int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
if (!(dmevh = _create_dm_event_handler(cmd, uuid, dso, 0, DM_EVENT_ALL_ERRORS)))
return_0;
- if (dm_event_get_registered_device(dmevh, 0)) {
- dm_event_handler_destroy(dmevh);
- return 0;
+ if ((r = dm_event_get_registered_device(dmevh, 0))) {
+ if (r == -ENOENT) {
+ r = 1;
+ goto out;
+ }
+ r = 0;
+ goto_out;
}
evmask = dm_event_handler_get_event_mask(dmevh);
@@ -1773,9 +1798,12 @@ int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
evmask &= ~DM_EVENT_REGISTRATION_PENDING;
}
+ *monitored = evmask;
+ r = 1;
+out:
dm_event_handler_destroy(dmevh);
- return evmask;
+ return r;
}
int target_register_events(struct cmd_context *cmd, const char *dso, const struct logical_volume *lv,
@@ -1818,7 +1846,7 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
const struct lv_activate_opts *laopts, int monitor)
{
#ifdef DMEVENTD
- int i, pending = 0, monitored;
+ int i, pending = 0, monitored = 0;
int r = 1;
struct dm_list *snh, *snht;
struct lv_segment *seg;
@@ -1964,11 +1992,21 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
!seg->segtype->ops->target_monitored) /* doesn't support registration */
continue;
- if (!monitor)
+ if (!monitor) {
/* When unmonitoring, obtain existing dso being used. */
- monitored = _device_registered_with_dmeventd(cmd, seg_is_snapshot(seg) ? seg->cow : seg->lv, &pending, &dso);
- else
- monitored = seg->segtype->ops->target_monitored(seg, &pending);
+ if (!_device_registered_with_dmeventd(cmd, seg_is_snapshot(seg) ? seg->cow : seg->lv,
+ &dso, &pending, &monitored)) {
+ log_warn("WARNING: Failed to %smonitor %s.",
+ monitor ? "" : "un",
+ display_lvname(seg_is_snapshot(seg) ? seg->cow : seg->lv));
+ return 0;
+ }
+ } else if (!seg->segtype->ops->target_monitored(seg, &pending, &monitored)) {
+ log_warn("WARNING: Failed to %smonitor %s.",
+ monitor ? "" : "un",
+ display_lvname(seg->lv));
+ return 0;
+ }
/* FIXME: We should really try again if pending */
monitored = (pending) ? 0 : monitored;
@@ -2021,7 +2059,11 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
/* Try a couple times if pending, but not forever... */
for (i = 0;; i++) {
pending = 0;
- monitored = seg->segtype->ops->target_monitored(seg, &pending);
+ if (!seg->segtype->ops->target_monitored(seg, &pending, &monitored)) {
+ stack;
+ r = 0;
+ break;
+ }
if (!pending || i >= 40)
break;
log_very_verbose("%s %smonitoring still pending: waiting...",
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index 25b7cc8..b1cc176 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -208,7 +208,7 @@ int monitor_dev_for_events(struct cmd_context *cmd, const struct logical_volume
# include "libdevmapper-event.h"
char *get_monitor_dso_path(struct cmd_context *cmd, const char *libpath);
int target_registered_with_dmeventd(struct cmd_context *cmd, const char *dso,
- const struct logical_volume *lv, int *pending);
+ const struct logical_volume *lv, int *pending, int *monitored);
int target_register_events(struct cmd_context *cmd, const char *dso, const struct logical_volume *lv,
int evmask __attribute__((unused)), int set, int timeout);
#endif
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 630880f..b19ae34 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -298,7 +298,7 @@ char *lvseg_monitor_dup(struct dm_pool *mem, const struct lv_segment *seg)
#ifdef DMEVENTD
struct lvinfo info;
- int pending = 0, monitored;
+ int pending = 0, monitored = 0;
struct lv_segment *segm = (struct lv_segment *) seg;
if (lv_is_cow(seg->lv) && !lv_is_merging_cow(seg->lv))
@@ -314,11 +314,13 @@ char *lvseg_monitor_dup(struct dm_pool *mem, const struct lv_segment *seg)
else if (!seg_monitored(segm) || (segm->status & PVMOVE))
s = "not monitored";
else if (lv_info(seg->lv->vg->cmd, seg->lv, 1, &info, 0, 0) && info.exists) {
- monitored = segm->segtype->ops->target_monitored(segm, &pending);
- if (pending)
- s = "pending";
- else
- s = (monitored) ? "monitored" : "not monitored";
+ if (segm->segtype->ops->target_monitored(segm, &pending, &monitored)) {
+ if (pending)
+ s = "pending";
+ else
+ s = (monitored) ? "monitored" : "not monitored";
+ } else
+ s = "not monitored";
} // else log_debug("Not active");
#endif
return dm_pool_strdup(mem, s);
diff --git a/lib/metadata/segtype.h b/lib/metadata/segtype.h
index 61a6580..fd8646c 100644
--- a/lib/metadata/segtype.h
+++ b/lib/metadata/segtype.h
@@ -259,7 +259,7 @@ struct segtype_handler {
const struct lv_segment *seg,
struct dm_list *modules);
void (*destroy) (struct segment_type * segtype);
- int (*target_monitored) (struct lv_segment *seg, int *pending);
+ int (*target_monitored) (struct lv_segment *seg, int *pending, int *monitored);
int (*target_monitor_events) (struct lv_segment *seg, int events);
int (*target_unmonitor_events) (struct lv_segment *seg, int events);
};
diff --git a/lib/mirror/mirrored.c b/lib/mirror/mirrored.c
index 602c30a..012501e 100644
--- a/lib/mirror/mirrored.c
+++ b/lib/mirror/mirrored.c
@@ -486,10 +486,10 @@ static const char *_get_mirror_dso_path(struct cmd_context *cmd)
}
/* FIXME Cache this */
-static int _target_registered(struct lv_segment *seg, int *pending)
+static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
return target_registered_with_dmeventd(seg->lv->vg->cmd, _get_mirror_dso_path(seg->lv->vg->cmd),
- seg->lv, pending);
+ seg->lv, pending, monitored);
}
/* FIXME This gets run while suspended and performs banned operations. */
diff --git a/lib/raid/raid.c b/lib/raid/raid.c
index 5d2e1ea..9b85373 100644
--- a/lib/raid/raid.c
+++ b/lib/raid/raid.c
@@ -544,12 +544,12 @@ static const char *_get_raid_dso_path(struct cmd_context *cmd)
return get_monitor_dso_path(cmd, config_str);
}
-static int _raid_target_monitored(struct lv_segment *seg, int *pending)
+static int _raid_target_monitored(struct lv_segment *seg, int *pending, int *monitored)
{
struct cmd_context *cmd = seg->lv->vg->cmd;
const char *dso_path = _get_raid_dso_path(cmd);
- return target_registered_with_dmeventd(cmd, dso_path, seg->lv, pending);
+ return target_registered_with_dmeventd(cmd, dso_path, seg->lv, pending, monitored);
}
static int _raid_set_events(struct lv_segment *seg, int evmask, int set)
diff --git a/lib/snapshot/snapshot.c b/lib/snapshot/snapshot.c
index a80f283..68e01f5 100644
--- a/lib/snapshot/snapshot.c
+++ b/lib/snapshot/snapshot.c
@@ -186,10 +186,11 @@ static const char *_get_snapshot_dso_path(struct cmd_context *cmd)
}
/* FIXME Cache this */
-static int _target_registered(struct lv_segment *seg, int *pending)
+static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
- return target_registered_with_dmeventd(seg->lv->vg->cmd, _get_snapshot_dso_path(seg->lv->vg->cmd),
- seg->cow, pending);
+ return target_registered_with_dmeventd(seg->lv->vg->cmd,
+ _get_snapshot_dso_path(seg->lv->vg->cmd),
+ seg->cow, pending, monitored);
}
/* FIXME This gets run while suspended and performs banned operations. */
diff --git a/lib/thin/thin.c b/lib/thin/thin.c
index 73fffa6..9cb1ee0 100644
--- a/lib/thin/thin.c
+++ b/lib/thin/thin.c
@@ -437,11 +437,11 @@ static const char *_get_thin_dso_path(struct cmd_context *cmd)
}
/* FIXME Cache this */
-static int _target_registered(struct lv_segment *seg, int *pending)
+static int _target_registered(struct lv_segment *seg, int *pending, int *monitored)
{
return target_registered_with_dmeventd(seg->lv->vg->cmd,
_get_thin_dso_path(seg->lv->vg->cmd),
- seg->lv, pending);
+ seg->lv, pending, monitored);
}
/* FIXME This gets run while suspended and performs banned operations. */
6 years, 2 months
master - cleanup: detect dmeventd_executable just once
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=12fba201be314dd16ea...
Commit: 12fba201be314dd16ea01fc756e39c04c8ba50c3
Parent: 4f278324c76c339b59f4c613303573bc64a16272
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Feb 9 23:38:02 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:14:25 2018 +0100
cleanup: detect dmeventd_executable just once
Avoid repeating debug messages about dmeventd executable
and just remember it once for whole cmd lifetime.
---
lib/activate/activate.c | 5 ++++-
lib/commands/toolcontext.h | 1 +
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 2328abe..58e6873 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1662,7 +1662,10 @@ static struct dm_event_handler *_create_dm_event_handler(struct cmd_context *cmd
if (!(dmevh = dm_event_handler_create()))
return_NULL;
- if (dm_event_handler_set_dmeventd_path(dmevh, find_config_tree_str(cmd, dmeventd_executable_CFG, NULL)))
+ if (!cmd->default_settings.dmeventd_executable)
+ cmd->default_settings.dmeventd_executable = find_config_tree_str(cmd, dmeventd_executable_CFG, NULL);
+
+ if (dm_event_handler_set_dmeventd_path(dmevh, cmd->default_settings.dmeventd_executable))
goto_bad;
if (dso && dm_event_handler_set_dso(dmevh, dso))
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 4419daa..3921167 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -42,6 +42,7 @@ struct config_info {
int cache_vgmetadata;
const char *msg_prefix;
const char *fmt_name;
+ const char *dmeventd_executable;
uint64_t unit_factor;
int cmd_name; /* Show command name? */
mode_t umask;
6 years, 2 months
master - lvmlockd: improve dm path creation for sanlock LV
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4f278324c76c339b59f...
Commit: 4f278324c76c339b59f4c613303573bc64a16272
Parent: 7239a45b79a6076c198e0542161146257114f5be
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 12 21:50:57 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:14:25 2018 +0100
lvmlockd: improve dm path creation for sanlock LV
Use devmapper function to create matching dm name with mangling.
Drop extra '-1' from buffer passed to snprintf.
---
daemons/lvmlockd/lvmlockd-sanlock.c | 43 ++++++++++++++++++++++++++++++----
1 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-sanlock.c b/daemons/lvmlockd/lvmlockd-sanlock.c
index 795362a..dd88d24 100644
--- a/daemons/lvmlockd/lvmlockd-sanlock.c
+++ b/daemons/lvmlockd/lvmlockd-sanlock.c
@@ -294,6 +294,36 @@ out:
return host_id;
}
+/* Prepare valid /dev/mapper/vgname-lvname with all the mangling */
+static int build_dm_path(char *path, size_t path_len,
+ const char *vg_name, const char *lv_name)
+{
+ struct dm_pool *mem;
+ char *dm_name;
+ int rv = 0;
+
+ if (!(mem = dm_pool_create("namepool", 1024))) {
+ log_error("Failed to create mempool.");
+ return -ENOMEM;
+ }
+
+ if (!(dm_name = dm_build_dm_name(mem, vg_name, lv_name, NULL))) {
+ log_error("Failed to build dm name for %s/%s.", vg_name, lv_name);
+ rv = -EINVAL;
+ goto fail;
+ }
+
+ if ((dm_snprintf(path, path_len, "%s/%s", dm_dir(), dm_name) < 0)) {
+ log_error("Failed to create path %s/%s.", dm_dir(), dm_name);
+ rv = -EINVAL;
+ }
+
+fail:
+ dm_pool_destroy(mem);
+
+ return rv;
+}
+
/*
* vgcreate
*
@@ -336,7 +366,8 @@ int lm_init_vg_sanlock(char *ls_name, char *vg_name, uint32_t flags, char *vg_ar
if (strlen(lock_lv_name) + strlen(lock_args_version) + 2 > MAX_ARGS)
return -EARGS;
- snprintf(disk.path, SANLK_PATH_LEN-1, "/dev/mapper/%s-%s", vg_name, lock_lv_name);
+ if ((rv = build_dm_path(disk.path, SANLK_PATH_LEN, vg_name, lock_lv_name)))
+ return rv;
log_debug("S %s init_vg_san path %s", ls_name, disk.path);
@@ -513,7 +544,8 @@ int lm_init_lv_sanlock(char *ls_name, char *vg_name, char *lv_name,
strncpy(rd.rs.lockspace_name, ls_name, SANLK_NAME_LEN);
rd.rs.num_disks = 1;
- snprintf(rd.rs.disks[0].path, SANLK_PATH_LEN-1, "/dev/mapper/%s-%s", vg_name, lock_lv_name);
+ if ((rv = build_dm_path(rd.rs.disks[0].path, SANLK_PATH_LEN, vg_name, lock_lv_name)))
+ return rv;
align_size = sanlock_align(&rd.rs.disks[0]);
if (align_size <= 0) {
@@ -612,7 +644,8 @@ int lm_rename_vg_sanlock(char *ls_name, char *vg_name, uint32_t flags, char *vg_
return rv;
}
- snprintf(disk.path, SANLK_PATH_LEN-1, "/dev/mapper/%s-%s", vg_name, lock_lv_name);
+ if ((rv = build_dm_path(disk.path, SANLK_PATH_LEN, vg_name, lock_lv_name)))
+ return rv;
log_debug("S %s rename_vg_san path %s", ls_name, disk.path);
@@ -1088,8 +1121,8 @@ int lm_prepare_lockspace_sanlock(struct lockspace *ls)
goto fail;
}
- snprintf(disk_path, SANLK_PATH_LEN-1, "/dev/mapper/%s-%s",
- ls->vg_name, lock_lv_name);
+ if ((rv = build_dm_path(disk_path, SANLK_PATH_LEN, ls->vg_name, lock_lv_name)))
+ goto fail;
/*
* When a vg is started, the internal sanlock lv should be
6 years, 2 months
master - clean: drop unneeded -1 for snprintf
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7239a45b79a6076c198...
Commit: 7239a45b79a6076c198e0542161146257114f5be
Parent: d94036f8ed412457f2044f0b36aebe24f7fcc707
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 12 21:50:07 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:14:25 2018 +0100
clean: drop unneeded -1 for snprintf
man gives:
snprintf() and vsnprintf() write at most size bytes
(including the terminating null byte ('\0')) to str.
---
daemons/lvmetad/lvmetad-core.c | 2 +-
daemons/lvmlockd/lvmlockd-dlm.c | 2 +-
daemons/lvmlockd/lvmlockd-sanlock.c | 4 ++--
lib/activate/activate.c | 2 +-
libdm/libdm-config.c | 2 +-
libdm/libdm-file.c | 3 +--
libdm/libdm-string.c | 2 +-
7 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 6d5f6a7..04a7224 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -2432,7 +2432,7 @@ static response get_global_info(lvmetad_state *s, request r)
pid = (int)daemon_request_int(r, "pid", 0);
if (s->flags & GLFL_DISABLE) {
- snprintf(reason, REASON_BUF_SIZE - 1, "%s%s%s%s%s",
+ snprintf(reason, REASON_BUF_SIZE, "%s%s%s%s%s",
(s->flags & GLFL_DISABLE_REASON_DIRECT) ? LVMETAD_DISABLE_REASON_DIRECT "," : "",
(s->flags & GLFL_DISABLE_REASON_REPAIR) ? LVMETAD_DISABLE_REASON_REPAIR "," : "",
(s->flags & GLFL_DISABLE_REASON_LVM1) ? LVMETAD_DISABLE_REASON_LVM1 "," : "",
diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c
index 9440821..d9dfabb 100644
--- a/daemons/lvmlockd/lvmlockd-dlm.c
+++ b/daemons/lvmlockd/lvmlockd-dlm.c
@@ -699,7 +699,7 @@ int lm_hosts_dlm(struct lockspace *ls, int notify)
return 0;
memset(ls_nodes_path, 0, sizeof(ls_nodes_path));
- snprintf(ls_nodes_path, PATH_MAX-1, "%s/%s/nodes",
+ snprintf(ls_nodes_path, PATH_MAX, "%s/%s/nodes",
DLM_LOCKSPACES_PATH, ls->name);
if (!(ls_dir = opendir(ls_nodes_path)))
diff --git a/daemons/lvmlockd/lvmlockd-sanlock.c b/daemons/lvmlockd/lvmlockd-sanlock.c
index 16db2d6..795362a 100644
--- a/daemons/lvmlockd/lvmlockd-sanlock.c
+++ b/daemons/lvmlockd/lvmlockd-sanlock.c
@@ -1069,10 +1069,10 @@ int lm_prepare_lockspace_sanlock(struct lockspace *ls)
* and appending "lockctl" to get /path/to/lvmlockctl.
*/
memset(killpath, 0, sizeof(killpath));
- snprintf(killpath, SANLK_PATH_LEN - 1, "%slockctl", LVM_PATH);
+ snprintf(killpath, SANLK_PATH_LEN, "%slockctl", LVM_PATH);
memset(killargs, 0, sizeof(killargs));
- snprintf(killargs, SANLK_PATH_LEN - 1, "--kill %s", ls->vg_name);
+ snprintf(killargs, SANLK_PATH_LEN, "--kill %s", ls->vg_name);
rv = check_args_version(ls->vg_args, VG_LOCK_ARGS_MAJOR);
if (rv < 0) {
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 7a37130..2328abe 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -606,7 +606,7 @@ int module_present(struct cmd_context *cmd, const char *target_name)
#endif
struct stat st;
char path[PATH_MAX];
- int i = dm_snprintf(path, (sizeof(path) - 1), "%smodule/dm_%s",
+ int i = dm_snprintf(path, sizeof(path), "%smodule/dm_%s",
dm_sysfs_dir(), target_name);
if (i > 0) {
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index e1ca210..746ef07 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -244,7 +244,7 @@ static int _line_append(struct config_output *out, const char *fmt, ...)
*/
va_start(ap, fmt);
- n = vsnprintf(&buf[0], sizeof buf - 1, fmt, ap);
+ n = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (n < 0) {
diff --git a/libdm/libdm-file.c b/libdm/libdm-file.c
index 2c313b3..e7416f1 100644
--- a/libdm/libdm-file.c
+++ b/libdm/libdm-file.c
@@ -187,8 +187,7 @@ retry_fcntl:
goto fail_close_unlink;
}
- memset(buffer, 0, sizeof(buffer));
- snprintf(buffer, sizeof(buffer)-1, "%u\n", getpid());
+ snprintf(buffer, sizeof(buffer), "%u\n", getpid());
bufferlen = strlen(buffer);
write_out = write(fd, buffer, bufferlen);
diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c
index 2085aa8..cf9690c 100644
--- a/libdm/libdm-string.c
+++ b/libdm/libdm-string.c
@@ -611,7 +611,7 @@ const char *dm_size_to_string(struct dm_pool *mem, uint64_t size,
precision = 2;
}
- snprintf(size_buf, SIZE_BUF - 1, "%s%.*f%s", prefix, precision,
+ snprintf(size_buf, SIZE_BUF, "%s%.*f%s", prefix, precision,
(double) size / byte, include_suffix ? size_str[base + s][suffix_type] : "");
return size_buf;
6 years, 2 months
master - vgimportclone: add some dm_snprintf checks
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d94036f8ed412457f20...
Commit: d94036f8ed412457f2044f0b36aebe24f7fcc707
Parent: 60b61f2db3d6e98329213e11b65581ea1ee080a5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Feb 9 17:06:30 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:14:22 2018 +0100
vgimportclone: add some dm_snprintf checks
Check if the generated vg name still fits the buffer.
So too long strings are rejected.
Drop -1 from size passed to snprintf - as the \0 is already included.
---
WHATS_NEW | 1 +
tools/vgimportclone.c | 23 ++++++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 74f9616..1ffa3db 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.178 -
=====================================
+ Improve validation of created strings in vgimportclone.
Add missing initialisation of mem pool in systemd generator.
Do not reopen output streams for multithreaded users of liblvm.
Use versionsort to fix archive file expiry beyond 100000 files.
diff --git a/tools/vgimportclone.c b/tools/vgimportclone.c
index 1f86ad6..146d3b4 100644
--- a/tools/vgimportclone.c
+++ b/tools/vgimportclone.c
@@ -283,12 +283,22 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv)
*/
if (arg_is_set(cmd, basevgname_ARG)) {
- snprintf(base_vgname, sizeof(base_vgname) - 1, "%s", arg_str_value(cmd, basevgname_ARG, ""));
- memcpy(tmp_vgname, base_vgname, NAME_LEN);
+ vgname = arg_str_value(cmd, basevgname_ARG, "");
+ if (dm_snprintf(base_vgname, sizeof(base_vgname), "%s", vgname) < 0) {
+ log_error("Base vg name %s is too long.", vgname);
+ goto out;
+ }
+ (void) dm_strncpy(tmp_vgname, base_vgname, NAME_LEN);
vgname_count = 0;
} else {
- snprintf(base_vgname, sizeof(base_vgname) - 1, "%s", vp.old_vgname);
- snprintf(tmp_vgname, sizeof(tmp_vgname) - 1, "%s1", vp.old_vgname);
+ if (dm_snprintf(base_vgname, sizeof(base_vgname), "%s", vp.old_vgname) < 0) {
+ log_error(INTERNAL_ERROR "Old vg name %s is too long.", vp.old_vgname);
+ goto out;
+ }
+ if (dm_snprintf(tmp_vgname, sizeof(tmp_vgname), "%s1", vp.old_vgname) < 0) {
+ log_error("Temporary vg name %s1 is too long.", vp.old_vgname);
+ goto out;
+ }
vgname_count = 1;
}
@@ -299,7 +309,10 @@ retry_name:
dm_list_iterate_items(vgnl, &vgnameids_on_system) {
if (!strcmp(vgnl->vg_name, tmp_vgname)) {
vgname_count++;
- snprintf(tmp_vgname, sizeof(tmp_vgname) - 1, "%s%u", base_vgname, vgname_count);
+ if (dm_snprintf(tmp_vgname, sizeof(tmp_vgname), "%s%u", base_vgname, vgname_count) < 0) {
+ log_error("Failed to generated temporary vg name, %s%u is too long.", base_vgname, vgname_count);
+ goto out;
+ }
goto retry_name;
}
}
6 years, 2 months
master - libdm-stats: correct checking of dm_snprintf error
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=60b61f2db3d6e983292...
Commit: 60b61f2db3d6e98329213e11b65581ea1ee080a5
Parent: afdbb28f7222b3a5a38964d47d750aad8aec12f6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Feb 12 10:27:16 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:13:57 2018 +0100
libdm-stats: correct checking of dm_snprintf error
Function dm_snprintf returns -1 on error, while 0 is still
considered valid result code so correcting error path testing.
---
WHATS_NEW_DM | 1 +
libdm/libdm-stats.c | 36 ++++++++++++++++++------------------
tools/dmsetup.c | 22 +++++++++++-----------
3 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index bf3ae19..52593c5 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.147 -
=====================================
+ Fix tests for failing dm_snprintf() in stats code.
Parsing mirror status accepts 'userspace' keyword in status.
Introduce dm_malloc_aligned for page alignment of buffers.
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index bc49867..c74444a 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -1894,10 +1894,10 @@ static int _stats_set_aux(struct dm_stats *dms,
}
}
- if (!dm_snprintf(msg, sizeof(msg), "@stats_set_aux " FMTu64 " %s%s%s ",
- region_id, (group_tag) ? group_tag : "",
- (group_tag) ? DMS_AUX_SEP : "",
- (strlen(aux_data)) ? aux_data : "-")) {
+ if (dm_snprintf(msg, sizeof(msg), "@stats_set_aux " FMTu64 " %s%s%s ",
+ region_id, (group_tag) ? group_tag : "",
+ (group_tag) ? DMS_AUX_SEP : "",
+ (strlen(aux_data)) ? aux_data : "-") < 0) {
log_error("Could not prepare @stats_set_aux message");
goto bad;
}
@@ -1940,8 +1940,8 @@ static int _stats_create_region(struct dm_stats *dms, uint64_t *region_id,
program_id = dms->program_id;
if (start || len) {
- if (!dm_snprintf(range, sizeof(range), FMTu64 "+" FMTu64,
- start, len)) {
+ if (dm_snprintf(range, sizeof(range), FMTu64 "+" FMTu64,
+ start, len) < 0) {
log_error(err_fmt, "range");
return 0;
}
@@ -1971,11 +1971,11 @@ static int _stats_create_region(struct dm_stats *dms, uint64_t *region_id,
} else
opt_args = dm_strdup("");
- if (!dm_snprintf(msg, sizeof(msg), "@stats_create %s %s" FMTu64
- " %s %s %s", (start || len) ? range : "-",
- (step < 0) ? "/" : "",
- (uint64_t)llabs(step),
- opt_args, program_id, aux_data)) {
+ if (dm_snprintf(msg, sizeof(msg), "@stats_create %s %s" FMTu64
+ " %s %s %s", (start || len) ? range : "-",
+ (step < 0) ? "/" : "",
+ (uint64_t)llabs(step),
+ opt_args, program_id, aux_data) < 0) {
log_error(err_fmt, "message");
dm_free((void *) opt_args);
return 0;
@@ -2079,7 +2079,7 @@ static int _stats_delete_region(struct dm_stats *dms, uint64_t region_id)
return 0;
}
- if (!dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id)) {
+ if (dm_snprintf(msg, sizeof(msg), "@stats_delete " FMTu64, region_id) < 0) {
log_error("Could not prepare @stats_delete message.");
return 0;
}
@@ -2163,7 +2163,7 @@ int dm_stats_clear_region(struct dm_stats *dms, uint64_t region_id)
if (!_stats_bound(dms))
return_0;
- if (!dm_snprintf(msg, sizeof(msg), "@stats_clear " FMTu64, region_id)) {
+ if (dm_snprintf(msg, sizeof(msg), "@stats_clear " FMTu64, region_id) < 0) {
log_error("Could not prepare @stats_clear message.");
return 0;
}
@@ -2188,15 +2188,15 @@ static struct dm_task *_stats_print_region(struct dm_stats *dms,
struct dm_task *dmt = NULL;
if (start_line || num_lines)
- if (!dm_snprintf(lines, sizeof(lines),
- "%u %u", start_line, num_lines)) {
+ if (dm_snprintf(lines, sizeof(lines),
+ "%u %u", start_line, num_lines) < 0) {
log_error(err_fmt, "row specification");
return NULL;
}
- if (!dm_snprintf(msg, sizeof(msg), "@stats_print%s " FMTu64 " %s",
- (clear) ? "_clear" : "",
- region_id, (start_line || num_lines) ? lines : "")) {
+ if (dm_snprintf(msg, sizeof(msg), "@stats_print%s " FMTu64 " %s",
+ (clear) ? "_clear" : "",
+ region_id, (start_line || num_lines) ? lines : "") < 0) {
log_error(err_fmt, "message");
return NULL;
}
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index e85680f..cc47d11 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -4051,7 +4051,7 @@ static int _dm_stats_rrqm_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", rrqm))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", rrqm) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4082,7 +4082,7 @@ static int _dm_stats_wrqm_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", wrqm))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", wrqm) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4113,7 +4113,7 @@ static int _dm_stats_rs_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", rs))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", rs) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4144,7 +4144,7 @@ static int _dm_stats_ws_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", ws))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", ws) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4265,7 +4265,7 @@ static int _dm_stats_qusz_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", qusz))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", qusz) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4299,7 +4299,7 @@ static int _dm_stats_await_disp(struct dm_report *rh,
/* display in msecs */
await /= NSEC_PER_MSEC;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", await))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", await) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4333,7 +4333,7 @@ static int _dm_stats_r_await_disp(struct dm_report *rh,
/* display in msecs */
r_await /= NSEC_PER_MSEC;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", r_await))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", r_await) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4367,7 +4367,7 @@ static int _dm_stats_w_await_disp(struct dm_report *rh,
/* display in msecs */
w_await /= NSEC_PER_MSEC;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", w_await))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", w_await) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4397,7 +4397,7 @@ static int _dm_stats_tput_disp(struct dm_report *rh,
DM_STATS_AREA_CURRENT))
return_0;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", tput))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", tput) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4431,7 +4431,7 @@ static int _dm_stats_svctm_disp(struct dm_report *rh,
/* display in msecs */
svctm /= NSEC_PER_MSEC;
- if (!dm_snprintf(buf, sizeof(buf), "%.2f", svctm))
+ if (dm_snprintf(buf, sizeof(buf), "%.2f", svctm) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
@@ -4487,7 +4487,7 @@ static int _dm_stats_sample_interval_disp(struct dm_report *rh,
*sortval = (double)_last_interval / (double) NSEC_PER_SEC;
- if (!dm_snprintf(buf, sizeof(buf), "%2.6f", *sortval))
+ if (dm_snprintf(buf, sizeof(buf), "%2.6f", *sortval) < 0)
return_0;
if (!(repstr = dm_pool_strdup(mem, buf)))
6 years, 2 months
master - toolcontext: light context missed to set-up mem mempool
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=afdbb28f7222b3a5a38...
Commit: afdbb28f7222b3a5a38964d47d750aad8aec12f6
Parent: 34a9e3d3cdde5771e30fbd686b20ffba1647a497
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Feb 9 15:39:14 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Feb 12 22:13:53 2018 +0100
toolcontext: light context missed to set-up mem mempool
If cmd->mem was null, then systemd generator was failing on:
(gdb) bt
dm_pool_alloc_aligned (p=0x0, s=96, alignment=8) at mm/pool-fast.c:95
dm_pool_alloc (p=0x0, s=96) at mm/pool-fast.c:90
dm_pool_zalloc (p=0x0, s=96) at mm/pool.c:74
config_file_read_fd (mem=0x0, cft=0x55f4339dbad0, dev=0x55f4339dfac0, reason=DEV_IO_MDA_CONTENT, offset=0, size=82293, offset2=0, size2=0,
checksum_fn=0x0, checksum=0, checksum_only=0, no_dup_node_check=0, ioflags=0, config_file_read_fd_callback=0x0, config_file_read_fd_context=0x0) at config/config.c:567
config_file_read (mem=0x0, cft=0x55f4339dbad0) at config/config.c:658
config_file_open_and_read (config_file=0x7f49aef14540 <config_file> "/var/tmp/lvm/etc/lvm/lvm.conf", source=CONFIG_FILE, cmd=0x55f4339d6260)
at config/config.c:282
_load_config_file (cmd=0x55f4339d6260, tag=0x7f49aeca15da "", local=0) at commands/toolcontext.c:824
_init_lvm_conf (cmd=0x55f4339d6260) at commands/toolcontext.c:853
create_config_context () at commands/toolcontext.c:1814
lvm_config_find_bool (libh=0x0, config_path=0x55f431a884ad "global/use_lvmetad", fail=0) at lvm_base.c:144
main ()
---
WHATS_NEW | 1 +
lib/commands/toolcontext.c | 5 +++++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index bf46281..74f9616 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.178 -
=====================================
+ Add missing initialisation of mem pool in systemd generator.
Do not reopen output streams for multithreaded users of liblvm.
Use versionsort to fix archive file expiry beyond 100000 files.
Add devices/use_aio, aio_max, aio_memory to configure AIO limits.
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index ba757dd..b613b8f 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1792,6 +1792,8 @@ void destroy_config_context(struct cmd_context *cmd)
/*
* A "config context" is a very light weight toolcontext that
* is only used for reading config settings from lvm.conf.
+ *
+ * FIXME: this needs to go back to parametrized create_toolcontext()
*/
struct cmd_context *create_config_context(void)
{
@@ -1808,6 +1810,9 @@ struct cmd_context *create_config_context(void)
if (!(cmd->libmem = dm_pool_create("library", 4 * 1024)))
goto_out;
+ if (!(cmd->mem = dm_pool_create("command", 4 * 1024)))
+ goto out;
+
dm_list_init(&cmd->config_files);
dm_list_init(&cmd->tags);
6 years, 2 months
master - python: add devmapper library to linking
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=34a9e3d3cdde5771e30...
Commit: 34a9e3d3cdde5771e30fbd686b20ffba1647a497
Parent: 7cfe5ab9bc279bb1cea42862a53d83556fb3ed52
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Feb 9 10:21:00 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Feb 9 11:00:18 2018 +0100
python: add devmapper library to linking
On occasional gcc releases it's better to specify also -ldevmapper
to linking logic for python object.
It's in fact more correct since the liblvm.c code is using
libdevmapper functions - that were linked in only via
liblvm2app library.
---
python/setup.py.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/setup.py.in b/python/setup.py.in
index 6a44482..dac999a 100644
--- a/python/setup.py.in
+++ b/python/setup.py.in
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2012-2018 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@@ -20,7 +20,7 @@ from distutils.core import setup, Extension
liblvm = Extension('lvm',
sources = ['liblvm_python.c'],
- libraries= ['lvm2app'],
+ libraries= ['lvm2app', 'devmapper'],
library_dirs= ['@top_builddir@/liblvm'],
include_dirs= ['@top_builddir@/include'])
6 years, 2 months