From 604355bc4738446ab38aa353a07a50594f22e5e3 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 22 Jan 2025 16:01:50 +0100 Subject: [PATCH] fix(vhdutil): coalesce returns a size in bytes now Signed-off-by: Ronan Abhamon --- drivers/cleanup.py | 5 ++--- drivers/vhdutil.py | 6 ++++-- tests/test_vhdutil.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/cleanup.py b/drivers/cleanup.py index a6e0e110..aa931225 100755 --- a/drivers/cleanup.py +++ b/drivers/cleanup.py @@ -897,8 +897,7 @@ def _reportCoalesceError(vdi, ce): xapi.message.create(msg_name, "3", "SR", vdi.sr.uuid, msg_body) def coalesce(self) -> int: - # size is returned in sectors - return self.cowutil.coalesce(self.path) * 512 + return self.cowutil.coalesce(self.path) @staticmethod def _doCoalesceCowImage(vdi): @@ -1634,7 +1633,7 @@ def pause(self, failfast=False) -> None: def coalesce(self) -> int: # Note: We raise `SMException` here to skip the current coalesce in case of failure. # Using another exception we can't execute the next coalesce calls. - return self.sr._vhdutil.force_coalesce(self.path) * 512 + return self.sr._vhdutil.force_coalesce(self.path) @override def getParent(self) -> str: diff --git a/drivers/vhdutil.py b/drivers/vhdutil.py index 12585826..6196492b 100755 --- a/drivers/vhdutil.py +++ b/drivers/vhdutil.py @@ -43,6 +43,8 @@ VHD_FOOTER_SIZE: Final = 512 +VHD_SECTOR_SIZE: Final = 512 + MAX_VHD_CHAIN_LENGTH: Final = 30 VHD_UTIL: Final = "/usr/bin/vhd-util" @@ -329,12 +331,12 @@ def getBlockBitmap(self, path: str) -> bytes: @override def coalesce(self, path: str) -> int: """ - Coalesce the VHD, on success it returns the number of sectors coalesced. + Coalesce the VHD, on success it returns the number of bytes coalesced. """ text = cast(str, self._ioretry([VHD_UTIL, "coalesce", OPT_LOG_ERR, "-n", path])) match = re.match(r"^Coalesced (\d+) sectors", text) if match: - return int(match.group(1)) + return int(match.group(1)) * VHD_SECTOR_SIZE return 0 @override diff --git a/tests/test_vhdutil.py b/tests/test_vhdutil.py index 10d4eacd..03cb6e38 100644 --- a/tests/test_vhdutil.py +++ b/tests/test_vhdutil.py @@ -366,7 +366,7 @@ def test_function(args, inp): context.add_executable(VHD_UTIL, test_function) # Act/Assert - self.assertEqual(25, vhdutil.coalesce(TEST_VHD_PATH)) + self.assertEqual(25 * vhdutil.SECTOR_SIZE, vhdutil.coalesce(TEST_VHD_PATH)) @testlib.with_context def test_get_vhd_info_allocated_size(self, context):