Skip to content

Commit 3374c8a

Browse files
committed
lvm in progress
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent a74374b commit 3374c8a

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

drivers/LVMSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ def _setType(self, vdiType: str) -> None:
20462046
self.lvmcowutil = LvmCowUtil(self.cowutil)
20472047

20482048
def _initFromVDIInfo(self, vdiInfo):
2049-
self._setType(vdiType)
2049+
self._setType(vdiInfo.vdiType)
20502050
self.lvname = vdiInfo.lvName
20512051
self.size = vdiInfo.sizeVirt
20522052
self.utilisation = vdiInfo.sizeLV

drivers/cleanup.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def getAllLeaves(self):
751751
return leaves
752752

753753
def updateBlockInfo(self) -> Optional[str]:
754-
val = base64.b64encode(self._queryVHDBlocks()).decode()
754+
val = base64.b64encode(self._queryCowBlocks()).decode()
755755
self.setConfig(VDI.DB_VDI_BLOCKS, val)
756756
return val
757757

@@ -1087,7 +1087,7 @@ def _setSizeVirt(self, size) -> None:
10871087
jFile = os.path.join(self.sr.path, self.uuid)
10881088
self.cowutil.setSizeVirt(self.path, size, jFile)
10891089

1090-
def _queryVHDBlocks(self) -> bytes:
1090+
def _queryCowBlocks(self) -> bytes:
10911091
return self.cowutil.getBlockBitmap(self.path)
10921092

10931093
def _getCoalescedSizeData(self):
@@ -1200,7 +1200,7 @@ def getAllocatedSize(self) -> int:
12001200

12011201

12021202
class LVMVDI(VDI):
1203-
"""Object representing a VDI in an LVHD SR"""
1203+
"""Object representing a VDI in an LVM SR"""
12041204

12051205
JRN_ZERO = "zero" # journal entry type for zeroing out end of parent
12061206

@@ -1222,13 +1222,14 @@ def load(self, info=None) -> None:
12221222
self.hidden = info.hidden
12231223
self.parentUuid = info.parentUuid
12241224
self.path = os.path.join(self.sr.path, self.fileName)
1225+
self.lvmcowutil = LvmCowUtil(self.cowutil)
12251226

12261227
@staticmethod
12271228
def extractUuid(path):
12281229
return LvmCowUtil.extractUuid(path)
12291230

12301231
def inflate(self, size):
1231-
"""inflate the LV containing the VHD to 'size'"""
1232+
"""inflate the LV containing the COW image to 'size'"""
12321233
if not VdiType.isCowImage(self.vdi_type):
12331234
return
12341235
self._activate()
@@ -1314,8 +1315,8 @@ def getSizePhys(self) -> int:
13141315
return self._sizePhys
13151316

13161317
def _loadInfoSizePhys(self):
1317-
"""Get the physical utilization of the VHD file. We do it individually
1318-
(and not using the VHD batch scanner) as an optimization: this info is
1318+
"""Get the physical utilization of the COW image file. We do it individually
1319+
(and not using the COW batch scanner) as an optimization: this info is
13191320
relatively expensive and we need it only for VDI's involved in
13201321
coalescing."""
13211322
if not VdiType.isCowImage(self.vdi_type):
@@ -1334,7 +1335,7 @@ def getAllocatedSize(self) -> int:
13341335

13351336
def _loadInfoSizeAllocated(self):
13361337
"""
1337-
Get the allocated size of the VHD volume.
1338+
Get the allocated size of the COW volume.
13381339
"""
13391340
if not VdiType.isCowImage(self.vdi_type):
13401341
return
@@ -1386,7 +1387,7 @@ def validate(self, fast=False) -> None:
13861387

13871388
@override
13881389
def _doCoalesce(self) -> None:
1389-
"""LVHD parents must first be activated, inflated, and made writable"""
1390+
"""LVMVDI parents must first be activated, inflated, and made writable"""
13901391
try:
13911392
self._activateChain()
13921393
self.sr.lvmCache.setReadonly(self.parent.fileName, False)
@@ -1415,10 +1416,10 @@ def _setParent(self, parent) -> None:
14151416
parent.children.append(self)
14161417
try:
14171418
self.setConfig(self.DB_VDI_PARENT, self.parentUuid)
1418-
Util.log("Updated the vhd-parent field for child %s with %s" % \
1419+
Util.log("Updated the VDI-parent field for child %s with %s" % \
14191420
(self.uuid, self.parentUuid))
14201421
except:
1421-
Util.log("Failed to update the vhd-parent with %s for child %s" % \
1422+
Util.log("Failed to update the VDI-parent with %s for child %s" % \
14221423
(self.parentUuid, self.uuid))
14231424

14241425
def _activate(self):
@@ -1474,7 +1475,7 @@ def _increaseSizeVirt(self, size, atomic=True) -> None:
14741475
def _setSizeVirt(self, size) -> None:
14751476
"""WARNING: do not call this method directly unless all VDIs in the
14761477
subtree are guaranteed to be unplugged (and remain so for the duration
1477-
of the operation): this operation is only safe for offline VHDs"""
1478+
of the operation): this operation is only safe for offline COW images."""
14781479
self._activate()
14791480
jFile = self.lvmcowutil.createResizeJournal(self.sr.lvmCache, self.uuid)
14801481
try:
@@ -1483,9 +1484,9 @@ def _setSizeVirt(self, size) -> None:
14831484
self.lvmcowutil.destroyResizeJournal(self.sr.lvmCache, self.uuid)
14841485

