Skip to contentSkip to conversation

stable-2.02 - thin: introduce estimate_thin_pool_metadata_size

PATCH Zdenek Kabelac 1 participant 1 message Apr 30, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bcf1aa99e66b7a99f9cddbecffad1b3d65b59a50
Commit:        bcf1aa99e66b7a99f9cddbecffad1b3d65b59a50
Parent:        b41b112a4bf5f674acd45f12ff4efe7fa0d1d8be
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Wed Apr 3 12:56:48 2019 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Tue Apr 30 12:02:49 2019 +0200

thin: introduce estimate_thin_pool_metadata_size

Add function for estimation of thin-pool metadata size for given size of data. Function is using already existing internal API so it can be reused for resize of thin-pool data.

---
 lib/metadata/metadata.h   |    1 +
 lib/metadata/thin_manip.c |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
lib/metadata/metadata.h +1 -0
index 1e3dd1b..f8083e5 100644
@@ -498,6 +498,7 @@ int pool_below_threshold(const struct lv_segment *pool_seg);
 int pool_check_overprovisioning(const struct logical_volume *lv);
 int create_pool(struct logical_volume *pool_lv, const struct segment_type *segtype,
 		struct alloc_handle *ah, uint32_t stripes, uint32_t stripe_size);
+uint64_t estimate_thin_pool_metadata_size(uint32_t data_extents, uint32_t extent_size, uint32_t chunk_size);
 
 /*
  * Begin skeleton for external LVM library
lib/metadata/thin_manip.c +12 -0
index d2d1384..313ef1b 100644
@@ -916,3 +916,15 @@ int validate_thin_pool_chunk_size(struct cmd_context *cmd, uint32_t chunk_size)
 
 	return r;
 }
+
+uint64_t estimate_thin_pool_metadata_size(uint32_t data_extents, uint32_t extent_size, uint32_t chunk_size)
+{
+	uint64_t sz = _estimate_metadata_size(data_extents, extent_size, chunk_size);
+
+	if (sz > (2 * DEFAULT_THIN_POOL_MAX_METADATA_SIZE))
+		sz = 2 * DEFAULT_THIN_POOL_MAX_METADATA_SIZE;
+	else if (sz < (2 * DEFAULT_THIN_POOL_MIN_METADATA_SIZE))
+		sz = 2 * DEFAULT_THIN_POOL_MIN_METADATA_SIZE;
+
+	return sz;
+}