diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c index 184df7916..f617f4e92 100644 --- a/lib/metadata/cache_manip.c +++ b/lib/metadata/cache_manip.c @@ -314,3 +314,16 @@ int get_cache_mode(const char *str, uint32_t *flags) return 1; } + +int lv_is_cache_origin(const struct logical_volume *lv) +{ + struct lv_segment *seg; + + /* Make sure there's exactly one segment in segs_using_this_lv! */ + if (dm_list_empty(&lv->segs_using_this_lv) || + (dm_list_size(&lv->segs_using_this_lv) > 1)) + return 0; + + seg = get_only_segment_using_this_lv(lv); + return seg && lv_is_cache(seg->lv) && (seg_lv(seg, 0) == lv); +} diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index fa96a1a4c..497e59cd9 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -921,6 +921,8 @@ int lv_is_striped(const struct logical_volume *lv); */ int lv_is_origin(const struct logical_volume *lv); int lv_is_virtual_origin(const struct logical_volume *lv); +int lv_is_thin_origin(const struct logical_volume *lv); +int lv_is_cache_origin(const struct logical_volume *lv); int lv_is_cow(const struct logical_volume *lv); int lv_is_merging_origin(const struct logical_volume *origin); int lv_is_merging_cow(const struct logical_volume *snapshot); diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c index 07246f78d..7d861875e 100644 --- a/lib/metadata/thin_manip.c +++ b/lib/metadata/thin_manip.c @@ -499,3 +499,19 @@ const char *get_pool_discards_name(thin_discards_t discards) return "unknown"; } + +int lv_is_thin_origin(const struct logical_volume *lv) +{ + struct seg_list *segl; + + if (!lv_is_thin_volume(lv) || + dm_list_empty(&lv->segs_using_this_lv)) + return 0; + + dm_list_iterate_items(segl, &lv->segs_using_this_lv) { + if (segl->seg->origin == lv) + return 1; + } + + return 0; +}