14851486
@override
1486-
def _queryVHDBlocks(self) -> bytes:
1487+
def _queryCowBlocks(self) -> bytes:
14871488
self._activate()
1488-
return VDI._queryVHDBlocks(self)
1489+
return VDI._queryCowBlocks(self)
14891490

14901491
@override
14911492
def _calcExtraSpaceForCoalescing(self) -> int:
@@ -1782,7 +1783,7 @@ def _setSizeVirt(self, size) -> None:
17821783
jfile, self.cowutil.getResizeJournalSize(), persistent=False, volume_name=jfile
17831784
)
17841785
try:
1785-
self.inflate(LinstorVhdUtil.compute_volume_size(size, self.vdi_type))
1786+
self.inflate(linstorcowutil.compute_volume_size(size, self.vdi_type))
17861787
self.sr._vhdutil.set_size_virt(size, jfile)
17871788
finally:
17881789
try:
@@ -1792,7 +1793,7 @@ def _setSizeVirt(self, size) -> None:
17921793
pass
17931794

17941795
@override
1795-
def _queryVHDBlocks(self) -> bytes:
1796+
def _queryCowBlocks(self) -> bytes:
17961797
return self.sr._vhdutil.get_block_bitmap(self.uuid)
17971798

17981799
def _inflateParentForCoalesce(self):
@@ -3083,14 +3084,21 @@ def _calcExtraSpaceNeeded(self, child, parent) -> int:
30833084
def _handleInterruptedCoalesceLeaf(self) -> None:
30843085
entries = self.journaler.getAll(VDI.JRN_LEAF)
30853086
for uuid, parentUuid in entries.items():
3086-
childLV = LV_PREFIX[VdiType.VHD] + uuid
3087-
tmpChildLV = LV_PREFIX[VdiType.VHD] + \
3088-
self.TMP_RENAME_PREFIX + uuid
3089-
parentLV1 = LV_PREFIX[VdiType.VHD] + parentUuid
3090-
parentLV2 = LV_PREFIX[VdiType.RAW] + parentUuid
3091-
parentPresent = (self.lvmCache.checkLV(parentLV1) or \
3092-
self.lvmCache.checkLV(parentLV2))
3093-
if parentPresent or self.lvmCache.checkLV(tmpChildLV):
3087+
undo = False
3088+
for prefix in LV_PREFIX.values():
3089+
parentLV = prefix + parentUuid
3090+
undo = self.lvmCache.checkLV(parentLV):
3091+
if undo:
3092+
break
3093+
3094+
if not undo:
3095+
for prefix in LV_PREFIX.values():
3096+
tmpChildLV = prefix + uuid
3097+
undo = self.lvmCache.checkLV(tmpChildLV)
3098+
if undo:
3099+
break
3100+
3101+
if undo:
30943102
self._undoInterruptedCoalesceLeaf(uuid, parentUuid)
30953103
else:
30963104
self._finishInterruptedCoalesceLeaf(uuid, parentUuid)
@@ -3199,8 +3207,7 @@ def _updateSlavesOnUndoLeafCoalesce(self, parent, child) -> None:
31993207
child)
32003208
return
32013209

3202-
tmpName = LV_PREFIX[VdiType.VHD] + \
3203-
self.TMP_RENAME_PREFIX + child.uuid
3210+
tmpName = child.vdi_type + self.TMP_RENAME_PREFIX + child.uuid
32043211
args = {"vgName": self.vgName,
32053212
"action1": "deactivateNoRefcount",
32063213
"lvName1": tmpName,

0 commit comments

Comments
 (0)