Skip to content

Commit

Permalink
rbd: avoid accidental root disk downsizes
Browse files Browse the repository at this point in the history
PL-133166
  • Loading branch information
ctheune committed Nov 12, 2024
1 parent a0223a3 commit ffd5fb7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----------------
Expand Down
5 changes: 4 additions & 1 deletion src/fc/qemu/hazmat/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions tests/hazmat/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffd5fb7

Please sign in to comment.