3737import XenAPI # pylint: disable=import-error
3838import util
3939import lvutil
40- import lvhdutil
40+ import lvmcowutil
4141import lvmcache
4242import journaler
4343import fjournaler
5252from time import monotonic as _time
5353
5454from cowutil import CowUtil , getCowUtil
55+ from lvmcowutil import LV_PREFIX , NS_PREFIX_LVM , VG_LOCATION , VG_PREFIX
5556from vditype import VdiType , VdiTypeExtension , VDI_COW_TYPES , VDI_TYPE_TO_EXTENSION
5657
5758try :
@@ -767,7 +768,7 @@ def rename(self, uuid) -> None:
767768
768769 def delete (self ) -> None :
769770 "Physically delete the VDI"
770- lock .Lock .cleanup (self .uuid , lvhdutil . NS_PREFIX_LVM + self .sr .uuid )
771+ lock .Lock .cleanup (self .uuid , NS_PREFIX_LVM + self .sr .uuid )
771772 lock .Lock .cleanupAll (self .uuid )
772773 self ._clear ()
773774
@@ -1023,7 +1024,7 @@ def _tagChildrenForRelink(self):
10231024 child ._tagChildrenForRelink ()
10241025
10251026 def _loadInfoParent (self ):
1026- ret = self .cowutil .getParent (self .path , lvhdutil .extractUuid )
1027+ ret = self .cowutil .getParent (self .path , LvmCowUtil .extractUuid )
10271028 if ret :
10281029 self .parentUuid = ret
10291030
@@ -1225,7 +1226,7 @@ def load(self, info=None) -> None:
12251226
12261227 @staticmethod
12271228 def extractUuid (path ):
1228- return lvhdutil .extractUuid (path )
1229+ return LvmCowUtil .extractUuid (path )
12291230
12301231 def inflate (self , size ):
12311232 """inflate the LV containing the VHD to 'size'"""
@@ -1234,7 +1235,7 @@ def inflate(self, size):
12341235 self ._activate ()
12351236 self .sr .lock ()
12361237 try :
1237- lvhdutil . inflate (self .sr .journaler , self .sr .uuid , self .uuid , size )
1238+ self . lvmcowutil . inflate (self .sr .journaler , self .sr .uuid , self .uuid , self . vdi_type , size )
12381239 util .fistpoint .activate ("LVHDRT_inflating_the_parent" , self .sr .uuid )
12391240 finally :
12401241 self .sr .unlock ()
@@ -1243,21 +1244,21 @@ def inflate(self, size):
12431244 self ._sizeAllocated = - 1
12441245
12451246 def deflate (self ):
1246- """deflate the LV containing the VHD to minimum"""
1247+ """deflate the LV containing the image to minimum"""
12471248 if not VdiType .isCowImage (self .vdi_type ):
12481249 return
12491250 self ._activate ()
12501251 self .sr .lock ()
12511252 try :
1252- lvhdutil .deflate (self .sr .lvmCache , self .fileName , self .getSizePhys ())
1253+ self . lvmcowutil .deflate (self .sr .lvmCache , self .fileName , self .getSizePhys ())
12531254 finally :
12541255 self .sr .unlock ()
12551256 self .sizeLV = self .sr .lvmCache .getSize (self .fileName )
12561257 self ._sizePhys = - 1
12571258 self ._sizeAllocated = - 1
12581259
12591260 def inflateFully (self ):
1260- self .inflate (lvhdutil . calcSizeVHDLV (self .sizeVirt ))
1261+ self .inflate (self . lvmcowutil . calcVolumeSize (self .sizeVirt ))
12611262
12621263 def inflateParentForCoalesce (self ):
12631264 """Inflate the parent only as much as needed for the purposes of
@@ -1280,15 +1281,15 @@ def rename(self, uuid) -> None:
12801281 oldUuid = self .uuid
12811282 oldLVName = self .fileName
12821283 VDI .rename (self , uuid )
1283- self .fileName = lvhdutil . LV_PREFIX [self .vdi_type ] + self .uuid
1284+ self .fileName = LV_PREFIX [self .vdi_type ] + self .uuid
12841285 self .path = os .path .join (self .sr .path , self .fileName )
12851286 assert (not self .sr .lvmCache .checkLV (self .fileName ))
12861287
12871288 self .sr .lvmCache .rename (oldLVName , self .fileName )
12881289 if self .sr .lvActivator .get (oldUuid , False ):
12891290 self .sr .lvActivator .replace (oldUuid , self .uuid , self .fileName , False )
12901291
1291- ns = lvhdutil . NS_PREFIX_LVM + self .sr .uuid
1292+ ns = NS_PREFIX_LVM + self .sr .uuid
12921293 (cnt , bcnt ) = RefCounter .check (oldUuid , ns )
12931294 RefCounter .set (self .uuid , cnt , bcnt , ns )
12941295 RefCounter .reset (oldUuid , ns )
@@ -1304,7 +1305,7 @@ def delete(self) -> None:
13041305 self .sr .forgetVDI (self .uuid )
13051306 finally :
13061307 self .sr .unlock ()
1307- RefCounter .reset (self .uuid , lvhdutil . NS_PREFIX_LVM + self .sr .uuid )
1308+ RefCounter .reset (self .uuid , NS_PREFIX_LVM + self .sr .uuid )
13081309 VDI .delete (self )
13091310
13101311 @override
@@ -1476,12 +1477,11 @@ def _setSizeVirt(self, size) -> None:
14761477 subtree are guaranteed to be unplugged (and remain so for the duration
14771478 of the operation): this operation is only safe for offline VHDs"""
14781479 self ._activate ()
1479- jFile = lvhdutil . createVHDJournalLV (self .sr .lvmCache , self .uuid , self . cowutil . getResizeJournalSize () )
1480+ jFile = self . lvmcowutil . createResizeJournal (self .sr .lvmCache , self .uuid )
14801481 try :
1481- lvhdutil .setSizeVirt (self .sr .journaler , self .sr .uuid , self .uuid ,
1482- size , jFile )
1482+ self .lvmcowutil .setSizeVirt (self .sr .journaler , self .sr .uuid , self .uuid , self .vdi_type , size , jFile )
14831483 finally :
1484- lvhdutil . deleteVHDJournalLV (self .sr .lvmCache , self .uuid )
1484+ self . lvmcowutil . destroyResizeJournal (self .sr .lvmCache , self .uuid )
14851485
14861486 @override
14871487 def _queryVHDBlocks (self ) -> bytes :
@@ -1492,7 +1492,7 @@ def _queryVHDBlocks(self) -> bytes:
14921492 def _calcExtraSpaceForCoalescing (self ) -> int :
14931493 if not VdiType .isCowImage (self .parent .vdi_type ):
14941494 return 0 # raw parents are never deflated in the first place
1495- sizeCoalesced = lvhdutil . calcSizeVHDLV (self ._getCoalescedSizeData ())
1495+ sizeCoalesced = self . lvmcowutil . calcVolumeSize (self ._getCoalescedSizeData ())
14961496 Util .log ("Coalesced size = %s" % Util .num2str (sizeCoalesced ))
14971497 return sizeCoalesced - self .parent .sizeLV
14981498
@@ -1501,13 +1501,13 @@ def _calcExtraSpaceForLeafCoalescing(self) -> int:
15011501 """How much extra space in the SR will be required to
15021502 [live-]leaf-coalesce this VDI"""
15031503 # we can deflate the leaf to minimize the space requirements
1504- deflateDiff = self .sizeLV - lvhdutil .calcSizeLV (self .getSizePhys ())
1504+ deflateDiff = self .sizeLV - lvutil .calcSizeLV (self .getSizePhys ())
15051505 return self ._calcExtraSpaceForCoalescing () - deflateDiff
15061506
15071507 @override
15081508 def _calcExtraSpaceForSnapshotCoalescing (self ) -> int :
15091509 return self ._calcExtraSpaceForCoalescing () + \
1510- lvhdutil .calcSizeLV (self .getSizePhys ())
1510+ lvutil .calcSizeLV (self .getSizePhys ())
15111511
15121512
15131513class LinstorVDI (VDI ):
@@ -2880,8 +2880,8 @@ class LVMSR(SR):
28802880
28812881 def __init__ (self , uuid , xapi , createLock , force ):
28822882 SR .__init__ (self , uuid , xapi , createLock , force )
2883- self .vgName = "%s%s" % (lvhdutil . VG_PREFIX , self .uuid )
2884- self .path = os .path .join (lvhdutil . VG_LOCATION , self .vgName )
2883+ self .vgName = "%s%s" % (VG_PREFIX , self .uuid )
2884+ self .path = os .path .join (VG_LOCATION , self .vgName )
28852885
28862886 sr_ref = self .xapi .session .xenapi .SR .get_by_uuid (self .uuid )
28872887 other_conf = self .xapi .session .xenapi .SR .get_other_config (sr_ref )
@@ -2958,7 +2958,7 @@ def _scan(self, force):
29582958 for i in range (SR .SCAN_RETRY_ATTEMPTS ):
29592959 error = False
29602960 self .lvmCache .refresh ()
2961- vdis = lvhdutil .getVDIInfo (self .lvmCache )
2961+ vdis = LvmCowUtil .getVDIInfo (self .lvmCache )
29622962 for uuid , vdiInfo in vdis .items ():
29632963 if vdiInfo .scanError :
29642964 error = True
@@ -3007,7 +3007,7 @@ def _updateNode(self, vdi) -> None:
30073007 # this node is really the parent node) - minus 1 if it is online (since
30083008 # non-leaf nodes increment their normal counts when they are online and
30093009 # we are now a leaf, storing that 1 in the binary refcount).
3010- ns = lvhdutil . NS_PREFIX_LVM + self .uuid
3010+ ns = NS_PREFIX_LVM + self .uuid
30113011 cCnt , cBcnt = RefCounter .check (vdi .uuid , ns )
30123012 pCnt , pBcnt = RefCounter .check (vdi .parent .uuid , ns )
30133013 pCnt = pCnt - cBcnt
@@ -3023,17 +3023,17 @@ def _finishCoalesceLeaf(self, parent) -> None:
30233023
30243024 @override
30253025 def _calcExtraSpaceNeeded (self , child , parent ) -> int :
3026- return lvhdutil . calcSizeVHDLV (parent .sizeVirt ) - parent .sizeLV
3026+ return parent . lvmcowutil . calcVolumeSize (parent .sizeVirt ) - parent .sizeLV
30273027
30283028 @override
30293029 def _handleInterruptedCoalesceLeaf (self ) -> None :
30303030 entries = self .journaler .getAll (VDI .JRN_LEAF )
30313031 for uuid , parentUuid in entries .items ():
3032- childLV = lvhdutil . LV_PREFIX [VdiType .VHD ] + uuid
3033- tmpChildLV = lvhdutil . LV_PREFIX [VdiType .VHD ] + \
3032+ childLV = LV_PREFIX [VdiType .VHD ] + uuid
3033+ tmpChildLV = LV_PREFIX [VdiType .VHD ] + \
30343034 self .TMP_RENAME_PREFIX + uuid
3035- parentLV1 = lvhdutil . LV_PREFIX [VdiType .VHD ] + parentUuid
3036- parentLV2 = lvhdutil . LV_PREFIX [VdiType .RAW ] + parentUuid
3035+ parentLV1 = LV_PREFIX [VdiType .VHD ] + parentUuid
3036+ parentLV2 = LV_PREFIX [VdiType .RAW ] + parentUuid
30373037 parentPresent = (self .lvmCache .checkLV (parentLV1 ) or \
30383038 self .lvmCache .checkLV (parentLV2 ))
30393039 if parentPresent or self .lvmCache .checkLV (tmpChildLV ):
@@ -3073,7 +3073,7 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
30733073 # refcount (best effort - assume that it had succeeded if the
30743074 # second rename succeeded; if not, this adjustment will be wrong,
30753075 # leading to a non-deactivation of the LV)
3076- ns = lvhdutil . NS_PREFIX_LVM + self .uuid
3076+ ns = NS_PREFIX_LVM + self .uuid
30773077 cCnt , cBcnt = RefCounter .check (child .uuid , ns )
30783078 pCnt , pBcnt = RefCounter .check (parent .uuid , ns )
30793079 pCnt = pCnt + cBcnt
@@ -3120,7 +3120,7 @@ def _checkSlaves(self, vdi):
31203120 "lvName1" : vdi .fileName ,
31213121 "action2" : "cleanupLockAndRefcount" ,
31223122 "uuid2" : vdi .uuid ,
3123- "ns2" : lvhdutil . NS_PREFIX_LVM + self .uuid }
3123+ "ns2" : NS_PREFIX_LVM + self .uuid }
31243124 onlineHosts = self .xapi .getOnlineHosts ()
31253125 abortFlag = IPCFlag (self .uuid )
31263126 for pbdRecord in self .xapi .getAttachedPBDs ():
@@ -3145,7 +3145,7 @@ def _updateSlavesOnUndoLeafCoalesce(self, parent, child) -> None:
31453145 child )
31463146 return
31473147
3148- tmpName = lvhdutil . LV_PREFIX [VdiType .VHD ] + \
3148+ tmpName = LV_PREFIX [VdiType .VHD ] + \
31493149 self .TMP_RENAME_PREFIX + child .uuid
31503150 args = {"vgName" : self .vgName ,
31513151 "action1" : "deactivateNoRefcount" ,
@@ -3178,7 +3178,7 @@ def _updateSlavesOnRename(self, vdi, oldNameLV, origParentUuid) -> None:
31783178 "lvName2" : vdi .fileName ,
31793179 "action3" : "cleanupLockAndRefcount" ,
31803180 "uuid3" : origParentUuid ,
3181- "ns3" : lvhdutil . NS_PREFIX_LVM + self .uuid }
3181+ "ns3" : NS_PREFIX_LVM + self .uuid }
31823182 for slave in slaves :
31833183 Util .log ("Updating %s to %s on slave %s" % \
31843184 (oldNameLV , vdi .fileName ,
@@ -3194,7 +3194,7 @@ def _updateSlavesOnResize(self, vdi) -> None:
31943194 if not slaves :
31953195 util .SMlog ("Update-on-resize: %s not attached on any slave" % vdi )
31963196 return
3197- lvhdutil . lvRefreshOnSlaves (self .xapi .session , self .uuid , self .vgName ,
3197+ LvmCowUtil . refreshVolumeOnSlaves (self .xapi .session , self .uuid , self .vgName ,
31983198 vdi .fileName , vdi .uuid , slaves )
31993199
32003200
@@ -3973,7 +3973,7 @@ def debug(sr_uuid, cmd, vdi_uuid):
39733973 vdi ._activate ()
39743974 print ("VDI file: %s" % vdi .path )
39753975 if cmd == "deactivate" :
3976- ns = lvhdutil . NS_PREFIX_LVM + sr .uuid
3976+ ns = NS_PREFIX_LVM + sr .uuid
39773977 sr .lvmCache .deactivate (ns , vdi .uuid , vdi .fileName , False )
39783978 if cmd == "inflate" :
39793979 vdi .inflateFully ()
0 commit comments