Skip to content

Commit

Permalink
fix(vhdutil): coalesce returns a size in bytes now
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Jan 22, 2025
1 parent 5f8eaba commit 604355b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions drivers/vhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vhdutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 604355b

Please sign in to comment.