From e36028b7d2fe785ab7b5fb74cb474170b692875f Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Tue, 4 Jul 2023 19:21:43 +0200 Subject: [PATCH] cache: update validation rules Validate cache origin in front of the prompt. Also add some rules to command description file. TODO: more validation needed also for lvcreate, more complex rules with "OR" seems to be needed. --- lib/metadata/cache_manip.c | 9 +-------- tools/command-lines.in | 4 ++-- tools/lvconvert.c | 3 +++ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index 9e156995e..efcba2a1c 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -356,17 +356,10 @@ int validate_lv_cache_create_origin(const struct logical_volume *origin_lv) return 0; } - /* - * Only linear, striped or raid supported. - * FIXME Tidy up all these type restrictions. - */ if (lv_is_cache_type(origin_lv) || lv_is_mirror_type(origin_lv) || - lv_is_thin_volume(origin_lv) || lv_is_thin_pool_metadata(origin_lv) || lv_is_merging_origin(origin_lv) || - lv_is_cow(origin_lv) || lv_is_merging_cow(origin_lv) || - /* TODO: think about enabling caching of a single thin volume */ - (lv_is_virtual(origin_lv) && !lv_is_vdo(origin_lv))) { + lv_is_cow(origin_lv) || lv_is_merging_cow(origin_lv)) { log_error("Cache is not supported with %s segment type of the original logical volume %s.", lvseg_name(first_seg(origin_lv)), display_lvname(origin_lv)); return 0; diff --git a/tools/command-lines.in b/tools/command-lines.in index 9e14f375f..86fcf1b9c 100644 --- a/tools/command-lines.in +++ b/tools/command-lines.in @@ -479,7 +479,7 @@ lvconvert --type cache --cachepool LV LV_linear_striped_raid_thinpool_vdo_vdopoo OO: --cache, OO_LVCONVERT_CACHE, OO_LVCONVERT_POOL, OO_LVCONVERT ID: lvconvert_to_cache_with_cachepool DESC: Attach a cache pool to an LV, converts the LV to type cache. -RULE: all and lv_is_visible +RULE: all not lv_is_locked lv_is_merging_origin lv_is_merging_cow lv_is_cow RULE: --poolmetadata not --readahead --stripesize --stripes_long # alternate form of lvconvert --type cache @@ -487,7 +487,7 @@ lvconvert --cache --cachepool LV LV_linear_striped_raid_thinpool_vdo_vdopool_vdo OO: OO_LVCONVERT_CACHE, OO_LVCONVERT_POOL, OO_LVCONVERT ID: lvconvert_to_cache_with_cachepool DESC: Attach a cache pool to an LV. -RULE: all and lv_is_visible +RULE: all not lv_is_locked lv_is_merging_origin lv_is_merging_cow lv_is_cow RULE: --poolmetadata not --readahead --stripesize --stripes_long FLAGS: SECONDARY_SYNTAX AUTOTYPE: cache diff --git a/tools/lvconvert.c b/tools/lvconvert.c index d7a2911e4..8410ebbb0 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -4516,6 +4516,9 @@ static int _lvconvert_cachepool_attach_single(struct cmd_context *cmd, goto out; } + if (!validate_lv_cache_create_origin(lv)) + goto_out; + /* Ensure the LV is not active elsewhere. */ if (!lockd_lv(cmd, lv, "ex", 0)) goto_out;