master - hash: add comment about multiple values
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=920a2819941144...
Commit: 920a28199411445f6489912efd5b8bfca00dc588
Parent: b6a45963e341d85196fcb070026180b3c62d608f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 16 11:01:53 2015 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Nov 16 11:02:25 2015 -0600
hash: add comment about multiple values
---
libdm/libdevmapper.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index a240d0e..2c3900b 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -1849,6 +1849,52 @@ void *dm_hash_get_data(struct dm_hash_table *t, struct dm_hash_node *n);
struct dm_hash_node *dm_hash_get_first(struct dm_hash_table *t);
struct dm_hash_node *dm_hash_get_next(struct dm_hash_table *t, struct dm_hash_node *n);
+/*
+ * dm_hash_insert() replaces the value of an existing
+ * entry with a matching key if one exists. Otherwise
+ * it adds a new entry.
+ *
+ * dm_hash_insert_withval() inserts a new entry if
+ * another entry with the same key already exists.
+ * val_len is the size of the data being inserted.
+ *
+ * If two entries with the same key exist,
+ * (added using dm_hash_insert_multival), then:
+ * . dm_hash_lookup() returns the first one it finds, and
+ * dm_hash_lookup_withval() returns the one with a matching
+ * val_len/val.
+ * . dm_hash_remove() removes the first one it finds, and
+ * dm_hash_remove_withval() removes the one with a matching
+ * val_len/val.
+ *
+ * If a single entry with a given key exists, and it has
+ * zero val_len, then:
+ * . dm_hash_lookup() returns it
+ * . dm_hash_lookup_withval(val_len=0) returns it
+ * . dm_hash_remove() removes it
+ * . dm_hash_remove_withval(val_len=0) removes it
+ *
+ * dm_hash_lookup_multival() is a single call that will
+ * both lookup a key's value and check if there is more
+ * than one entry with the given key.
+ *
+ * (It is not meant to retrieve all the entries with the
+ * given key. In the common case where a single entry exists
+ * for the key, it is useful to have a single call that will
+ * both look up the value and indicate if multiple values
+ * exist for the key.)
+ *
+ * dm_hash_lookup_multival:
+ * . If no entries exist, the function returns NULL, and
+ * the val2 arg is set to NULL.
+ * . If only one entry exists, the value of that entry is
+ * returned and the val2 arg is set to NULL.
+ * . If more than one entry exists, the value of one entry
+ * is returned and the val2 arg is set to the value of a
+ * second entry. Testing that the val2 arg is not NULL
+ * indicates that more than one entry exists.
+ */
+
void *dm_hash_lookup_withval(struct dm_hash_table *t, const char *key,
const void *val, uint32_t val_len);
void dm_hash_remove_withval(struct dm_hash_table *t, const char *key,
8 years, 5 months
master - libdm: fix check of pointer
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b6a45963e341d8...
Commit: b6a45963e341d85196fcb070026180b3c62d608f
Parent: 2a2487f02fb2ddb72106f922dcbf0ddda6959b2f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 16 11:51:43 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 13:10:24 2015 +0100
libdm: fix check of pointer
Ahhh being blind here - wanted to check the pointer before dereference
not a dereferenced one.
---
libdm/libdm-report.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 790f84f..2457335 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -2692,14 +2692,14 @@ static const char *_tok_value_string_list(const struct dm_report_field_type *ft,
dm_free(arr);
out:
*end = s;
- if (*sel_str_list)
+ if (sel_str_list)
*sel_str_list = ssl;
return s;
bad:
*end = s;
if (ssl)
dm_pool_free(mem, ssl);
- if (*sel_str_list)
+ if (sel_str_list)
*sel_str_list = NULL;
return s;
}
8 years, 5 months
master - libdm: better error reporting from dm_split_lvm_name
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2a2487f02fb2dd...
Commit: 2a2487f02fb2ddb72106f922dcbf0ddda6959b2f
Parent: 5d4f5873a99c3ebe52e671f828580d4cd045e456
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 16 13:07:36 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 13:09:53 2015 +0100
libdm: better error reporting from dm_split_lvm_name
Report errors from all error paths correctly.
Validate passed args before dereferencing them.
---
libdm/libdm-string.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c
index 9132832..79a969c 100644
--- a/libdm/libdm-string.c
+++ b/libdm/libdm-string.c
@@ -95,13 +95,18 @@ static char *_unquote(char *component)
int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
char **vgname, char **lvname, char **layer)
{
- if (mem && !(*vgname = dm_pool_strdup(mem, dmname))) {
- log_error("Failed to duplicate dmname.");
+ if (!vgname || !lvname || !layer) {
+ log_error(INTERNAL_ERROR "dm_split_lvm_name: vgname, lvname nor layer could be NULL.");
return 0;
}
- if (!*vgname)
+ if (mem && (!dmname || !(*vgname = dm_pool_strdup(mem, dmname)))) {
+ log_error("Failed to duplicate lvm name.");
return 0;
+ } else if (!*vgname) {
+ log_error("Missing lvm name for split.");
+ return 0;
+ }
_unquote(*layer = _unquote(*lvname = _unquote(*vgname)));
8 years, 5 months
master - coverity: model FD_ZERO
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5d4f5873a99c3e...
Commit: 5d4f5873a99c3ebe52e671f828580d4cd045e456
Parent: 8ebf2b061174daec744f9e361fa7ca28eb19ea2e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 13 20:11:52 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
coverity: model FD_ZERO
Coverity is not able to understand assembly language in
system's header file, so provide model for such macro.
Note: to really see model in-use: #nodef FD_ZERO model_FD_ZERO
need to go to coverity/config/user_nodefs.h
---
coverity/coverity_model.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/coverity/coverity_model.c b/coverity/coverity_model.c
index 947e9c8..d41c67c 100644
--- a/coverity/coverity_model.c
+++ b/coverity/coverity_model.c
@@ -29,19 +29,16 @@
*/
struct lv_segment;
-
-struct logical_volume {
- struct lv_segment *seg;
-};
+struct logical_volume;
struct lv_segment *first_seg(const struct logical_volume *lv)
{
- return lv->seg;
+ return ((struct lv_segment **)lv)[0];
}
struct lv_segment *last_seg(const struct logical_volume *lv)
{
- return lv->seg;
+ return ((struct lv_segment **)lv)[0];
}
/* simple_memccpy() from glibc */
@@ -58,6 +55,22 @@ void *memccpy(void *dest, const void *src, int c, size_t n)
}
/*
+ * 2 lines bellow needs to be placed in coverity/config/user_nodefs.h
+ * Not sure about any other way.
+ * Without them, coverity shows warning since x86 system header files
+ * are using inline assembly to reset fdset
+ */
+//#nodef FD_ZERO model_FD_ZERO
+//void model_FD_ZERO(void *fdset);
+
+void model_FD_ZERO(void *fdset)
+{
+ unsigned i;
+ for (i = 0; i < 1024 / 8 / sizeof(int); ++i)
+ ((int*)fdset)[i];
+}
+
+/*
* Added extra pointer check to not need these models,
* for now just keep then in file
*/
8 years, 5 months
master - debug: lvconvert add missing display_lvname
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8ebf2b061174da...
Commit: 8ebf2b061174daec744f9e361fa7ca28eb19ea2e
Parent: 0f4d96f1bd7c30e29cd9d10b555d4ce0b553f5b3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 13 23:38:34 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
debug: lvconvert add missing display_lvname
Add missing display_lvname in _lvconvert_merge_thin_snapshot().
Also when we detect missing origin, report Internal error,
which would likely be the primary fault here
(and avoid dereft of NULL origin as noticed by Coverity).
---
tools/lvconvert.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 335f6a4..3cfd915 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -2238,8 +2238,8 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
struct logical_volume *origin = snap_seg->origin;
if (!origin) {
- log_error("\"%s\" is not a mergeable logical volume.",
- lv->name);
+ log_error("%s is not a mergeable logical volume.",
+ display_lvname(lv));
return 0;
}
@@ -2251,9 +2251,12 @@ static int _lvconvert_merge_thin_snapshot(struct cmd_context *cmd,
}
if (lv_is_external_origin(origin)) {
- origin = origin_from_cow(lv);
- log_error("%s is read-only external origin %s.",
- display_lvname(lv), display_lvname(origin));
+ if (!(origin = origin_from_cow(lv)))
+ log_error(INTERNAL_ERROR "%s is missing origin.",
+ display_lvname(lv));
+ else
+ log_error("%s is read-only external origin %s.",
+ display_lvname(lv), display_lvname(origin));
return 0;
}
8 years, 5 months
master - cleanup: just alphabetically sort links
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0f4d96f1bd7c30...
Commit: 0f4d96f1bd7c30e29cd9d10b555d4ce0b553f5b3
Parent: dccbc3b621cdac035802cb9f60438a389acadcad
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Nov 14 22:14:37 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
cleanup: just alphabetically sort links
---
include/.symlinks.in | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 9b97eb4..98d6804 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -1,15 +1,13 @@
@top_srcdir(a)/daemons/clvmd/clvm.h
@top_srcdir(a)/daemons/dmeventd/libdevmapper-event.h
@top_srcdir(a)/daemons/lvmetad/lvmetad-client.h
+@top_srcdir(a)/daemons/lvmlockd/lvmlockd-client.h
@top_srcdir(a)/daemons/lvmpolld/lvmpolld-protocol.h
@top_srcdir(a)/daemons/lvmpolld/polling_ops.h
-@top_srcdir(a)/daemons/lvmlockd/lvmlockd-client.h
-@top_srcdir(a)/liblvm/lvm2app.h
@top_srcdir(a)/lib/activate/activate.h
@top_srcdir(a)/lib/activate/targets.h
@top_srcdir(a)/lib/cache/lvmcache.h
@top_srcdir(a)/lib/cache/lvmetad.h
-@top_srcdir(a)/lib/locking/lvmlockd.h
@top_srcdir(a)/lib/commands/toolcontext.h
@top_srcdir(a)/lib/config/config.h
@top_srcdir(a)/lib/config/config_settings.h
@@ -19,8 +17,8 @@
@top_srcdir(a)/lib/device/dev-cache.h
@top_srcdir(a)/lib/device/dev-ext-udev-constants.h
@top_srcdir(a)/lib/device/dev-type.h
-@top_srcdir(a)/lib/device/device.h
@top_srcdir(a)/lib/device/device-types.h
+@top_srcdir(a)/lib/device/device.h
@top_srcdir(a)/lib/display/display.h
@top_srcdir(a)/lib/filters/filter.h
@top_srcdir(a)/lib/format1/format1.h
@@ -31,20 +29,19 @@
@top_srcdir(a)/lib/format_text/text_import.h
@top_srcdir(a)/lib/label/label.h
@top_srcdir(a)/lib/locking/locking.h
+@top_srcdir(a)/lib/locking/lvmlockd.h
@top_srcdir(a)/lib/log/log.h
@top_srcdir(a)/lib/log/lvm-logging.h
@top_srcdir(a)/lib/lvmpolld/lvmpolld-client.h
@top_srcdir(a)/lib/lvmpolld/polldaemon.h
@top_srcdir(a)/lib/metadata/lv.h
@top_srcdir(a)/lib/metadata/lv_alloc.h
-@top_srcdir(a)/lib/metadata/metadata.h
@top_srcdir(a)/lib/metadata/metadata-exported.h
+@top_srcdir(a)/lib/metadata/metadata.h
@top_srcdir(a)/lib/metadata/pv.h
@top_srcdir(a)/lib/metadata/pv_alloc.h
@top_srcdir(a)/lib/metadata/segtype.h
@top_srcdir(a)/lib/metadata/vg.h
-@top_srcdir(a)/lib/mm/memlock.h
-@top_srcdir(a)/lib/mm/xlate.h
@top_srcdir(a)/lib/misc/crc.h
@top_srcdir(a)/lib/misc/intl.h
@top_srcdir(a)/lib/misc/last-path-component.h
@@ -53,25 +50,28 @@
@top_srcdir(a)/lib/misc/lvm-file.h
@top_srcdir(a)/lib/misc/lvm-flock.h
@top_srcdir(a)/lib/misc/lvm-globals.h
+@top_srcdir(a)/lib/misc/lvm-percent.h
@top_srcdir(a)/lib/misc/lvm-signal.h
@top_srcdir(a)/lib/misc/lvm-string.h
-@top_srcdir(a)/lib/misc/lvm-percent.h
@top_srcdir(a)/lib/misc/lvm-wrappers.h
@top_srcdir(a)/lib/misc/sharedlib.h
@top_srcdir(a)/lib/misc/util.h
+@top_srcdir(a)/lib/mm/memlock.h
+@top_srcdir(a)/lib/mm/xlate.h
@top_srcdir(a)/lib/properties/prop_common.h
@top_srcdir(a)/lib/report/properties.h
@top_srcdir(a)/lib/report/report.h
@top_srcdir(a)/lib/uuid/uuid.h
+@top_srcdir(a)/libdaemon/client/config-util.h
@top_srcdir(a)/libdaemon/client/daemon-client.h
@top_srcdir(a)/libdaemon/client/daemon-io.h
-@top_srcdir(a)/libdaemon/client/config-util.h
@top_srcdir(a)/libdm/libdevmapper.h
@top_srcdir(a)/libdm/misc/dm-ioctl.h
-@top_srcdir(a)/libdm/misc/dm-logging.h
@top_srcdir(a)/libdm/misc/dm-log-userspace.h
+@top_srcdir(a)/libdm/misc/dm-logging.h
@top_srcdir(a)/libdm/misc/dmlib.h
@top_srcdir(a)/libdm/misc/kdev_t.h
+@top_srcdir(a)/liblvm/lvm2app.h
@top_srcdir(a)/po/pogen.h
@top_srcdir(a)/tools/lvm2cmd.h
@top_srcdir(a)/tools/tool.h
8 years, 5 months
master - cleanup: simplify dev_cache_exit
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=dccbc3b621cdac...
Commit: dccbc3b621cdac035802cb9f60438a389acadcad
Parent: 5a4676fea9808f348b9bbda46c03dce298eef6e5
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Dec 6 23:56:14 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
cleanup: simplify dev_cache_exit
Just set whole _cache struct into unitialized state just
like with lib init start usage.
Lists are initialized with dev_cache_init().
---
lib/device/dev-cache.c | 16 +++-------------
1 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 185b394..7626ceb 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -819,23 +819,13 @@ int dev_cache_exit(void)
if ((num_open = _check_for_open_devices(1)) > 0)
log_error(INTERNAL_ERROR "%d device(s) were left open and have been closed.", num_open);
- if (_cache.preferred_names_matcher)
- _cache.preferred_names_matcher = NULL;
-
- if (_cache.mem) {
+ if (_cache.mem)
dm_pool_destroy(_cache.mem);
- _cache.mem = NULL;
- }
- if (_cache.names) {
+ if (_cache.names)
dm_hash_destroy(_cache.names);
- _cache.names = NULL;
- }
- _cache.devices = NULL;
- _cache.has_scanned = 0;
- dm_list_init(&_cache.dirs);
- dm_list_init(&_cache.files);
+ memset(&_cache, 0, sizeof(_cache));
return (!num_open);
}
8 years, 5 months
master - cleanup: add _free on error path
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5a4676fea9808f...
Commit: 5a4676fea9808f348b9bbda46c03dce298eef6e5
Parent: c3b292a4a9924d00da421d66d8281f8cd8efc3a9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Dec 6 23:55:25 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
cleanup: add _free on error path
Just like with failing allocation above also _free(dev).
TODO: rework this to always use mempool and drop unneeded
comlexity we have in this function.
---
lib/device/dev-cache.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index b9d4271..185b394 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -115,6 +115,7 @@ struct device *dev_create_file(const char *filename, struct device *dev,
}
if (!(alias->str = _strdup(filename))) {
log_error("filename strdup failed");
+ _free(dev);
return NULL;
}
}
8 years, 5 months
master - format-text: ensure no division by zero
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c3b292a4a9924d...
Commit: c3b292a4a9924d00da421d66d8281f8cd8efc3a9
Parent: 193e7f5973e8a0ff7a4f8ebc542fcb9853a30d0d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 16 01:04:21 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
format-text: ensure no division by zero
Coverity likes here to be 100% sure no division by zero is possible.
Add check for alignment !=0 which is made on other code paths here.
---
lib/format_text/format-text.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index d4f2c89..58d6209 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -2119,7 +2119,7 @@ static int _text_pv_add_metadata_area(const struct format_type *fmt,
}
/* Align MDA0 end position with given alignment offset if possible. */
- if (alignment_offset &&
+ if (alignment && alignment_offset &&
(((mda_start + mda_size) % alignment) == 0)) {
tmp_mda_size = mda_size + alignment_offset;
if (mda_start + tmp_mda_size <= limit)
8 years, 5 months
master - config: check vdef pointer before dereference
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=193e7f5973e8a0...
Commit: 193e7f5973e8a0ff7a4f8ebc542fcb9853a30d0d
Parent: 96d73dc6ea3016a80b5041ee0252e8473481b91e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 16 00:42:29 2015 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 16 01:16:11 2015 +0100
config: check vdef pointer before dereference
Coverity notices we check for v_def != NULL elsewhere, so it thinks
it may be possibly NULL also here.
---
lib/config/config.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 1298b40..d69f1f7 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -891,7 +891,7 @@ static int _check_value_differs_from_default(struct cft_check_handle *handle,
}
break;
case DM_CFG_EMPTY_ARRAY:
- diff = v_def->type != DM_CFG_EMPTY_ARRAY;
+ diff = (v_def && (v_def->type != DM_CFG_EMPTY_ARRAY));
break;
default:
log_error(INTERNAL_ERROR "inconsistent state reached in _check_value_differs_from_default");
8 years, 5 months