diff --git a/WHATS_NEW b/WHATS_NEW index b08fbe10d..4fb2ebaaf 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.92 - ==================================== + Clean error paths for format instance creation (2.02.91). Release vg in error path of _format1_vg_read() instead of just free(). Report allocation failure for allocation of PV structure. Add clvmd init dependency on dlm service when running with new corosync. diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 3836abf82..30b79b5aa 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -580,8 +580,10 @@ struct format_type *init_format(struct cmd_context *cmd) struct format_instance_ctx fic; struct format_instance *fid; - if (!fmt) - return_NULL; + if (!fmt) { + log_error("Failed to allocate format1 format type structure."); + return NULL; + } fmt->cmd = cmd; fmt->ops = &_format1_ops; @@ -607,15 +609,19 @@ struct format_type *init_format(struct cmd_context *cmd) if (!(fmt->orphan_vg = alloc_vg("text_orphan", cmd, fmt->orphan_vg_name))) { log_error("Couldn't create lvm1 orphan VG."); + dm_free(fmt); return NULL; } + fic.type = FMT_INSTANCE_AUX_MDAS; fic.context.vg_ref.vg_name = fmt->orphan_vg_name; fic.context.vg_ref.vg_id = NULL; + if (!(fid = _format1_create_instance(fmt, &fic))) { - log_error("Couldn't create lvm1 orphan VG format instance."); - return NULL; + _format1_destroy(fmt); + return_NULL; } + vg_set_fid(fmt->orphan_vg, fid); log_very_verbose("Initialised format: %s", fmt->name); diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c index eac166017..1e742eaf0 100644 --- a/lib/format_pool/format_pool.c +++ b/lib/format_pool/format_pool.c @@ -320,15 +320,19 @@ struct format_type *init_format(struct cmd_context *cmd) if (!(fmt->orphan_vg = alloc_vg("text_orphan", cmd, fmt->orphan_vg_name))) { log_error("Couldn't create lvm1 orphan VG."); + dm_free(fmt); return NULL; } + fic.type = FMT_INSTANCE_AUX_MDAS; fic.context.vg_ref.vg_name = fmt->orphan_vg_name; fic.context.vg_ref.vg_id = NULL; + if (!(fid = _pool_create_instance(fmt, &fic))) { - log_error("Couldn't create lvm1 orphan VG format instance."); + _pool_destroy(fmt); return NULL; } + vg_set_fid(fmt->orphan_vg, fid); log_very_verbose("Initialised format: %s", fmt->name); diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 7781a9362..717db7491 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -2270,8 +2270,10 @@ struct format_type *create_text_format(struct cmd_context *cmd) const struct dm_config_value *cv; struct mda_lists *mda_lists; - if (!(fmt = dm_malloc(sizeof(*fmt)))) - return_NULL; + if (!(fmt = dm_malloc(sizeof(*fmt)))) { + log_error("Failed to allocate text format type structure."); + return NULL; + } fmt->cmd = cmd; fmt->ops = &_text_handler; @@ -2296,13 +2298,13 @@ struct format_type *create_text_format(struct cmd_context *cmd) if (!(fmt->labeller = text_labeller_create(fmt))) { log_error("Couldn't create text label handler."); - goto err; + goto bad; } if (!(label_register_handler(FMT_TEXT_NAME, fmt->labeller))) { log_error("Couldn't register text label handler."); fmt->labeller->ops->destroy(fmt->labeller); - goto err; + goto bad; } if ((cn = find_config_tree_node(cmd, "metadata/dirs"))) { @@ -2310,13 +2312,13 @@ struct format_type *create_text_format(struct cmd_context *cmd) if (cv->type != DM_CFG_STRING) { log_error("Invalid string in config file: " "metadata/dirs"); - goto err; + goto bad; } if (!_add_dir(cv->v.str, &mda_lists->dirs)) { log_error("Failed to add %s to text format " "metadata directory list ", cv->v.str); - goto err; + goto bad; } cmd->independent_metadata_areas = 1; } @@ -2325,31 +2327,26 @@ struct format_type *create_text_format(struct cmd_context *cmd) if ((cn = find_config_tree_node(cmd, "metadata/disk_areas"))) { for (cn = cn->child; cn; cn = cn->sib) { if (!_get_config_disk_area(cmd, cn, &mda_lists->raws)) - goto err; + goto_bad; cmd->independent_metadata_areas = 1; } } - if (!(fmt->orphan_vg = alloc_vg("text_orphan", cmd, fmt->orphan_vg_name))) { - dm_free(fmt); - return NULL; - } + if (!(fmt->orphan_vg = alloc_vg("text_orphan", cmd, fmt->orphan_vg_name))) + goto_bad; fic.type = FMT_INSTANCE_AUX_MDAS; fic.context.vg_ref.vg_name = fmt->orphan_vg_name; fic.context.vg_ref.vg_id = NULL; - if (!(fid = _text_create_text_instance(fmt, &fic))) { - log_error("Failed to create format instance"); - release_vg(fmt->orphan_vg); - goto err; - } + if (!(fid = _text_create_text_instance(fmt, &fic))) + goto_bad; + vg_set_fid(fmt->orphan_vg, fid); log_very_verbose("Initialised format: %s", fmt->name); return fmt; - - err: +bad: _text_destroy(fmt); return NULL;