From ffd5fb70a40e57ff56fdf6c038741d3bc82d489a Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 12 Nov 2024 12:03:47 +0100 Subject: [PATCH] rbd: avoid accidental root disk downsizes PL-133166 --- CHANGES.txt | 3 +++ src/fc/qemu/hazmat/volume.py | 5 ++++- tests/hazmat/test_volume.py | 3 +++ tests/test_vm.py | 11 +++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0cb3198..3f5eb3e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,9 @@ Release notes impatient clients and we ended up not thawing correctly when creating the snapshot resulted in an ImageExists error. (PL-133149) +- rbd: fix disk downsizing that causes potential data loss + when inventory data and real data mismatch and may shrink root images + accidentally. (PL-133166) 1.6 (2024-10-23) ---------------- diff --git a/src/fc/qemu/hazmat/volume.py b/src/fc/qemu/hazmat/volume.py index 976a303..b3fb4d1 100644 --- a/src/fc/qemu/hazmat/volume.py +++ b/src/fc/qemu/hazmat/volume.py @@ -234,7 +234,10 @@ def size(self): return self.rbdimage.size() def ensure_size(self, size): - if self.size == size: + # The existing size must be considered as a minimum, because we can't + # just reduce images that already exist and are bigger and expect them + # to work properly. + if self.size >= size: return self.rbdimage.resize(size) diff --git a/tests/hazmat/test_volume.py b/tests/hazmat/test_volume.py index ea88f8e..87857e5 100644 --- a/tests/hazmat/test_volume.py +++ b/tests/hazmat/test_volume.py @@ -94,6 +94,9 @@ def test_volume_size(tmp_spec): # Call ensure multiple times to help triggering caching code paths. volume.ensure_size(2048) assert volume.size == 2048 + # Trying to reduce the size doesn't make a change + volume.ensure_size(1024) + assert volume.size == 2048 def test_volume_shared_lock_protection(tmp_spec): diff --git a/tests/test_vm.py b/tests/test_vm.py index ada511d..ea5d34c 100644 --- a/tests/test_vm.py +++ b/tests/test_vm.py @@ -638,6 +638,17 @@ def test_vm_resize_disk(vm, patterns): assert get_log() == resize_noop + # Decreasing the desired disk size does not trigger a change. + vm.cfg["root_size"] = 6442450944 - 1 + vm.ensure_online_disk_size() + resize_noop2 = patterns.resize_noop2 + resize_noop2.in_order( + """ +check-disk-size action=none found=6442450944 machine=simplevm wanted=6442450943 +""" + ) + assert get_log() == resize_noop2 + def test_swap_size(): assert swap_size(512) == 1024 * MiB