libblockdev/valid_thpool_md_size.patch
Vratislav Podzimek c29e6ca081 New version
- Make sure the returned thpool MD size is valid (vpodzime)
2017-04-11 09:50:18 +02:00

76 lines
2.6 KiB
Diff

From 2b510a862dfc120e9e5592ba15112385b6c8c371 Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Mon, 3 Apr 2017 13:54:52 +0200
Subject: [PATCH] Make sure the returned thpool MD size is valid
It may be too small as given by the thin_metadata_size tool which
obviously doesn't guard for too small values.
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
src/plugins/lvm-dbus.c | 2 +-
src/plugins/lvm.c | 2 +-
tests/lvm_dbus_tests.py | 4 ++++
tests/lvm_test.py | 4 ++++
4 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c
index 25cb82a..86a5383 100644
--- a/src/plugins/lvm-dbus.c
+++ b/src/plugins/lvm-dbus.c
@@ -1097,7 +1097,7 @@ guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n
return 0;
}
- return ret;
+ return MAX (ret, BD_LVM_MIN_THPOOL_MD_SIZE);
}
/**
diff --git a/src/plugins/lvm.c b/src/plugins/lvm.c
index a8acc69..21a20ba 100644
--- a/src/plugins/lvm.c
+++ b/src/plugins/lvm.c
@@ -615,7 +615,7 @@ guint64 bd_lvm_get_thpool_meta_size (guint64 size, guint64 chunk_size, guint64 n
return 0;
}
- return ret;
+ return MAX (ret, BD_LVM_MIN_THPOOL_MD_SIZE);
}
/**
diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py
index 4ba93e9..998f97c 100644
--- a/tests/lvm_dbus_tests.py
+++ b/tests/lvm_dbus_tests.py
@@ -130,6 +130,10 @@ class LvmNoDevTestCase(unittest.TestCase):
# twice the chunk_size -> roughly half the metadata needed
self.assertAlmostEqual(float(out1) / float(out2), 2, places=2)
+ # unless thin_metadata_size gives a value that is not valid (too small)
+ self.assertEqual(BlockDev.lvm_get_thpool_meta_size (100 * 1024**2, 128 * 1024, 100),
+ BlockDev.LVM_MIN_THPOOL_MD_SIZE)
+
def test_is_valid_thpool_md_size(self):
"""Verify that is_valid_thpool_md_size works as expected"""
diff --git a/tests/lvm_test.py b/tests/lvm_test.py
index 4879808..c7fedbd 100644
--- a/tests/lvm_test.py
+++ b/tests/lvm_test.py
@@ -114,6 +114,10 @@ class LvmNoDevTestCase(unittest.TestCase):
# twice the chunk_size -> roughly half the metadata needed
self.assertAlmostEqual(float(out1) / float(out2), 2, places=2)
+ # unless thin_metadata_size gives a value that is not valid (too small)
+ self.assertEqual(BlockDev.lvm_get_thpool_meta_size (100 * 1024**2, 128 * 1024, 100),
+ BlockDev.LVM_MIN_THPOOL_MD_SIZE)
+
def test_is_valid_thpool_md_size(self):
"""Verify that is_valid_thpool_md_size works as expected"""
--
2.9.3