From 73e62cdc110e644616acf4a10b693768818a8ba5 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Mon, 13 Feb 2012 11:25:56 +0000 Subject: [PATCH] Add internal error for unsupported code paths Patch mainly helps static analyzers to better work with code paths lvm code should never trigger. --- lib/metadata/lv.c | 3 +++ lib/metadata/lv_manip.c | 5 +++++ liblvm/lvm_lv.c | 13 ++++++++++--- tools/reporter.c | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c index 7cb154622..fb17442a5 100644 --- a/lib/metadata/lv.c +++ b/lib/metadata/lv.c @@ -53,6 +53,9 @@ static char *_format_pvsegs(struct dm_pool *mem, const struct lv_segment *seg, case AREA_UNASSIGNED: name = "unassigned"; extent = 0; + default: + log_error(INTERNAL_ERROR "Unknown area segtype."); + return NULL; } if (!dm_pool_grow_object(mem, name, strlen(name))) { diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index ae9fc505e..464e4207b 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -2116,6 +2116,11 @@ struct alloc_handle *allocate_extents(struct volume_group *vg, return NULL; } + if (!allocatable_pvs) { + log_error(INTERNAL_ERROR "Missing allocatable pvs."); + return NULL; + } + if (vg->fid->fmt->ops->segtype_supported && !vg->fid->fmt->ops->segtype_supported(vg->fid, segtype)) { log_error("Metadata format (%s) does not support required " diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c index c535caf9d..f8ef2f16e 100644 --- a/liblvm/lvm_lv.c +++ b/liblvm/lvm_lv.c @@ -124,12 +124,18 @@ static void _lv_set_default_params(struct lvcreate_params *lp, } /* Set default for linear segment specific LV parameters */ -static void _lv_set_default_linear_params(struct cmd_context *cmd, +static int _lv_set_default_linear_params(struct cmd_context *cmd, struct lvcreate_params *lp) { - lp->segtype = get_segtype_from_string(cmd, "striped"); + if (!(lp->segtype = get_segtype_from_string(cmd, "striped"))) { + log_error(INTERNAL_ERROR "Segtype striped not found."); + return 0; + } + lp->stripes = 1; lp->stripe_size = DEFAULT_STRIPESIZE * 2; + + return 1; } /* @@ -151,7 +157,8 @@ lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size) extents = extents_from_size(vg->cmd, size / SECTOR_SIZE, vg->extent_size); _lv_set_default_params(&lp, vg, name, extents); - _lv_set_default_linear_params(vg->cmd, &lp); + if (!_lv_set_default_linear_params(vg->cmd, &lp)) + return_NULL; if (!lv_create_single(vg, &lp)) return NULL; lvl = find_lv_in_vg(vg, name); diff --git a/tools/reporter.c b/tools/reporter.c index a52725383..1c8e39d1b 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -315,6 +315,9 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, "report/pvsegs_cols_verbose", DEFAULT_PVSEGS_COLS_VERB); break; + default: + log_error(INTERNAL_ERROR "Unknown report type."); + return ECMD_FAILED; } /* If -o supplied use it, else use default for report_type */