diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index 456bc8668..6a0f0f61c 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -91,8 +91,6 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool, struct cmd_context *cmd = pool->vg->cmd; struct logical_volume *cache_lv; struct lv_segment *seg; - int origin_name_len = strlen(origin->name); - char origin_name[origin_name_len + 7]; /* + "_corig" and NULL */ if (!lv_is_cache_pool(pool)) { log_error(INTERNAL_ERROR @@ -124,21 +122,6 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool, if (!(segtype = get_segtype_from_string(cmd, "cache"))) return_NULL; - /* - * insert_layer_for_lv does not rename the sub-LVs when adding - * the suffix. So, we rename everything here and then change - * only the top-level LV back before adding the layer. - */ - sprintf(origin_name, "%s_corig", origin->name); - if (!lv_rename_update(cmd, origin, origin_name, 0)) { - log_error("Failed to rename origin LV, %s", origin->name); - return NULL; - } - - origin_name[origin_name_len] = '\0'; - if (!(origin->name = dm_pool_strdup(origin->vg->vgmem, origin_name))) - return_0; - cache_lv = origin; if (!(origin = insert_layer_for_lv(cmd, cache_lv, CACHE, "_corig"))) return_NULL; diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index b05f6cc9f..44f94f467 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -5384,6 +5384,7 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd, uint64_t status, const char *layer_suffix) { + static char _suffixes[][8] = { "_tdata", "_cdata", "_corig" }; int r; char *name; size_t len; @@ -5493,12 +5494,14 @@ struct logical_volume *insert_layer_for_lv(struct cmd_context *cmd, * currently supported only for thin data layer * FIXME: without strcmp it breaks mirrors.... */ - if (strcmp(layer_suffix, "_tdata") == 0) { - lv_names.old = lv_where->name; - lv_names.new = layer_lv->name; - if (!for_each_sub_lv(layer_lv, _rename_cb, (void *) &lv_names)) - return 0; - } + for (r = 0; r < DM_ARRAY_SIZE(_suffixes); ++r) + if (strcmp(layer_suffix, _suffixes[r]) == 0) { + lv_names.old = lv_where->name; + lv_names.new = layer_lv->name; + if (!for_each_sub_lv(layer_lv, _rename_cb, (void *) &lv_names)) + return 0; + break; + } return layer_lv; }