master - coverity: check vg->lvm1_system_id is not NULL before calling strncmp with that
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bcd193cb182188...
Commit: bcd193cb182188e7c45e705212c4cd6da10fd4f0
Parent: 1f3d04cddf5a447de9bfb81ed22d0ccbe58e82fc
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 10:16:45 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 10:16:45 2015 +0200
coverity: check vg->lvm1_system_id is not NULL before calling strncmp with that
lib/format1/import-export.c:167: var_deref_model: Passing null pointer "vg->lvm1_system_id" to "strncmp", which dereferences it.
---
lib/format1/import-export.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c
index 275583d..b62cd67 100644
--- a/lib/format1/import-export.c
+++ b/lib/format1/import-export.c
@@ -164,7 +164,7 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute__((unused
/* Is VG already exported or being exported? */
if (vg && vg_is_exported(vg)) {
/* Does system_id need setting? */
- if ((vg->lvm1_system_id && !*vg->lvm1_system_id) ||
+ if (vg->lvm1_system_id || !*vg->lvm1_system_id ||
strncmp(vg->lvm1_system_id, EXPORTED_TAG,
sizeof(EXPORTED_TAG) - 1)) {
if (!generate_lvm1_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG))
8 years, 8 months
master - coverity: variable init must be done before its use
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1f3d04cddf5a44...
Commit: 1f3d04cddf5a447de9bfb81ed22d0ccbe58e82fc
Parent: c78033233ab03749b37c01454310ac0c29fd5af8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 09:51:16 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 09:51:16 2015 +0200
coverity: variable init must be done before its use
tools/polldaemon.c:465: uninit_use_in_call: Using uninitialized value "id.vg_name" when calling "print_log".
tools/polldaemon.c:465: uninit_use_in_call: Using uninitialized value "id.lv_name" when calling "print_log".
---
tools/polldaemon.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index 4527efb..83928b7 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -461,13 +461,14 @@ static int _lvmpolld_init_poll_vg(struct cmd_context *cmd, const char *vgname,
if (!id.display_name && !lpdp->parms->aborting)
continue;
+ id.vg_name = lv->vg->name;
+ id.lv_name = lv->name;
+
if (!*lv->lvid.s) {
log_print_unless_silent("Missing LV uuid within: %s/%s", id.vg_name, id.lv_name);
continue;
}
- id.vg_name = lv->vg->name;
- id.lv_name = lv->name;
id.uuid = lv->lvid.s;
r = lvmpolld_poll_init(cmd, &id, lpdp->parms);
8 years, 8 months
master - coverity: return value check in lvmlockd-dlm
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c78033233ab037...
Commit: c78033233ab03749b37c01454310ac0c29fd5af8
Parent: 83541123c81b8ff129175963866d9fbd01c21e38
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 09:49:23 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 09:49:29 2015 +0200
coverity: return value check in lvmlockd-dlm
daemons/lvmlockd/lvmlockd-dlm.c:647: check_return: Calling "closedir" without checking return value (as is done elsewhere 13 out of 14 times).
---
daemons/lvmlockd/lvmlockd-dlm.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c
index f1b060a..c96866b 100644
--- a/daemons/lvmlockd/lvmlockd-dlm.c
+++ b/daemons/lvmlockd/lvmlockd-dlm.c
@@ -616,6 +616,7 @@ int lm_unlock_dlm(struct lockspace *ls, struct resource *r,
int lm_get_lockspaces_dlm(struct list_head *ls_rejoin)
{
+ static const char closedir_err_msg[] = "lm_get_lockspace_dlm: closedir failed";
struct lockspace *ls;
struct dirent *de;
DIR *ls_dir;
@@ -632,7 +633,7 @@ int lm_get_lockspaces_dlm(struct list_head *ls_rejoin)
if (!(ls = alloc_lockspace())) {
if (closedir(ls_dir))
- log_error("lm_get_lockspace_dlm: closedir failed");
+ log_error(closedir_err_msg);
return -ENOMEM;
}
@@ -642,7 +643,8 @@ int lm_get_lockspaces_dlm(struct list_head *ls_rejoin)
list_add_tail(&ls->list, ls_rejoin);
}
- closedir(ls_dir);
+ if (closedir(ls_dir))
+ log_error(closedir_err_msg);
return 0;
}
8 years, 8 months
master - coverity: fix cppcheck warnings
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=83541123c81b8f...
Commit: 83541123c81b8ff129175963866d9fbd01c21e38
Parent: 46e6b2b86e58e081fa40e9cc724f09f03ecf843e
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 09:33:55 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 09:33:55 2015 +0200
coverity: fix cppcheck warnings
/lib/log/log.c:88: warning[invalidScanfArgType_int]: %llu in format string (no. 2) requires 'unsigned long long *' but the argument type is 'long long *'.
daemons/lvmlockd/lvmlockd-core.c:791: error[uninitstring]: Dangerous usage of 'version' (strncpy doesn't always null-terminate it).
---
daemons/lvmlockd/lvmlockd-core.c | 1 +
lib/log/log.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 2f470f5..266339d 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -787,6 +787,7 @@ int version_from_args(char *args, unsigned int *major, unsigned int *minor, unsi
char *n, *d1, *d2;
strncpy(version, args, MAX_ARGS);
+ version[MAX_ARGS] = '\0';
n = strstr(version, ":");
if (n)
diff --git a/lib/log/log.c b/lib/log/log.c
index 9929090..bd11363 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -69,7 +69,7 @@ void init_log_file(const char *log_file, int append)
static const char statfile[] = "/proc/self/stat";
const char *env;
int pid;
- long long starttime;
+ unsigned long long starttime;
FILE *st;
int i = 0;
8 years, 8 months
master - coverity: fix possible resource leak in lvmpolld-core
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=46e6b2b86e58e0...
Commit: 46e6b2b86e58e081fa40e9cc724f09f03ecf843e
Parent: 6ac5689ce4d4f86c4b3985d73a0fdb4af04c298d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 09:25:40 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 09:25:47 2015 +0200
coverity: fix possible resource leak in lvmpolld-core
/daemons/lvmpolld/lvmpolld-core.c:573: leaked_storage: Variable "cmdargv" going out of scope leaks the storage it points to.
---
daemons/lvmpolld/lvmpolld-core.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmpolld/lvmpolld-core.c b/daemons/lvmpolld/lvmpolld-core.c
index 1da2da2..1402373 100644
--- a/daemons/lvmpolld/lvmpolld-core.c
+++ b/daemons/lvmpolld/lvmpolld-core.c
@@ -566,6 +566,8 @@ static struct lvmpolld_lv *construct_pdlv(request req, struct lvmpolld_state *ls
return NULL;
}
+ pdlv->cmdargv = cmdargv;
+
cmdenvp = cmdenvp_ctr(pdlv);
if (!cmdenvp) {
pdlv_destroy(pdlv);
@@ -573,7 +575,6 @@ static struct lvmpolld_lv *construct_pdlv(request req, struct lvmpolld_state *ls
return NULL;
}
- pdlv->cmdargv = cmdargv;
pdlv->cmdenvp = cmdenvp;
return pdlv;
8 years, 8 months
master - report: also recognize variants without underscores for <prefix>_all fields
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6ac5689ce4d4f8...
Commit: 6ac5689ce4d4f86c4b3985d73a0fdb4af04c298d
Parent: d11f8d42287025ff8584b9d6f1d5e70a0d78371b
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Aug 4 09:03:31 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 4 09:03:31 2015 +0200
report: also recognize variants without underscores for <prefix>_all fields
For example: "pvs -o pv_all" and pvs -o pvall" are same.
---
libdm/libdm-report.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 5b94311..225da90 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -876,15 +876,20 @@ static void _all_match_combine(const struct dm_report_object_type *types,
const char *field, size_t flen,
uint32_t *report_types)
{
+ char field_canon[DM_REPORT_FIELD_TYPE_ID_LEN];
const struct dm_report_object_type *t;
size_t prefix_len;
+ if (!_get_canonical_field_name(field, flen, field_canon, DM_REPORT_FIELD_TYPE_ID_LEN, NULL))
+ return;
+ flen = strlen(field_canon);
+
for (t = types; t->data_fn; t++) {
- prefix_len = strlen(t->prefix);
+ prefix_len = strlen(t->prefix) - 1;
- if (!strncasecmp(t->prefix, field, prefix_len) &&
+ if (!strncasecmp(t->prefix, field_canon, prefix_len) &&
((unprefixed_all_matched && (flen == prefix_len)) ||
- (!strncasecmp(field + prefix_len, "all", 3) &&
+ (!strncasecmp(field_canon + prefix_len, "all", 3) &&
(flen == prefix_len + 3))))
*report_types |= t->id;
}
8 years, 8 months
master - lvmlockd: automatically remove the dlm global lockspace
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d11f8d42287025...
Commit: d11f8d42287025ff8584b9d6f1d5e70a0d78371b
Parent: 71dbe47619794ed673a892f533c348a472411195
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Jul 31 16:45:43 2015 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Aug 3 10:23:01 2015 -0500
lvmlockd: automatically remove the dlm global lockspace
The dlm global lockspace is automatically added when the
first dlm VG lockspace is added. Reverse this by removing
the dlm global lockspace after the last dlm VG lockspace
is removed. (Remove old non-working code that did this
based on an old command that could explicitly add/remove
the dlm global lockspace.)
---
daemons/lvmlockd/lvmlockd-core.c | 47 ++++++++-------------------------
daemons/lvmlockd/lvmlockd-dlm.c | 4 +--
daemons/lvmlockd/lvmlockd-internal.h | 4 +--
3 files changed, 14 insertions(+), 41 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index b299050..2f470f5 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -2506,18 +2506,8 @@ static int add_dlm_global_lockspace(struct action *act)
if (gl_running_dlm)
return -EEXIST;
-
gl_running_dlm = 1;
- /* Keep track of whether we automatically added
- the global ls, so we know to automatically
- remove it. */
-
- if (act)
- gl_auto_dlm = 0;
- else
- gl_auto_dlm = 1;
-
/*
* There's a short period after which a previous gl lockspace thread
* has set gl_running_dlm = 0, but before its ls struct has been
@@ -2526,11 +2516,9 @@ static int add_dlm_global_lockspace(struct action *act)
*/
rv = add_lockspace_thread(gl_lsname_dlm, NULL, NULL, LD_LM_DLM, NULL, act);
-
if (rv < 0) {
log_error("add_dlm_global_lockspace add_lockspace_thread %d", rv);
gl_running_dlm = 0;
- gl_auto_dlm = 0;
}
return rv;
@@ -2583,28 +2571,12 @@ out:
}
/*
- * When the first dlm lockspace is added for a vg,
- * automatically add a separate dlm lockspace for the
- * global lock if it hasn't been done explicitly.
- * This is to make the dlm global lockspace work similarly to
- * the sanlock global lockspace, which is "automatic" by
- * nature of being one of the vg lockspaces.
+ * When the first dlm lockspace is added for a vg, automatically add a separate
+ * dlm lockspace for the global lock.
*
- * For sanlock, a separate lockspace is not used for
- * the global lock, but the gl lock lives in a vg
- * lockspace, (although it's recommended to create a
+ * For sanlock, a separate lockspace is not used for the global lock, but the
+ * gl lock lives in a vg lockspace, (although it's recommended to create a
* special vg dedicated to holding the gl).
- *
- * N.B. for dlm, if this is an add+WAIT action for a vg
- * lockspace, and this triggered the automatic addition
- * of the global lockspace, then the action may complete
- * for the vg ls add, while the gl ls add is still in
- * progress. If the caller wants to ensure that the
- * gl ls add is complete, they should explicitly add+WAIT
- * the gl ls.
- *
- * If this function returns and error, the caller
- * will queue the act with that error for the client.
*/
static int add_lockspace(struct action *act)
@@ -2614,6 +2586,11 @@ static int add_lockspace(struct action *act)
memset(ls_name, 0, sizeof(ls_name));
+ /*
+ * FIXME: I don't think this is used any more.
+ * Remove it, or add the ability to start the global
+ * dlm lockspace using lvmlockctl?
+ */
if (act->rt == LD_RT_GL) {
if (gl_use_dlm) {
rv = add_dlm_global_lockspace(act);
@@ -2697,13 +2674,13 @@ static int rem_lockspace(struct action *act)
pthread_mutex_unlock(&lockspaces_mutex);
/*
- * If the dlm global lockspace was automatically added when
- * the first dlm vg lockspace was added, then reverse that
+ * The dlm global lockspace was automatically added when
+ * the first dlm vg lockspace was added, now reverse that
* by automatically removing the dlm global lockspace when
* the last dlm vg lockspace is removed.
*/
- if (rt == LD_RT_VG && gl_use_dlm && gl_auto_dlm)
+ if (rt == LD_RT_VG && gl_use_dlm)
rem_dlm_global_lockspace();
return 0;
diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c
index eaa2657..f1b060a 100644
--- a/daemons/lvmlockd/lvmlockd-dlm.c
+++ b/daemons/lvmlockd/lvmlockd-dlm.c
@@ -247,10 +247,8 @@ int lm_rem_lockspace_dlm(struct lockspace *ls, int free_vg)
free(lmd);
ls->lm_data = NULL;
- if (!strcmp(ls->name, gl_lsname_dlm)) {
+ if (!strcmp(ls->name, gl_lsname_dlm))
gl_running_dlm = 0;
- gl_auto_dlm = 0;
- }
return 0;
}
diff --git a/daemons/lvmlockd/lvmlockd-internal.h b/daemons/lvmlockd/lvmlockd-internal.h
index 1ecb5dc..78ae88d 100644
--- a/daemons/lvmlockd/lvmlockd-internal.h
+++ b/daemons/lvmlockd/lvmlockd-internal.h
@@ -307,6 +307,7 @@ static inline int list_empty(const struct list_head *head)
* or when disable_gl matches.
*/
+EXTERN int gl_running_dlm;
EXTERN int gl_type_static;
EXTERN int gl_use_dlm;
EXTERN int gl_use_sanlock;
@@ -315,9 +316,6 @@ EXTERN pthread_mutex_t gl_type_mutex;
EXTERN char gl_lsname_dlm[MAX_NAME+1];
EXTERN char gl_lsname_sanlock[MAX_NAME+1];
-EXTERN int gl_running_dlm;
-EXTERN int gl_auto_dlm;
-
EXTERN int daemon_test; /* run as much as possible without a live lock manager */
EXTERN int daemon_debug;
EXTERN int daemon_host_id;
8 years, 8 months
master - report: update comment for _is_same_field fn
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=71dbe47619794e...
Commit: 71dbe47619794ed673a892f533c348a472411195
Parent: a5b476a7d3ffd06fa8124395857b4dcca32d612b
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 3 16:47:02 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 3 16:47:02 2015 +0200
report: update comment for _is_same_field fn
---
libdm/libdm-report.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 64ba033..5b94311 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -845,9 +845,10 @@ static int _get_canonical_field_name(const char *field,
}
/*
- * Compare name1 against name2 or prefix plus name2
- * name2 is not necessarily null-terminated.
- * len2 is the length of name2.
+ * Compare canonical_name1 against canonical_name2 or prefix
+ * plus canonical_name2. Canonical name is a name where all
+ * superfluous characters are removed (underscores for now).
+ * Both names are always null-terminated.
*/
static int _is_same_field(const char *canonical_name1, const char *canonical_name2,
const char *prefix)
8 years, 8 months
master - report: recognize report field name variants without any underscores too
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a5b476a7d3ffd0...
Commit: a5b476a7d3ffd06fa8124395857b4dcca32d612b
Parent: b3997469b56eb54f78fc84a8d9fde285ffd53c56
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 3 16:29:50 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 3 16:29:50 2015 +0200
report: recognize report field name variants without any underscores too
Whenver reporting field name is registered with libdevmapper and if
the field name contains any number of underscores ('_'), libdm
can now automatically recognize any of its variant without any
underscores used.
For example:
..for underscores in prefixes:
pvs -o pv_name
pvs -o name
pvs -o pvname (newly recognized besides pvname)
..for underscores in the name:
lvs -o cache_mode
lvs -o cachemode
..or even multiple underscores:
pvs -o pv___na___me
It's all variant of the same field name.
---
WHATS_NEW_DM | 1 +
libdm/libdm-report.c | 92 ++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 82 insertions(+), 11 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 2a006db..57cfce4 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.104 -
=================================
+ Recognize report field name variants without any underscores too.
Add dmsetup --interval and --count to repeat reports at specified intervals.
Add report interval and waiting functions to libdevmapper.
Add dm_timestamp functions to libdevmapper.
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 5ae994d..64ba033 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -55,6 +55,7 @@ struct dm_report {
/* Array of field definitions */
const struct dm_report_field_type *fields;
+ const char **canonical_field_ids;
const struct dm_report_object_type *types;
/* To store caller private data */
@@ -816,25 +817,51 @@ static struct field_properties * _add_field(struct dm_report *rh,
return fp;
}
+static int _get_canonical_field_name(const char *field,
+ size_t flen,
+ char *canonical_field,
+ size_t fcanonical_len,
+ int *differs)
+{
+ size_t i;
+ int diff = 0;
+
+ for (i = 0; *field && flen; field++, flen--) {
+ if (*field == '_') {
+ diff = 1;
+ continue;
+ }
+ if (i >= fcanonical_len) {
+ log_error("%s: field name too long", field);
+ return 0;
+ }
+ canonical_field[i++] = *field;
+ }
+
+ canonical_field[i] = '\0';
+ if (differs)
+ *differs = diff;
+ return 1;
+}
+
/*
* Compare name1 against name2 or prefix plus name2
* name2 is not necessarily null-terminated.
* len2 is the length of name2.
*/
-static int _is_same_field(const char *name1, const char *name2,
- size_t len2, const char *prefix)
+static int _is_same_field(const char *canonical_name1, const char *canonical_name2,
+ const char *prefix)
{
size_t prefix_len;
/* Exact match? */
- if (!strncasecmp(name1, name2, len2) && strlen(name1) == len2)
+ if (!strcasecmp(canonical_name1, canonical_name2))
return 1;
/* Match including prefix? */
- prefix_len = strlen(prefix);
- if (!strncasecmp(prefix, name1, prefix_len) &&
- !strncasecmp(name1 + prefix_len, name2, len2) &&
- strlen(name1) == prefix_len + len2)
+ prefix_len = strlen(prefix) - 1;
+ if (!strncasecmp(prefix, canonical_name1, prefix_len) &&
+ !strcasecmp(canonical_name1 + prefix_len, canonical_name2))
return 1;
return 0;
@@ -901,13 +928,17 @@ static int _add_all_fields(struct dm_report *rh, uint32_t type)
static int _get_field(struct dm_report *rh, const char *field, size_t flen,
uint32_t *f_ret, int *implicit)
{
+ char field_canon[DM_REPORT_FIELD_TYPE_ID_LEN];
uint32_t f;
if (!flen)
return 0;
+ if (!_get_canonical_field_name(field, flen, field_canon, DM_REPORT_FIELD_TYPE_ID_LEN, NULL))
+ return 0;
+
for (f = 0; _implicit_report_fields[f].report_fn; f++) {
- if (_is_same_field(_implicit_report_fields[f].id, field, flen, rh->field_prefix)) {
+ if (_is_same_field(_implicit_report_fields[f].id, field_canon, rh->field_prefix)) {
*f_ret = f;
*implicit = 1;
return 1;
@@ -915,7 +946,7 @@ static int _get_field(struct dm_report *rh, const char *field, size_t flen,
}
for (f = 0; rh->fields[f].report_fn; f++) {
- if (_is_same_field(rh->fields[f].id, field, flen, rh->field_prefix)) {
+ if (_is_same_field(rh->canonical_field_ids[f], field_canon, rh->field_prefix)) {
*f_ret = f;
*implicit = 0;
return 1;
@@ -994,6 +1025,7 @@ static int _add_sort_key(struct dm_report *rh, uint32_t field_num, int implicit,
static int _key_match(struct dm_report *rh, const char *key, size_t len,
unsigned report_type_only)
{
+ char key_canon[DM_REPORT_FIELD_TYPE_ID_LEN];
uint32_t f;
uint32_t flags;
@@ -1016,12 +1048,15 @@ static int _key_match(struct dm_report *rh, const char *key, size_t len,
return 0;
}
+ if (!_get_canonical_field_name(key, len, key_canon, DM_REPORT_FIELD_TYPE_ID_LEN, NULL))
+ return 0;
+
for (f = 0; _implicit_report_fields[f].report_fn; f++)
- if (_is_same_field(_implicit_report_fields[f].id, key, len, rh->field_prefix))
+ if (_is_same_field(_implicit_report_fields[f].id, key_canon, rh->field_prefix))
return _add_sort_key(rh, f, 1, flags, report_type_only);
for (f = 0; rh->fields[f].report_fn; f++)
- if (_is_same_field(rh->fields[f].id, key, len, rh->field_prefix))
+ if (_is_same_field(rh->canonical_field_ids[f], key_canon, rh->field_prefix))
return _add_sort_key(rh, f, 0, flags, report_type_only);
return 0;
@@ -1129,6 +1164,36 @@ static int _help_requested(struct dm_report *rh)
return 0;
}
+static int _canonicalize_field_ids(struct dm_report *rh)
+{
+ size_t registered_field_count = 0, i;
+ char canonical_field[DM_REPORT_FIELD_TYPE_ID_LEN];
+ char *canonical_field_dup;
+ int differs;
+
+ while (*rh->fields[registered_field_count].id)
+ registered_field_count++;
+
+ if (!(rh->canonical_field_ids = dm_pool_alloc(rh->mem, registered_field_count * sizeof(const char *)))) {
+ log_error("_canonicalize_field_ids: dm_pool_alloc failed");
+ return 0;
+ }
+
+ for (i = 0; i < registered_field_count; i++) {
+ if (!_get_canonical_field_name(rh->fields[i].id, strlen(rh->fields[i].id),
+ canonical_field, DM_REPORT_FIELD_TYPE_ID_LEN, &differs))
+ return_0;
+
+ if (differs) {
+ canonical_field_dup = dm_pool_strdup(rh->mem, canonical_field);
+ rh->canonical_field_ids[i] = canonical_field_dup;
+ } else
+ rh->canonical_field_ids[i] = rh->fields[i].id;
+ }
+
+ return 1;
+}
+
struct dm_report *dm_report_init(uint32_t *report_types,
const struct dm_report_object_type *types,
const struct dm_report_field_type *fields,
@@ -1189,6 +1254,11 @@ struct dm_report *dm_report_init(uint32_t *report_types,
return NULL;
}
+ if (!_canonicalize_field_ids(rh)) {
+ dm_report_free(rh);
+ return NULL;
+ }
+
/*
* To keep the code needed to add the "all" field to a minimum, we parse
* the field lists twice. The first time we only update the report type.
8 years, 8 months
master - toolcontext: do not set cmd->initialized_connections = 0 on destroy_toolcontext
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b3997469b56eb5...
Commit: b3997469b56eb54f78fc84a8d9fde285ffd53c56
Parent: 519c309952245a0d6221a3297399a310acdb8144
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 3 16:17:09 2015 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 3 16:17:17 2015 +0200
toolcontext: do not set cmd->initialized_connections = 0 on destroy_toolcontext
The whole cmd context is freed completely in destroy_toolcontext, so do
not write to any of dead cmd variables.
---
lib/commands/toolcontext.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index f4c0c95..11affee 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -2179,7 +2179,6 @@ void destroy_toolcontext(struct cmd_context *cmd)
lvmetad_release_token();
lvmetad_disconnect();
lvmpolld_disconnect();
- cmd->initialized.connections = 0;
release_log_memory();
activation_exit();
8 years, 8 months