From 8344fce3f629f92e4b9ee0b6b90b974565bd5455 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 1256c08e6..6907ee7d6 100755 --- a/drivers/cleanup.py +++ b/drivers/cleanup.py @@ -893,8 +893,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): @@ -1631,7 +1630,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 94219192e..8318b4746 100755 --- a/drivers/vhdutil.py +++ b/drivers/vhdutil.py @@ -41,6 +41,8 @@ VHD_FOOTER_SIZE: Final = 512 +VHD_SECTOR_SIZE: Final = 512 + MAX_VHD_CHAIN_LENGTH: Final = 30 VHD_UTIL: Final = "/usr/bin/vhd-util" @@ -323,12 +325,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 9f04dee1a..f6b300caf 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):