Skip to content

Commit

Permalink
fix(cleanup.py): replace VDI.raw attr with VDI.vdi_type
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Dec 13, 2024
1 parent 1f1b3c9 commit ddfc8d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
70 changes: 35 additions & 35 deletions drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ class VDI(object):

STR_TREE_INDENT = 4

def __init__(self, sr, uuid, raw):
def __init__(self, sr, uuid, vdi_type):
self.sr = sr
self.scanError = True
self.uuid = uuid
self.raw = raw
self.vdi_type = vdi_type
self.fileName = ""
self.parentUuid = ""
self.sizeVirt = -1
Expand Down Expand Up @@ -791,7 +791,7 @@ def __str__(self) -> str:
if self._sizeAllocated >= 0:
strSizeAllocated = "/%s" % Util.num2str(self._sizeAllocated)
strType = ""
if self.raw:
if self.vdi_type == VdiType.RAW:
strType = "[RAW]"
strSizeVHD = ""

Expand Down Expand Up @@ -924,7 +924,7 @@ def _vdi_is_raw(self, vdi_path):
Given path to vdi determine if it is raw
"""
uuid = self.extractUuid(vdi_path)
return self.sr.vdis[uuid].raw
return self.sr.vdis[uuid].vdi_type == VdiType.RAW

def _coalesceVHD(self, timeOut):
Util.log(" Running VHD coalesce on %s" % self)
Expand Down Expand Up @@ -1146,9 +1146,9 @@ def extractUuid(path):
# TODO: validate UUID format
return uuid

def __init__(self, sr, uuid, raw):
VDI.__init__(self, sr, uuid, raw)
if self.raw:
def __init__(self, sr, uuid, vdi_type):
VDI.__init__(self, sr, uuid, vdi_type)
if self.vdi_type == VdiType.RAW:
self.fileName = "%s%s" % (self.uuid, VdiTypeExtension.RAW)
else:
self.fileName = "%s%s" % (self.uuid, VdiTypeExtension.VHD)
Expand Down Expand Up @@ -1238,13 +1238,13 @@ def extractUuid(path):

@override
def getDriverName(self) -> str:
if self.raw:
if self.vdi_type == VdiType.RAW:
return self.DRIVER_NAME_RAW
return self.DRIVER_NAME_VHD

def inflate(self, size):
"""inflate the LV containing the VHD to 'size'"""
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self._activate()
self.sr.lock()
Expand All @@ -1259,7 +1259,7 @@ def inflate(self, size):

def deflate(self):
"""deflate the LV containing the VHD to minimum"""
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self._activate()
self.sr.lock()
Expand All @@ -1277,7 +1277,7 @@ def inflateFully(self):
def inflateParentForCoalesce(self):
"""Inflate the parent only as much as needed for the purposes of
coalescing"""
if self.parent.raw:
if self.parent.vdi_type == VdiType.RAW:
return
inc = self._calcExtraSpaceForCoalescing()
if inc > 0:
Expand All @@ -1286,7 +1286,7 @@ def inflateParentForCoalesce(self):

@override
def updateBlockInfo(self) -> Optional[str]:
if not self.raw:
if self.vdi_type != VdiType.RAW:
return VDI.updateBlockInfo(self)
return None

Expand All @@ -1296,7 +1296,7 @@ def rename(self, uuid) -> None:
oldLVName = self.fileName
VDI.rename(self, uuid)
self.fileName = lvhdutil.LV_PREFIX[VdiType.VHD] + self.uuid
if self.raw:
if self.vdi_type == VdiType.RAW:
self.fileName = lvhdutil.LV_PREFIX[VdiType.RAW] + self.uuid
self.path = os.path.join(self.sr.path, self.fileName)
assert(not self.sr.lvmCache.checkLV(self.fileName))
Expand Down Expand Up @@ -1335,7 +1335,7 @@ def _loadInfoSizeVHD(self):
(and not using the VHD batch scanner) as an optimization: this info is
relatively expensive and we need it only for VDI's involved in
coalescing."""
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self._activate()
self._sizeVHD = vhdutil.getSizePhys(self.path)
Expand All @@ -1353,21 +1353,21 @@ def _loadInfoSizeAllocated(self):
"""
Get the allocated size of the VHD volume.
"""
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self._activate()
self._sizeAllocated = vhdutil.getAllocatedSize(self.path)

