From a686391eca557fc35eb90c1ef4cdc57418b6ee19 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mon, 5 Nov 2018 16:14:45 -0600 Subject: [PATCH] cache: reorganize cache_set_policy to prepare for future addition --- lib/metadata/cache_manip.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index 66f759fd4..8e8e70426 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -748,23 +748,30 @@ static cache_metadata_format_t _get_default_cache_metadata_format(struct cmd_con return f; } -int cache_set_policy(struct lv_segment *seg, const char *name, +int cache_set_policy(struct lv_segment *lvseg, const char *name, const struct dm_config_tree *settings) { + struct lv_segment *seg; struct dm_config_node *cn; const struct dm_config_node *cns; struct dm_config_tree *old = NULL, *new = NULL, *tmp = NULL; int r = 0; - struct profile *profile = seg->lv->profile; + struct profile *profile = lvseg->lv->profile; - if (seg_is_cache(seg)) - seg = first_seg(seg->pool_lv); - else if (seg_is_cache_pool(seg)) { + if (seg_is_cache_pool(lvseg)) { if (!name && !settings) return 1; /* Policy and settings can be selected later when caching LV */ - } else { + } + + if (seg_is_cache_pool(lvseg)) + seg = lvseg; + + else if (seg_is_cache(lvseg)) + seg = first_seg(lvseg->pool_lv); + + else { log_error(INTERNAL_ERROR "Cannot set cache metadata format for non cache volume %s.", - display_lvname(seg->lv)); + display_lvname(lvseg->lv)); return 0; } -- 2.43.5