master - lvmcmdline: enhance acceptance of size numbers
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b4b5d449ef7045d33b...
Commit: 9b4b5d449ef7045d33b8d8d7e69011d16f4bb8ab
Parent: f7e62bc55ccc7ab012325ba2ecc4a2009339989a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 10:30:07 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
lvmcmdline: enhance acceptance of size numbers
Explictely detect duplicate sing symbols and leave the rest of
double number validation on 'strtod()' function. This way
we can also accept size like:
lvcreate -L.1M
We already accept -L0.1M - but it's common to accept numbers
starting with leading '.' - just as 'strtod()' accepts it).
---
tools/lvmcmdline.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 9cf2144..3ff0d1d 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -560,8 +560,10 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
av->sign = SIGN_NONE;
}
- if (!isdigit(*val))
+ if (*val == '+' || *val == '-') {
+ log_error("Multiple sign symbols detected.");
return 0;
+ }
errno = 0;
v = strtod(val, &ptr);
@@ -596,6 +598,7 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
break;
if (i < 0) {
+ log_error("Can't parse size argument.");
return 0;
} else if (i == 7) {
/* v is already in sectors */
6 years, 9 months
master - cleanup: drop extra compare
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f7e62bc55ccc7ab0123...
Commit: f7e62bc55ccc7ab012325ba2ecc4a2009339989a
Parent: 55f9e2f39996ad325425d99d4631120e8271cfcd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 10:22:20 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
cleanup: drop extra compare
dm_free() already validates for NULL itself.
---
daemons/lvmetad/lvmetad-core.c | 21 +++++++--------------
lib/cache/lvmcache.c | 9 +++------
lib/format_text/export.c | 4 ++--
lib/format_text/format-text.c | 3 +--
libdm/libdm-report.c | 4 ++--
libdm/libdm-stats.c | 12 ++++--------
6 files changed, 19 insertions(+), 34 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index f56eede..64d4fbb 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -884,16 +884,13 @@ static int remove_metadata(lvmetad_state *s, const char *vgid, int update_pvids)
/* free the unmapped data */
- if (info_lookup)
- dm_free(info_lookup);
if (meta_lookup)
dm_config_destroy(meta_lookup);
- if (name_lookup)
- dm_free(name_lookup);
if (outdated_pvs_lookup)
dm_config_destroy(outdated_pvs_lookup);
- if (vgid_lookup)
- dm_free(vgid_lookup);
+ dm_free(info_lookup);
+ dm_free(name_lookup);
+ dm_free(vgid_lookup);
return 1;
}
@@ -1220,10 +1217,8 @@ static int _update_metadata_add_new(lvmetad_state *s, const char *new_name, cons
out:
out_free:
if (!new_name_dup || !new_vgid_dup || abort_daemon) {
- if (new_name_dup)
- dm_free(new_name_dup);
- if (new_vgid_dup)
- dm_free(new_vgid_dup);
+ dm_free(new_name_dup);
+ dm_free(new_vgid_dup);
ERROR(s, "lvmetad could not be updated and is aborting.");
exit(EXIT_FAILURE);
}
@@ -1813,8 +1808,7 @@ static response pv_gone(lvmetad_state *s, request r)
}
dm_config_destroy(pvmeta);
- if (old_pvid)
- dm_free(old_pvid);
+ dm_free(old_pvid);
return daemon_reply_simple("OK", NULL );
}
@@ -2238,8 +2232,7 @@ static response pv_found(lvmetad_state *s, request r)
}
/* This was unhashed from device_to_pvid above. */
- if (prev_pvid_on_dev)
- dm_free((void *)prev_pvid_on_dev);
+ dm_free((void *)prev_pvid_on_dev);
return daemon_reply_simple("OK",
"status = %s", vg_status,
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index a15481f..8431ca1 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1898,8 +1898,7 @@ static int _lvmcache_update_vgstatus(struct lvmcache_info *info, uint32_t vgstat
info->vginfo->creation_host))
goto set_lock_type;
- if (info->vginfo->creation_host)
- dm_free(info->vginfo->creation_host);
+ dm_free(info->vginfo->creation_host);
if (!(info->vginfo->creation_host = dm_strdup(creation_host))) {
log_error("cache creation host alloc failed for %s.",
@@ -1918,8 +1917,7 @@ set_lock_type:
if (info->vginfo->lock_type && !strcmp(lock_type, info->vginfo->lock_type))
goto set_system_id;
- if (info->vginfo->lock_type)
- dm_free(info->vginfo->lock_type);
+ dm_free(info->vginfo->lock_type);
if (!(info->vginfo->lock_type = dm_strdup(lock_type))) {
log_error("cache lock_type alloc failed for %s", lock_type);
@@ -1937,8 +1935,7 @@ set_system_id:
if (info->vginfo->system_id && !strcmp(system_id, info->vginfo->system_id))
goto out;
- if (info->vginfo->system_id)
- dm_free(info->vginfo->system_id);
+ dm_free(info->vginfo->system_id);
if (!(info->vginfo->system_id = dm_strdup(system_id))) {
log_error("cache system_id alloc failed for %s", system_id);
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index f369089..7a84909 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -910,8 +910,8 @@ static int _print_historical_lv(struct formatter *f, struct historical_logical_v
r = 1;
out:
- if (descendants_buffer)
- dm_free(descendants_buffer);
+ dm_free(descendants_buffer);
+
return r;
}
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 9e99c85..bf8cd02 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -268,8 +268,7 @@ static int _pv_analyze_mda_raw (const struct format_type * fmt,
r = 1;
out:
- if (buf)
- dm_free(buf);
+ dm_free(buf);
if (!dev_close(area->dev))
stack;
return r;
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 20a0827..a0ad26c 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -547,8 +547,8 @@ static int _report_field_string_list(struct dm_report *rh,
out:
if (!r && sort_value)
dm_pool_free(rh->mem, sort_value);
- if (arr)
- dm_free(arr);
+ dm_free(arr);
+
return r;
}
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index 541823b..bc49867 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -330,11 +330,9 @@ static void _stats_region_destroy(struct dm_stats_region *region)
region->counters = NULL;
region->bounds = NULL;
- if (region->program_id)
- dm_free(region->program_id);
+ dm_free(region->program_id);
region->program_id = NULL;
- if (region->aux_data)
- dm_free(region->aux_data);
+ dm_free(region->aux_data);
region->aux_data = NULL;
region->region_id = DM_STATS_REGION_NOT_PRESENT;
}
@@ -415,8 +413,7 @@ static void _stats_clear_binding(struct dm_stats *dms)
dm_pool_free(dms->mem, dms->bind_name);
if (dms->bind_uuid)
dm_pool_free(dms->mem, dms->bind_uuid);
- if (dms->name)
- dm_free((char *) dms->name);
+ dm_free((char *) dms->name);
dms->bind_name = dms->bind_uuid = NULL;
dms->bind_major = dms->bind_minor = -1;
@@ -2996,8 +2993,7 @@ int dm_stats_set_program_id(struct dm_stats *dms, int allow_empty,
if (!program_id)
program_id = "";
- if (dms->program_id)
- dm_free(dms->program_id);
+ dm_free(dms->program_id);
if (!(dms->program_id = dm_strdup(program_id)))
return_0;
6 years, 9 months
master - cleanup: shorten dump output code
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=55f9e2f39996ad32542...
Commit: 55f9e2f39996ad325425d99d4631120e8271cfcd
Parent: f6c2ee57fa97d374682c229a87700debf5f9302a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 18:22:52 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
cleanup: shorten dump output code
Save couple lines on code with simpler code.
---
daemons/lvmetad/lvmetad-core.c | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index a0821a3..f56eede 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -2578,14 +2578,12 @@ static void _dump_pairs(struct buffer *buf, struct dm_hash_table *ht, const char
dm_hash_iterate(n, ht) {
const char *key = dm_hash_get_key(ht, n),
*val = dm_hash_get_data(ht, n);
- buffer_append(buf, " ");
if (int_key)
- (void) dm_asprintf(&append, "%d = \"%s\"", *(const int*)key, val);
+ (void) dm_asprintf(&append, " %d = \"%s\"\n", *(const int*)key, val);
else
- (void) dm_asprintf(&append, "%s = \"%s\"", key, val);
+ (void) dm_asprintf(&append, " %s = \"%s\"\n", key, val);
if (append)
buffer_append(buf, append);
- buffer_append(buf, "\n");
dm_free(append);
}
buffer_append(buf, "}\n");
@@ -2603,11 +2601,9 @@ static void _dump_info_version(struct buffer *buf, struct dm_hash_table *ht, con
while (n) {
const char *key = dm_hash_get_key(ht, n);
info = dm_hash_get_data(ht, n);
- buffer_append(buf, " ");
- (void) dm_asprintf(&append, "%s = %lld", key, (long long)info->external_version);
+ (void) dm_asprintf(&append, " %s = %lld\n", key, (long long)info->external_version);
if (append)
buffer_append(buf, append);
- buffer_append(buf, "\n");
dm_free(append);
n = dm_hash_get_next(ht, n);
}
@@ -2626,11 +2622,9 @@ static void _dump_info_flags(struct buffer *buf, struct dm_hash_table *ht, const
while (n) {
const char *key = dm_hash_get_key(ht, n);
info = dm_hash_get_data(ht, n);
- buffer_append(buf, " ");
- (void) dm_asprintf(&append, "%s = %llx", key, (long long)info->flags);
+ (void) dm_asprintf(&append, " %s = %llx\n", key, (long long)info->flags);
if (append)
buffer_append(buf, append);
- buffer_append(buf, "\n");
dm_free(append);
n = dm_hash_get_next(ht, n);
}
6 years, 9 months
master - cleanup: drop const from allocated value
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f6c2ee57fa97d374682...
Commit: f6c2ee57fa97d374682c229a87700debf5f9302a
Parent: ba9820b14223b731125c83dbc9709aa44fdcdbf1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 18:21:41 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
cleanup: drop const from allocated value
Avoid using const for casting to non-const.
---
daemons/lvmetad/lvmetad-core.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 8910bd4..a0821a3 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -1927,7 +1927,7 @@ static response pv_found(lvmetad_state *s, request r)
const char *arg_pvid = NULL;
const char *arg_pvid_lookup = NULL;
const char *new_pvid = NULL;
- const char *new_pvid_dup = NULL;
+ char *new_pvid_dup = NULL;
const char *arg_name = NULL;
const char *arg_vgid = NULL;
const char *arg_vgid_lookup = NULL;
@@ -2090,7 +2090,7 @@ static response pv_found(lvmetad_state *s, request r)
if (!(new_pvid_dup = dm_strdup(new_pvid)))
goto nomem_free1;
- if (!dm_hash_insert_binary(s->device_to_pvid, &new_device, sizeof(new_device), (char *)new_pvid_dup))
+ if (!dm_hash_insert_binary(s->device_to_pvid, &new_device, sizeof(new_device), new_pvid_dup))
goto nomem_free2;
if (!dm_hash_insert(s->pvid_to_pvmeta, new_pvid, new_pvmeta))
@@ -2138,7 +2138,7 @@ static response pv_found(lvmetad_state *s, request r)
if (!(new_pvid_dup = dm_strdup(new_pvid)))
goto nomem_free1;
- if (!dm_hash_insert_binary(s->device_to_pvid, &arg_device, sizeof(arg_device), (char *)new_pvid_dup))
+ if (!dm_hash_insert_binary(s->device_to_pvid, &arg_device, sizeof(arg_device), new_pvid_dup))
goto nomem_free2;
if (!dm_hash_insert(s->pvid_to_pvmeta, new_pvid, new_pvmeta))
@@ -2251,7 +2251,7 @@ static response pv_found(lvmetad_state *s, request r)
NULL);
nomem_free2:
- dm_free((char *)new_pvid_dup);
+ dm_free(new_pvid_dup);
nomem_free1:
dm_config_destroy(new_pvmeta);
nomem:
6 years, 9 months
master - numbers: strtod or strtoul need reset of errno
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ba9820b14223b731125...
Commit: ba9820b14223b731125c83dbc9709aa44fdcdbf1
Parent: 94838b4df06c4f5a47c4cb51d5949d8e7b4684e7
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 10:28:02 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
numbers: strtod or strtoul need reset of errno
API for strtod() or strtoul() needs reset of errno, before it's being
called. So add missing resets in missing places and some also some
errno validation for out-of-range numbers.
---
daemons/dmfilemapd/dmfilemapd.c | 15 ++++++++++-----
daemons/lvmlockd/lvmlockd-sanlock.c | 3 +++
lib/config/config.c | 6 ++++--
libdm/libdm-config.c | 10 ++++++++++
libdm/libdm-report.c | 4 ++++
libdm/libdm-stats.c | 9 ++++++---
tools/dmsetup.c | 3 ++-
tools/lvmcmdline.c | 6 +++++-
8 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/daemons/dmfilemapd/dmfilemapd.c b/daemons/dmfilemapd/dmfilemapd.c
index a51187a..aa50242 100644
--- a/daemons/dmfilemapd/dmfilemapd.c
+++ b/daemons/dmfilemapd/dmfilemapd.c
@@ -225,8 +225,9 @@ static int _is_open(const char *path)
while ((proc_dp = readdir(proc_d)) != NULL) {
if (!isdigit(proc_dp->d_name[0]))
continue;
+ errno = 0;
pid = (pid_t) strtol(proc_dp->d_name, NULL, 10);
- if (!pid)
+ if (errno || !pid)
continue;
if (_is_open_in_pid(pid, path)) {
if (closedir(proc_d))
@@ -278,8 +279,9 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
fm->nr_regions = 1;
/* parse <fd> */
+ errno = 0;
fm->fd = (int) strtol(argv[0], &endptr, 10);
- if (*endptr) {
+ if (errno || *endptr) {
_early_log("Could not parse file descriptor: %s", argv[0]);
return 0;
}
@@ -288,8 +290,9 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
argv++;
/* parse <group_id> */
+ errno = 0;
fm->group_id = strtoull(argv[0], &endptr, 10);
- if (*endptr) {
+ if (*endptr || errno) {
_early_log("Could not parse group identifier: %s", argv[0]);
return 0;
}
@@ -332,8 +335,9 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
/* parse [<foreground>[<verbose>]] */
if (argc) {
+ errno = 0;
_foreground = (int) strtol(argv[0], &endptr, 10);
- if (*endptr) {
+ if (errno || *endptr) {
_early_log("Could not parse debug argument: %s.",
argv[0]);
return 0;
@@ -341,8 +345,9 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
argc--;
argv++;
if (argc) {
+ errno = 0;
_verbose = (int) strtol(argv[0], &endptr, 10);
- if (*endptr) {
+ if (errno || *endptr) {
_early_log("Could not parse verbose "
"argument: %s", argv[0]);
return 0;
diff --git a/daemons/lvmlockd/lvmlockd-sanlock.c b/daemons/lvmlockd/lvmlockd-sanlock.c
index e344cb1..aedd506 100644
--- a/daemons/lvmlockd/lvmlockd-sanlock.c
+++ b/daemons/lvmlockd/lvmlockd-sanlock.c
@@ -224,7 +224,10 @@ static int lock_lv_offset_from_args(char *lv_args, uint64_t *lock_lv_offset)
if (rv < 0)
return rv;
+ errno = 0;
*lock_lv_offset = strtoull(offset_str, NULL, 10);
+ if (errno)
+ return -1;
return 0;
}
diff --git a/lib/config/config.c b/lib/config/config.c
index c62b4c3..5c5916b 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -742,14 +742,16 @@ static struct dm_config_value *_get_def_array_values(struct cmd_context *cmd,
switch (toupper(token[0])) {
case 'I':
case 'B':
+ errno = 0;
v->v.i = strtoll(token + 1, &r, 10);
- if (*r)
+ if (errno || *r)
goto bad;
v->type = DM_CFG_INT;
break;
case 'F':
+ errno = 0;
v->v.f = strtod(token + 1, &r);
- if (*r)
+ if (errno || *r)
goto bad;
v->type = DM_CFG_FLOAT;
break;
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index 90e3405..d85effb 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -679,13 +679,23 @@ static struct dm_config_value *_type(struct parser *p)
switch (p->t) {
case TOK_INT:
v->type = DM_CFG_INT;
+ errno = 0;
v->v.i = strtoll(p->tb, NULL, 0); /* FIXME: check error */
+ if (errno) {
+ log_error("Failed to read int token.");
+ return NULL;
+ }
match(TOK_INT);
break;
case TOK_FLOAT:
v->type = DM_CFG_FLOAT;
+ errno = 0;
v->v.f = strtod(p->tb, NULL); /* FIXME: check error */
+ if (errno) {
+ log_error("Failed to read float token.");
+ return NULL;
+ }
match(TOK_FLOAT);
break;
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 0017ac3..20a0827 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -3185,6 +3185,7 @@ static const char *_tok_value_time(const struct dm_report_field_type *ft,
goto out;
}
+ errno = 0;
if (((t = strtoull(time_str, NULL, 10)) == ULLONG_MAX) && errno == ERANGE) {
log_error(_out_of_range_msg, time_str, ft->id);
goto out;
@@ -3555,6 +3556,7 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
if (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)
fs->value->next->v.i = (((const uint64_t *) rvw->value)[1]);
} else {
+ errno = 0;
if (((fs->value->v.i = strtoull(s, NULL, 10)) == ULLONG_MAX) &&
(errno == ERANGE)) {
log_error(_out_of_range_msg, s, field_id);
@@ -3573,6 +3575,7 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
if (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)
fs->value->next->v.d = (((const double *) rvw->value)[1]);
} else {
+ errno = 0;
fs->value->v.d = strtod(s, NULL);
if (errno == ERANGE) {
log_error(_out_of_range_msg, s, field_id);
@@ -3594,6 +3597,7 @@ static struct field_selection *_create_field_selection(struct dm_report *rh,
if (rvw->reserved->type & DM_REPORT_FIELD_RESERVED_VALUE_RANGE)
fs->value->next->v.i = (((const uint64_t *) rvw->value)[1]);
} else {
+ errno = 0;
fs->value->v.d = strtod(s, NULL);
if ((errno == ERANGE) || (fs->value->v.d < 0) || (fs->value->v.d > 100)) {
log_error(_out_of_range_msg, s, field_id);
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c
index 5cb7c2c..541823b 100644
--- a/libdm/libdm-stats.c
+++ b/libdm/libdm-stats.c
@@ -853,8 +853,9 @@ static int _stats_parse_histogram_spec(struct dm_stats *dms,
val_start = c;
endptr = NULL;
+ errno = 0;
this_val = strtoull(val_start, &endptr, 10);
- if (!endptr) {
+ if (errno || !endptr) {
log_error("Could not parse histogram boundary.");
goto bad;
}
@@ -1174,8 +1175,9 @@ static int _stats_parse_histogram(struct dm_pool *mem, char *hist_str,
val_start = c;
endptr = NULL;
+ errno = 0;
this_val = strtoull(val_start, &endptr, 10);
- if (!endptr) {
+ if (errno || !endptr) {
log_error("Could not parse histogram value.");
goto bad;
}
@@ -1992,8 +1994,9 @@ static int _stats_create_region(struct dm_stats *dms, uint64_t *region_id,
}
if (region_id) {
+ errno = 0;
*region_id = strtoull(resp, &endptr, 10);
- if (resp == endptr)
+ if (errno || resp == endptr)
goto_out;
}
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 5c5c14c..2eed39e 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -1270,8 +1270,9 @@ static int _message(CMD_ARGS)
argv++;
}
+ errno = 0;
sector = strtoull(argv[0], &endptr, 10);
- if (*endptr || endptr == argv[0]) {
+ if (errno || *endptr || endptr == argv[0]) {
err("invalid sector");
goto out;
}
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index d3523be..9cf2144 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -563,6 +563,7 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
if (!isdigit(*val))
return 0;
+ errno = 0;
v = strtod(val, &ptr);
if (*ptr == '.') {
@@ -571,13 +572,16 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
* Lets be toleran and retry with standard C locales
*/
if (setlocale(LC_ALL, "C")) {
+ errno = 0;
v = strtod(val, &ptr);
setlocale(LC_ALL, "");
}
}
- if (ptr == val)
+ if (ptr == val || errno) {
+ log_error("Can't parse size argument at '%c'.%s%s", ptr[0], (errno) ? " " :"", (errno) ? strerror(errno) : "");
return 0;
+ }
if (percent && *ptr == '%') {
if (!_get_percent_arg(av, ++ptr))
6 years, 9 months
master - lvmcmdline: validate size as double
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=94838b4df06c4f5a47c...
Commit: 94838b4df06c4f5a47c4cb51d5949d8e7b4684e7
Parent: 28e319ddc0cf3f60ee200a2c4a0bab971e1490c8
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 09:53:49 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:32:18 2017 +0200
lvmcmdline: validate size as double
Since we are reading size as (double) we can get way bigger
number then just plain int64. So to make this check actually
more valid and usable do a maxsize compare in 'double'.
---
WHATS_NEW | 1 +
tools/lvmcmdline.c | 3 ++-
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 477d4ea..48ec679 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.173 -
=================================
+ Improve --size args validation and report more detailed error message.
Initialize debugging mutex before any debug message in clvmd.
Log error instad of warn when noticing connection problem with lvmetad.
Fix memory leak in lvmetad when working with duplicates.
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 700593c..d3523be 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -617,7 +617,8 @@ static int _size_arg(struct cmd_context *cmd __attribute__((unused)),
} else
v *= factor;
- if ((uint64_t) v >= (UINT64_MAX >> SECTOR_SHIFT)) {
+ /* Compare (double) */
+ if (v >= (double) (UINT64_MAX >> SECTOR_SHIFT)) {
log_error("Size is too big (>=16EiB).");
return 0;
}
6 years, 9 months
master - clvmd: fix valgrind memory report
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=28e319ddc0cf3f60ee2...
Commit: 28e319ddc0cf3f60ee200a2c4a0bab971e1490c8
Parent: d7f92ea8ee71997027007088beaf342c625abb44
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 17 12:25:05 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:30:01 2017 +0200
clvmd: fix valgrind memory report
Avoid reading already released memory and do a continue directly.
Invalid read of size 1
at 0x1201B0: main_loop (clvmd.c:931)
by 0x11F640: main (clvmd.c:666)
Address 0x72ddef0 is 32 bytes inside a block of size 224 free'd
at 0x4C30D18: free (vg_replace_malloc.c:530)
by 0x54D6FD1: dm_free_wrapper (dbg_malloc.c:357)
by 0x122E6E: process_work_item (clvmd.c:2034)
by 0x123003: lvm_thread_fn (clvmd.c:2085)
by 0x590A3A8: start_thread (pthread_create.c:465)
by 0x5C3C7FE: clone (in /usr/lib64/libc-2.25.90.so)
Block was alloc'd at
at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
by 0x54D6EF1: dm_malloc_aux (dbg_malloc.c:286)
by 0x54D6F1C: dm_zalloc_aux (dbg_malloc.c:291)
by 0x54D6F96: dm_zalloc_wrapper (dbg_malloc.c:345)
by 0x11F89C: local_rendezvous_callback (clvmd.c:731)
by 0x1203D2: main_loop (clvmd.c:964)
by 0x11F640: main (clvmd.c:666)
---
daemons/clvmd/clvmd.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 0832f4a..7506dca 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -925,6 +925,7 @@ static void main_loop(int cmd_timeout)
/* Queue cleanup, this also frees the client struct */
add_to_lvmqueue(thisfd, NULL, 0, NULL);
+ continue;
}
if (thisfd->removeme)
6 years, 9 months
master - clvmd: fix valgrind warning
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d7f92ea8ee719970270...
Commit: d7f92ea8ee71997027007088beaf342c625abb44
Parent: ea96a9d68eadd3505330db73856418c253080dba
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 17 12:23:37 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:29:57 2017 +0200
clvmd: fix valgrind warning
Initialize mutex upfront any debugging and fix this report:
Mutex reinitialization: mutex 0x485d20, recursion count 0, owner 1.
at 0x4C38480: pthread_mutex_init_intercept (drd_pthread_intercepts.c:821)
by 0x4C38480: pthread_mutex_init (drd_pthread_intercepts.c:830)
by 0x11F359: main (clvmd.c:562)
mutex 0x485d20 was first observed at:
at 0x4C38F63: pthread_mutex_lock_intercept (drd_pthread_intercepts.c:885)
by 0x4C38F63: pthread_mutex_lock (drd_pthread_intercepts.c:898)
by 0x11E920: debuglog (clvmd.c:254)
by 0x11F1D8: main (clvmd.c:527)
---
WHATS_NEW | 1 +
daemons/clvmd/clvmd.c | 3 +--
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 818458c..477d4ea 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.173 -
=================================
+ Initialize debugging mutex before any debug message in clvmd.
Log error instad of warn when noticing connection problem with lvmetad.
Fix memory leak in lvmetad when working with duplicates.
Accept 'lvm -h' and 'lvm --help' as well as 'lvm help' for help.
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 881a931..0832f4a 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -124,7 +124,7 @@ static const size_t STACK_SIZE = 128 * 1024;
static pthread_attr_t stack_attr;
static int lvm_thread_exit = 0;
static pthread_mutex_t lvm_thread_mutex;
-static pthread_mutex_t _debuglog_mutex;
+static pthread_mutex_t _debuglog_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t lvm_thread_cond;
static pthread_barrier_t lvm_start_barrier;
static struct dm_list lvm_cmd_head;
@@ -559,7 +559,6 @@ int main(int argc, char *argv[])
exit(1);
}
pthread_mutex_init(&lvm_thread_mutex, NULL);
- pthread_mutex_init(&_debuglog_mutex, NULL);
pthread_cond_init(&lvm_thread_cond, NULL);
pthread_barrier_init(&lvm_start_barrier, NULL, 2);
init_lvhash();
6 years, 9 months
master - devcache: correct logging severity for connection
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ea96a9d68eadd350533...
Commit: ea96a9d68eadd3505330db73856418c253080dba
Parent: 919fa89482b85eb467ecd9561c89c1dfdaae7217
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 18:23:41 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:28:51 2017 +0200
devcache: correct logging severity for connection
Switch from warn to log_error since this generated
failing return code for command so printing log_error()
is mandatory.
Happens with i.e. pvscan --cache meets crashing lvmetad.
---
WHATS_NEW | 1 +
lib/cache/lvmetad.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 2fece12..818458c 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.173 -
=================================
+ Log error instad of warn when noticing connection problem with lvmetad.
Fix memory leak in lvmetad when working with duplicates.
Accept 'lvm -h' and 'lvm --help' as well as 'lvm help' for help.
Suppress error message from accept() on clean lvmetad shutdown.
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 531e01c..5490675 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -662,7 +662,7 @@ static int _lvmetad_handle_reply(daemon_reply reply, const char *id, const char
}
if (reply.error) {
- log_warn("WARNING: lvmetad cannot be used due to error: %s", strerror(reply.error));
+ log_error("lvmetad cannot be used due to error: %s", strerror(reply.error));
goto fail;
}
6 years, 9 months
master - lvmetad: fix memory leaks
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=919fa89482b85eb467e...
Commit: 919fa89482b85eb467ecd9561c89c1dfdaae7217
Parent: fb641c342343ac48cc623c8079900b1f4f395a69
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Jul 16 10:20:37 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 17 12:27:53 2017 +0200
lvmetad: fix memory leaks
Hash tables need to release no longer needed inserted data.
---
WHATS_NEW | 1 +
daemons/lvmetad/lvmetad-core.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 29678f4..2fece12 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.173 -
=================================
+ Fix memory leak in lvmetad when working with duplicates.
Accept 'lvm -h' and 'lvm --help' as well as 'lvm help' for help.
Suppress error message from accept() on clean lvmetad shutdown.
Tidy clvmd client list processing and fix segfaults.
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index af5d429..8910bd4 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -258,6 +258,21 @@ static void destroy_metadata_hashes(lvmetad_state *s)
dm_hash_iterate(n, s->pvid_to_pvmeta)
dm_config_destroy(dm_hash_get_data(s->pvid_to_pvmeta, n));
+ dm_hash_iterate(n, s->vgid_to_vgname)
+ dm_free(dm_hash_get_data(s->vgid_to_vgname, n));
+
+ dm_hash_iterate(n, s->vgname_to_vgid)
+ dm_free(dm_hash_get_data(s->vgname_to_vgid, n));
+
+ dm_hash_iterate(n, s->vgid_to_info)
+ dm_free(dm_hash_get_data(s->vgid_to_info, n));
+
+ dm_hash_iterate(n, s->device_to_pvid)
+ dm_free(dm_hash_get_data(s->device_to_pvid, n));
+
+ dm_hash_iterate(n, s->pvid_to_vgid)
+ dm_free(dm_hash_get_data(s->pvid_to_vgid, n));
+
dm_hash_destroy(s->pvid_to_pvmeta);
dm_hash_destroy(s->vgid_to_metadata);
dm_hash_destroy(s->vgid_to_vgname);
@@ -2111,6 +2126,8 @@ static response pv_found(lvmetad_state *s, request r)
DEBUGLOG(s, "pv_found ignore duplicate device %" PRIu64 " of existing PV for pvid %s",
arg_device, arg_pvid);
dm_config_destroy(new_pvmeta);
+ /* device_to_pvid no longer references prev_pvid_lookup */
+ dm_free((void*)prev_pvid_on_dev);
s->flags |= GLFL_DISABLE;
s->flags |= GLFL_DISABLE_REASON_DUPLICATES;
return reply_fail("Ignore duplicate PV");
6 years, 9 months