@override
def _loadInfoHidden(self) -> None:
if self.raw:
if self.vdi_type == VdiType.RAW:
self.hidden = self.sr.lvmCache.getHidden(self.fileName)
else:
VDI._loadInfoHidden(self)

@override
def _setHidden(self, hidden=True) -> None:
if self.raw:
if self.vdi_type == VdiType.RAW:
self.sr.lvmCache.setHidden(self.fileName, hidden)
self.hidden = hidden
else:
Expand All @@ -1376,7 +1376,7 @@ def _setHidden(self, hidden=True) -> None:
@override
def __str__(self) -> str:
strType = "VHD"
if self.raw:
if self.vdi_type == VdiType.RAW:
strType = "RAW"
strHidden = ""
if self.hidden:
Expand All @@ -1398,7 +1398,7 @@ def __str__(self) -> str:

@override
def validate(self, fast=False) -> None:
if not self.raw:
if self.vdi_type != VdiType.RAW:
VDI.validate(self, fast)

@override
Expand All @@ -1422,7 +1422,7 @@ def _setParent(self, parent) -> None:
self.sr.lvmCache.setReadonly(self.fileName, False)

try:
vhdutil.setParent(self.path, parent.path, parent.raw)
vhdutil.setParent(self.path, parent.path, parent.vdi_type == VdiType.RAW)
finally:
if self.lvReadonly:
self.sr.lvmCache.setReadonly(self.fileName, True)
Expand Down Expand Up @@ -1454,7 +1454,7 @@ def _deactivate(self):
def _increaseSizeVirt(self, size, atomic=True) -> None:
"ensure the virtual size of 'self' is at least 'size'"
self._activate()
if not self.raw:
if self.vdi_type != VdiType.RAW:
VDI._increaseSizeVirt(self, size, atomic)
return

Expand Down Expand Up @@ -1508,7 +1508,7 @@ def _queryVHDBlocks(self) -> bytes:

@override
def _calcExtraSpaceForCoalescing(self) -> int:
if self.parent.raw:
if self.parent.vdi_type == VdiType.RAW:
return 0 # raw parents are never deflated in the first place
sizeCoalesced = lvhdutil.calcSizeVHDLV(self._getCoalescedSizeData())
Util.log("Coalesced size = %s" % Util.num2str(sizeCoalesced))
Expand Down Expand Up @@ -1575,12 +1575,12 @@ def getDrbdSize(self, fetch=False):
@override
def getAllocatedSize(self) -> int:
if self._sizeAllocated == -1:
if not self.raw:
if self.vdi_type != VdiType.RAW:
self._sizeAllocated = self.sr._vhdutil.get_allocated_size(self.uuid)
return self._sizeAllocated

def inflate(self, size):
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self.sr.lock()
try:
Expand All @@ -1595,7 +1595,7 @@ def inflate(self, size):
self._sizeAllocated = -1

def deflate(self):
if self.raw:
if self.vdi_type == VdiType.RAW:
return
self.sr.lock()
try:
Expand All @@ -1610,7 +1610,7 @@ def deflate(self):
self._sizeAllocated = -1

def inflateFully(self):
if not self.raw:
if self.vdi_type != VdiType.RAW:
self.inflate(LinstorVhdUtil.compute_volume_size(self.sizeVirt, self.vdi_type))

@override
Expand All @@ -1637,7 +1637,7 @@ def delete(self) -> None:

@override
def validate(self, fast=False) -> None:
if not self.raw and not self.sr._vhdutil.check(self.uuid, fast=fast):
if self.vdi_type != VdiType.RAW and not self.sr._vhdutil.check(self.uuid, fast=fast):
raise util.SMException('VHD {} corrupted'.format(self))

@override
Expand Down Expand Up @@ -1730,7 +1730,7 @@ def _activateChain(self):
def _setHidden(self, hidden=True) -> None:
HIDDEN_TAG = 'hidden'

