Skip to content

Commit bbb0968

Browse files
committed
fix(vhdutil): coalesce returns a size in bytes now
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent 5f8eaba commit bbb0968

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

drivers/cleanup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,7 @@ def _reportCoalesceError(vdi, ce):
897897
xapi.message.create(msg_name, "3", "SR", vdi.sr.uuid, msg_body)
898898

899899
def coalesce(self) -> int:
900-
# size is returned in sectors
901-
return self.cowutil.coalesce(self.path) * 512
900+
return self.cowutil.coalesce(self.path)
902901

903902
@staticmethod
904903
def _doCoalesceCowImage(vdi):
@@ -1634,7 +1633,7 @@ def pause(self, failfast=False) -> None:
16341633
def coalesce(self) -> int:
16351634
# Note: We raise `SMException` here to skip the current coalesce in case of failure.
16361635
# Using another exception we can't execute the next coalesce calls.
1637-
return self.sr._vhdutil.force_coalesce(self.path) * 512
1636+
return self.sr._vhdutil.force_coalesce(self.path)
16381637

16391638
@override
16401639
def getParent(self) -> str:

drivers/vhdutil.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
VHD_FOOTER_SIZE: Final = 512
4545

46+
VHD_SECTOR_SIZE: Final = 512
47+
4648
MAX_VHD_CHAIN_LENGTH: Final = 30
4749

4850
VHD_UTIL: Final = "/usr/bin/vhd-util"
@@ -329,12 +331,12 @@ def getBlockBitmap(self, path: str) -> bytes:
329331
@override
330332
def coalesce(self, path: str) -> int:
331333
"""
332-
Coalesce the VHD, on success it returns the number of sectors coalesced.
334+
Coalesce the VHD, on success it returns the number of bytes coalesced.
333335
"""
334336
text = cast(str, self._ioretry([VHD_UTIL, "coalesce", OPT_LOG_ERR, "-n", path]))
335337
match = re.match(r"^Coalesced (\d+) sectors", text)
336338
if match:
337-
return int(match.group(1))
339+
return int(match.group(1)) * VHD_SECTOR_SIZE
338340
return 0
339341

340342
@override

tests/test_vhdutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_function(args, inp):
366366
context.add_executable(VHD_UTIL, test_function)
367367

368368
# Act/Assert
369-
self.assertEqual(25, vhdutil.coalesce(TEST_VHD_PATH))
369+
self.assertEqual(25 * 512, vhdutil.coalesce(TEST_VHD_PATH))
370370

371371
@testlib.with_context
372372
def test_get_vhd_info_allocated_size(self, context):

0 commit comments

Comments
 (0)