master - cleanup: format1 test whether PV was found
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=243cd3fd2ca377...
Commit: 243cd3fd2ca377d93fd7407f2a0109a04a189cbc
Parent: 132306c8887ac7279edd515a9f5c5de75dfc463a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 13:52:19 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:52 2012 +0200
cleanup: format1 test whether PV was found
Avoid dereferecing NULL pointer.
---
lib/format1/import-extents.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/lib/format1/import-extents.c b/lib/format1/import-extents.c
index 46c1b7b..f0f4f65 100644
--- a/lib/format1/import-extents.c
+++ b/lib/format1/import-extents.c
@@ -118,7 +118,10 @@ static int _fill_maps(struct dm_hash_table *maps, struct volume_group *vg,
uint32_t i, lv_num, le;
dm_list_iterate_items(dl, pvds) {
- pv = find_pv(vg, dl->dev);
+ if (!(pv = find_pv(vg, dl->dev))) {
+ log_error("PV %s not found.", dl->dev->pvid);
+ return 0;
+ }
e = dl->extents;
/* build an array of lv's for this pv */
11 years, 8 months
master - cleanup: add __attribute__ ((nonnull(1)))
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=132306c8887ac7...
Commit: 132306c8887ac7279edd515a9f5c5de75dfc463a
Parent: fd417db274e9a75f33f661b475aeebfd3d9eae45
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 23 23:45:50 2010 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:52 2012 +0200
cleanup: add __attribute__ ((nonnull(1)))
---
lib/device/dev-cache.h | 1 +
libdm/regex/ttree.c | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lib/device/dev-cache.h b/lib/device/dev-cache.h
index b684df6..f3511cc 100644
--- a/lib/device/dev-cache.h
+++ b/lib/device/dev-cache.h
@@ -42,6 +42,7 @@ int dev_cache_has_scanned(void);
int dev_cache_add_dir(const char *path);
int dev_cache_add_loopfile(const char *path);
+__attribute__((nonnull(1)))
struct device *dev_cache_get(const char *name, struct dev_filter *f);
// TODO
diff --git a/libdm/regex/ttree.c b/libdm/regex/ttree.c
index ec97c98..00b371e 100644
--- a/libdm/regex/ttree.c
+++ b/libdm/regex/ttree.c
@@ -28,6 +28,7 @@ struct ttree {
struct node *root;
};
+__attribute__((nonnull(1)))
static struct node **_lookup_single(struct node **c, unsigned int k)
{
while (*c) {
11 years, 8 months
master - check: add internal errors for unexpected paths
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fd417db274e9a7...
Commit: fd417db274e9a75f33f661b475aeebfd3d9eae45
Parent: 15891d366d34fa6ea7235ec803ee0c5445a17101
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jun 21 12:43:31 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:52 2012 +0200
check: add internal errors for unexpected paths
Adding couple INTERNAL_ERROR reports for unwanted parameters:
Ensure the 'top' metadata node cannot be NULL for lvmetad.
Make obvious vginfo2 cannot be NULL.
Report internal error if handler and vg is undefined.
Check for handle in poll_vg().
Ensure seg is not NULL in dev_manager_transient().
Report missing read_ahead for _lv_read_ahead_single().
Check for report handler in dm_report_object().
Check missing VG in _vgreduce_single().
---
lib/activate/dev_manager.c | 5 +++++
lib/cache/lvmcache.c | 12 +++++++-----
lib/cache/lvmetad.c | 11 ++++++++++-
lib/metadata/metadata.c | 5 +++++
libdm/libdm-report.c | 5 +++++
tools/polldaemon.c | 5 +++++
tools/vgreduce.c | 5 +++++
7 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 122741c..43bcd49 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -668,6 +668,11 @@ int dev_manager_transient(struct dev_manager *dm, struct logical_volume *lv)
if (!type || !params)
continue;
+ if (!seg) {
+ log_error(INTERNAL_ERROR "Segment is not selected.");
+ goto out;
+ }
+
if (seg->segtype->ops->check_transient_status &&
!seg->segtype->ops->check_transient_status(seg, params))
goto_out;
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 8936809..6f9cfad 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1005,12 +1005,14 @@ static int _free_vginfo(struct lvmcache_vginfo *vginfo)
vginfo->vgname);
r = 0;
}
- } else do
- if (vginfo2->next == vginfo) {
- vginfo2->next = vginfo->next;
- break;
+ } else
+ while (vginfo2) {
+ if (vginfo2->next == vginfo) {
+ vginfo2->next = vginfo->next;
+ break;
+ }
+ vginfo2 = vginfo2->next;
}
- while ((vginfo2 = vginfo2->next));
dm_free(vginfo->vgname);
dm_free(vginfo->creation_host);
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index db092ac..6e1759b 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -199,7 +199,11 @@ struct volume_group *lvmetad_vg_lookup(struct cmd_context *cmd, const char *vgna
if (!strcmp(daemon_reply_str(reply, "response", ""), "OK")) {
- top = dm_config_find_node(reply.cft->root, "metadata");
+ if (!(top = dm_config_find_node(reply.cft->root, "metadata"))) {
+ log_error(INTERNAL_ERROR "metadata config node not found.");
+ goto out;
+ }
+
name = daemon_reply_str(reply, "name", NULL);
/* fall back to lvm2 if we don't know better */
@@ -593,6 +597,11 @@ int lvmetad_pv_found(struct id pvid, struct device *device, const struct format_
"metadata = %b", strchr(buf, '{'),
NULL);
} else {
+ if (handler) {
+ log_error(INTERNAL_ERROR "Handler needs existing VG.");
+ dm_free(pvmeta);
+ return 0;
+ }
/* There are no MDAs on this PV. */
reply = daemon_send_simple(_lvmetad,
"pv_found",
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index dd029ac..fd13b0a 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2221,6 +2221,11 @@ static int _lv_read_ahead_single(struct logical_volume *lv, void *data)
struct lv_segment *seg = first_seg(lv);
uint32_t seg_read_ahead = 0, *read_ahead = data;
+ if (!read_ahead) {
+ log_error(INTERNAL_ERROR "Read ahead data missing.");
+ return 0;
+ }
+
if (seg && seg->area_count && seg_type(seg, 0) == AREA_PV)
dev_get_read_ahead(seg_pv(seg, 0)->dev, &seg_read_ahead);
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 3f86767..0bafa86 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -695,6 +695,11 @@ int dm_report_object(struct dm_report *rh, void *object)
struct dm_report_field *field;
void *data = NULL;
+ if (!rh) {
+ log_error(INTERNAL_ERROR "dm_report handler is NULL.");
+ return 0;
+ }
+
if (!(row = dm_pool_zalloc(rh->mem, sizeof(*row)))) {
log_error("dm_report_object: struct row allocation failed");
return 0;
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index fe55c3b..f57484e 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -261,6 +261,11 @@ static int _poll_vg(struct cmd_context *cmd, const char *vgname,
const char *name;
int finished;
+ if (!parms) {
+ log_error(INTERNAL_ERROR "Handle is undefined.");
+ return ECMD_FAILED;
+ }
+
dm_list_iterate_items(lvl, &vg->lvs) {
lv = lvl->lv;
if (!(lv->status & parms->lv_type))
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 9696651..975b9ea 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -124,6 +124,11 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
int r = ECMD_FAILED;
const char *name = pv_dev_name(pv);
+ if (!vg) {
+ log_error(INTERNAL_ERROR "VG is NULL.");
+ return ECMD_FAILED;
+ }
+
if (pv_pe_alloc_count(pv)) {
log_error("Physical volume \"%s\" still in use", name);
return ECMD_FAILED;
11 years, 8 months
master - cleanup: add error message and simplify creation
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=15891d366d34fa...
Commit: 15891d366d34fa6ea7235ec803ee0c5445a17101
Parent: 195fe0307526ffc8307842618a7eeb4a421cacf9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Jun 20 10:35:24 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:38 2012 +0200
cleanup: add error message and simplify creation
Report error for malloc failure, and use zeroed allocation
to initialize handler structure.
---
daemons/dmeventd/libdevmapper-event.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 386a4fa..1f8fbef 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -59,14 +59,10 @@ struct dm_event_handler *dm_event_handler_create(void)
{
struct dm_event_handler *dmevh = NULL;
- if (!(dmevh = dm_malloc(sizeof(*dmevh))))
+ if (!(dmevh = dm_zalloc(sizeof(*dmevh)))) {
+ log_error("Failed to allocate event handler.");
return NULL;
-
- dmevh->dmeventd_path = NULL;
- dmevh->dso = dmevh->dev_name = dmevh->uuid = NULL;
- dmevh->major = dmevh->minor = 0;
- dmevh->mask = 0;
- dmevh->timeout = 0;
+ }
return dmevh;
}
11 years, 8 months
master - cleanup: use proper activation_change_t
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=195fe0307526ff...
Commit: 195fe0307526ffc8307842618a7eeb4a421cacf9
Parent: 449c09201030cfb18baf8481430bc150e43f5f07
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Aug 21 15:49:23 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:38 2012 +0200
cleanup: use proper activation_change_t
---
lib/cache/lvmetad.h | 4 +++-
lib/metadata/metadata-exported.h | 2 +-
tools/pvscan.c | 3 ++-
tools/vgchange.c | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h
index 713c5a3..932a9f1 100644
--- a/lib/cache/lvmetad.h
+++ b/lib/cache/lvmetad.h
@@ -18,8 +18,10 @@
struct volume_group;
struct cmd_context;
struct dm_config_tree;
+typedef enum activation_change activation_change_t;
-typedef int (*activation_handler) (struct volume_group *vg, int partial, int activate);
+typedef int (*activation_handler) (struct volume_group *vg, int partial,
+ activation_change_t activate);
#ifdef LVMETAD_SUPPORT
/*
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index f39f968..0658fad 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -571,7 +571,7 @@ const char *get_pool_discards_name(thin_discards_t discards);
/*
* Activation options
*/
-typedef enum {
+typedef enum activation_change {
CHANGE_AY = 0, /* activate */
CHANGE_AN = 1, /* deactivate */
CHANGE_AE = 2, /* activate exclusively */
diff --git a/tools/pvscan.c b/tools/pvscan.c
index a846322..6c634e3 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -97,7 +97,8 @@ static void _pvscan_display_single(struct cmd_context *cmd,
pv_pe_size(pv)));
}
-static int _auto_activation_handler(struct volume_group *vg, int partial, int activate)
+static int _auto_activation_handler(struct volume_group *vg, int partial,
+ activation_change_t activate)
{
/* TODO: add support for partial and clustered VGs */
if (partial || vg_is_clustered(vg))
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 2013447..c59d58e 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -512,7 +512,8 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
}
if (arg_count(cmd, activate_ARG)) {
- if (!vgchange_activate(cmd, vg, arg_uint_value(cmd, activate_ARG, CHANGE_AY)))
+ if (!vgchange_activate(cmd, vg, (activation_change_t)
+ arg_uint_value(cmd, activate_ARG, CHANGE_AY)))
return ECMD_FAILED;
}
11 years, 8 months
master - cleanup: use static char[] array
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=449c09201030cf...
Commit: 449c09201030cfb18baf8481430bc150e43f5f07
Parent: 90191e6ff2d156abceebafa342ec34274b6bd22a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Aug 21 15:16:32 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:38 2012 +0200
cleanup: use static char[] array
---
lib/device/device.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/device/device.c b/lib/device/device.c
index 3e5e2a4..a87ae7f 100644
--- a/lib/device/device.c
+++ b/lib/device/device.c
@@ -361,7 +361,7 @@ static unsigned long _dev_topology_attribute(const char *attribute,
const char *sysfs_dir,
struct device *dev)
{
- const char *sysfs_fmt_str = "%s/dev/block/%d:%d/%s";
+ static const char sysfs_fmt_str[] = "%s/dev/block/%d:%d/%s";
char path[PATH_MAX+1], buffer[64];
FILE *fp;
struct stat info;
11 years, 8 months
master - cleanup: cast to matching type
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=90191e6ff2d156...
Commit: 90191e6ff2d156abceebafa342ec34274b6bd22a
Parent: 14d2b5a13ff6637f2ff1e8bd40dc8ca67e53e51b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 17 12:15:36 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:38 2012 +0200
cleanup: cast to matching type
---
tools/dmsetup.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 0734ded..0ac970f 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -2283,7 +2283,7 @@ static int _dm_mangled_name_disp(struct dm_report *rh,
int r = 0;
if ((name = dm_task_get_name_mangled((const struct dm_task *) data))) {
- r = dm_report_field_string(rh, field, (const char **) &name);
+ r = dm_report_field_string(rh, field, (const char * const *) &name);
dm_free(name);
}
@@ -2299,7 +2299,7 @@ static int _dm_unmangled_name_disp(struct dm_report *rh,
int r = 0;
if ((name = dm_task_get_name_unmangled((const struct dm_task *) data))) {
- r = dm_report_field_string(rh, field, (const char **) &name);
+ r = dm_report_field_string(rh, field, (const char * const *) &name);
dm_free(name);
}
11 years, 8 months
master - cleanup: use return_NULL
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=14d2b5a13ff663...
Commit: 14d2b5a13ff6637f2ff1e8bd40dc8ca67e53e51b
Parent: c8ad1f3e3a280b8cf3ca219dd6a6f3313b8be8d8
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 17 12:04:52 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:38 2012 +0200
cleanup: use return_NULL
Function returns pointer, so use NULL.
---
lib/cache/lvmetad.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index bb949b5..db092ac 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -189,7 +189,7 @@ struct volume_group *lvmetad_vg_lookup(struct cmd_context *cmd, const char *vgna
if (vgid) {
if (!id_write_format((const struct id*)vgid, uuid, sizeof(uuid)))
- return_0;
+ return_NULL;
reply = daemon_send_simple(_lvmetad, "vg_lookup", "uuid = %s", uuid, NULL);
} else {
if (!vgname)
11 years, 8 months
master - cleanup: ignore write/close output
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c8ad1f3e3a280b...
Commit: c8ad1f3e3a280b8cf3ca219dd6a6f3313b8be8d8
Parent: 93f36fb77f595f67602cd9b39bb696e802545546
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 17 00:48:28 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:37 2012 +0200
cleanup: ignore write/close output
Intentionaly ignore write and close errors.
---
.../lvm2_activation_generator_systemd_red_hat.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/lvm2_activation_generator_systemd_red_hat.c b/scripts/lvm2_activation_generator_systemd_red_hat.c
index 85420b8..9fcee20 100644
--- a/scripts/lvm2_activation_generator_systemd_red_hat.c
+++ b/scripts/lvm2_activation_generator_systemd_red_hat.c
@@ -46,7 +46,7 @@ static void kmsg(const char *format, ...)
if (kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > sizeof(message))))
return;
- write(kmsg_fd, message, n + 1);
+ (void) write(kmsg_fd, message, n + 1);
}
static int lvm_uses_lvmetad(void)
@@ -164,6 +164,6 @@ int main(int argc, char *argv[])
out:
kmsg("LVM: Activation generator %s.\n", r ? "failed" : "successfully completed");
if (kmsg_fd != -1)
- close(kmsg_fd);
+ (void) close(kmsg_fd);
return r;
}
11 years, 8 months
master - cleanup: add va_end
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=93f36fb77f595f...
Commit: 93f36fb77f595f67602cd9b39bb696e802545546
Parent: bd67a3151aa3a3202d52fcc9ffac781b96dca04a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 17 00:46:00 2012 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Aug 23 14:37:21 2012 +0200
cleanup: add va_end
Pair va_start with va_end.
---
libdaemon/server/daemon-log.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/libdaemon/server/daemon-log.c b/libdaemon/server/daemon-log.c
index 8eab917..b18e70c 100644
--- a/libdaemon/server/daemon-log.c
+++ b/libdaemon/server/daemon-log.c
@@ -53,13 +53,15 @@ void daemon_log(log_state *s, int type, const char *message) {
}
void daemon_logf(log_state *s, int type, const char *fmt, ...) {
+ char *buf;
va_list ap;
+
va_start(ap, fmt);
- char *buf;
- if (dm_vasprintf(&buf, fmt, ap) < 0)
- return; /* _0 */
- daemon_log(s, type, buf);
- dm_free(buf);
+ if (dm_vasprintf(&buf, fmt, ap) >= 0) {
+ daemon_log(s, type, buf);
+ dm_free(buf);
+ } /* else return_0 */
+ va_end(ap);
}
struct log_line_baton {
11 years, 8 months