if self.raw:
if self.vdi_type == VdiType.RAW:
self.sr._linstor.update_volume_metadata(self.uuid, {
HIDDEN_TAG: hidden
})
Expand Down Expand Up @@ -1759,15 +1759,15 @@ def _queryVHDBlocks(self) -> bytes:
return self.sr._vhdutil.get_block_bitmap(self.uuid)

def _inflateParentForCoalesce(self):
if self.parent.raw:
if self.parent.vdi_type == VdiType.RAW:
return
inc = self._calcExtraSpaceForCoalescing()
if inc > 0:
self.parent.inflate(self.parent.getDrbdSize() + inc)

@override
def _calcExtraSpaceForCoalescing(self) -> int:
if self.parent.raw:
if self.parent.vdi_type == VdiType.RAW:
return 0
size_coalesced = LinstorVhdUtil.compute_volume_size(
self._getCoalescedSizeData(), self.vdi_type
Expand Down Expand Up @@ -2555,7 +2555,7 @@ def _doCoalesceLeaf(self, vdi):

# update the VDI record
vdi.parent.delConfig(VDI.DB_VHD_PARENT)
if vdi.parent.raw:
if vdi.parent.vdi_type == VdiType.RAW:
vdi.parent.setConfig(VDI.DB_VDI_TYPE, VdiType.RAW)
vdi.parent.delConfig(VDI.DB_VHD_BLOCKS)
util.fistpoint.activate("LVHDRT_coaleaf_after_vdirec", self.uuid)
Expand Down Expand Up @@ -2586,7 +2586,7 @@ def _doCoalesceLeaf(self, vdi):
self._updateSlavesOnResize(parent)

def _calcExtraSpaceNeeded(self, child, parent) -> int:
assert(not parent.raw) # raw parents not supported
assert(parent.vdi_type != VdiType.RAW) # raw parents not supported
extra = child.getSizeVHD() - parent.getSizeVHD()
if extra < 0:
extra = 0
Expand Down Expand Up @@ -2929,7 +2929,7 @@ def cleanup(self):
@override
def needUpdateBlockInfo(self) -> bool:
for vdi in self.vdis.values():
if vdi.scanError or vdi.raw or len(vdi.children) == 0:
if vdi.scanError or vdi.vdi_type == VdiType.RAW or len(vdi.children) == 0:
continue
if not vdi.getConfig(vdi.DB_VHD_BLOCKS):
return True
Expand All @@ -2939,7 +2939,7 @@ def needUpdateBlockInfo(self) -> bool:
def updateBlockInfo(self) -> None:
numUpdated = 0
for vdi in self.vdis.values():
if vdi.scanError or vdi.raw or len(vdi.children) == 0:
if vdi.scanError or vdi.vdi_type == VdiType.RAW or len(vdi.children) == 0:
continue
if not vdi.getConfig(vdi.DB_VHD_BLOCKS):
vdi.updateBlockInfo()
Expand Down Expand Up @@ -2999,7 +2999,7 @@ def _liveLeafCoalesce(self, vdi) -> bool:
we'll need to resize the parent, which can take a while due to zeroing
out of the extended portion of the LV. Do it before pausing the child
to avoid a protracted downtime"""
if vdi.parent.raw and vdi.sizeVirt > vdi.parent.sizeVirt:
if vdi.parent.vdi_type == VdiType.RAW and vdi.sizeVirt > vdi.parent.sizeVirt:
self.lvmCache.setReadonly(vdi.parent.fileName, False)
vdi.parent._increaseSizeVirt(vdi.sizeVirt)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import ipc

from vditype import VdiType


class FakeFile(object):
pass
Expand Down Expand Up @@ -1499,7 +1501,7 @@ def run_abortable(func, ret, ns, abortTest, pollInterval, timeOut):
mock_ipc_flag.test.return_value = None

vdis = self.add_vdis_for_coalesce(sr)
vdis['parent'].raw = True
vdis['parent'].vdi_type = VdiType.RAW
mock_journaler.get.return_value = None

mock_vhdutil.getParent.return_value = vdis['parent'].path
Expand Down

0 comments on commit ddfc8d8

Please sign in to comment.