2828import lvutil
2929import lvmcache
3030import vhdutil
31- import lvhdutil
3231import scsiutil
3332import lock
3433import os
4140from journaler import Journaler
4241from refcounter import RefCounter
4342from ipc import IPCFlag
43+ from lvmcowutil import LV_PREFIX , NS_PREFIX_LVM , VG_LOCATION , VG_PREFIX
4444from lvmanager import LVActivator
4545from vditype import VdiType
4646import XenAPI # pylint: disable=import-error
5555import glob
5656from constants import CBTLOG_TAG
5757from fairlock import Fairlock
58- DEV_MAPPER_ROOT = os .path .join ('/dev/mapper' , lvhdutil . VG_PREFIX )
58+ DEV_MAPPER_ROOT = os .path .join ('/dev/mapper' , VG_PREFIX )
5959
6060geneology : Dict [str , List [str ]] = {}
6161CAPABILITIES = ["SR_PROBE" , "SR_UPDATE" , "SR_TRIM" ,
@@ -559,7 +559,7 @@ def delete(self, uuid) -> None:
559559
560560 self ._removeMetadataVolume ()
561561 self .lvmCache .refresh ()
562- if len (lvhdutil . getLVInfo (self .lvmCache )) > 0 :
562+ if len (LvmCowUtil . getVolumeInfo (self .lvmCache )) > 0 :
563563 raise xs_errors .XenError ('SRNotEmpty' )
564564
565565 if not success :
@@ -596,7 +596,7 @@ def attach(self, uuid) -> None:
596596
597597 # Test Legacy Mode Flag and update if VHD volumes exist
598598 if self .isMaster and self .legacyMode :
599- vdiInfo = lvhdutil .getVDIInfo (self .lvmCache )
599+ vdiInfo = LvmCowUtil .getVDIInfo (self .lvmCache )
600600 for uuid , info in vdiInfo .items ():
601601 if VdiType .isCowImage (info .vdiType ):
602602 self .legacyMode = False
@@ -858,8 +858,8 @@ def _updateStats(self, uuid, virtAllocDelta):
858858 @deviceCheck
859859 def probe (self ) -> str :
860860 return lvutil .srlist_toxml (
861- lvutil .scan_srlist (lvhdutil . VG_PREFIX , self .dconf ['device' ]),
862- lvhdutil . VG_PREFIX ,
861+ lvutil .scan_srlist (VG_PREFIX , self .dconf ['device' ]),
862+ VG_PREFIX ,
863863 ('metadata' in self .srcmd .params ['sr_sm_config' ] and \
864864 self .srcmd .params ['sr_sm_config' ]['metadata' ] == 'true' ))
865865
@@ -869,7 +869,7 @@ def vdi(self, uuid) -> VDI.VDI:
869869
870870 def _loadvdis (self ):
871871 self .virtual_allocation = 0
872- self .vdiInfo = lvhdutil .getVDIInfo (self .lvmCache )
872+ self .vdiInfo = LvmCowUtil .getVDIInfo (self .lvmCache )
873873 self .allVDIs = {}
874874
875875 for uuid , info in self .vdiInfo .items ():
@@ -927,7 +927,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
927927 we're still in the context of the failed snapshot operation since the
928928 VBD is paused for the duration of the operation"""
929929 util .SMlog ("*** INTERRUPTED CLONE OP: for %s (%s)" % (origUuid , jval ))
930- lvs = lvhdutil . getLVInfo (self .lvmCache )
930+ lvs = LvmCowUtil . getVolumeInfo (self .lvmCache )
931931 baseUuid , clonUuid = jval .split ("_" )
932932
933933 cowutil = None # TODO
@@ -951,7 +951,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
951951 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
952952 return
953953
954- vdis = lvhdutil .getVDIInfo (self .lvmCache )
954+ vdis = LvmCowUtil .getVDIInfo (self .lvmCache )
955955 if vdis [origUuid ].scanError or (clonUuid and vdis [clonUuid ].scanError ):
956956 util .SMlog ("One or both leaves invalid => revert" )
957957 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
@@ -1001,7 +1001,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10011001 if VdiType .isCowImage (base .vdiType ):
10021002 self .lvActivator .activate (baseUuid , base .name , False )
10031003 origRefcountNormal = 1
1004- cow_info = cowutil .getInfo (basePath , lvhdutil .extractUuid , False )
1004+ cow_info = cowutil .getInfo (basePath , LvmCowUtil .extractUuid , False )
10051005 if cow_info .hidden :
10061006 cowutil .setHidden (basePath , False )
10071007 elif base .hidden :
@@ -1020,7 +1020,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10201020 # inflate the parent to fully-allocated size
10211021 if VdiType .isCowImage (base .vdiType ):
10221022 fullSize = lvmcowutil .calcVolumeSize (vhdInfo .sizeVirt )
1023- lvmcowutil .inflate (self .journaler , self .uuid , baseUuid , fullSize )
1023+ lvmcowutil .inflate (self .journaler , self .uuid , baseUuid , base . vdiType , fullSize )
10241024
10251025 # rename back
10261026 origLV = lvhdutil .LV_PREFIX [base .vdiType ] + origUuid
@@ -1037,7 +1037,7 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
10371037
10381038 # update LVM metadata on slaves
10391039 slaves = util .get_slaves_attached_on (self .session , [origUuid ])
1040- lvhdutil . lvRefreshOnSlaves (self .session , self .uuid , self .vgname ,
1040+ LvmCowUtil . refreshVolumeOnSlaves (self .session , self .uuid , self .vgname ,
10411041 origLV , origUuid , slaves )
10421042
10431043 util .SMlog ("*** INTERRUPTED CLONE OP: rollback success" )
@@ -1193,8 +1193,9 @@ def _undoAllInflateJournals(self):
11931193 if vdi .readonly :
11941194 self .lvmCache .setReadonly (vdi .lvname , True )
11951195 if "true" == self .session .xenapi .SR .get_shared (self .sr_ref ):
1196- lvhdutil .lvRefreshOnAllSlaves (self .session , self .uuid ,
1197- self .vgname , vdi .lvname , uuid )
1196+ LvmCowUtil .refreshVolumeOnAllSlaves (
1197+ self .session , self .uuid , self .vgname , vdi .lvname , uuid
1198+ )
11981199 self .journaler .remove (lvhdutil .JRN_INFLATE , uuid )
11991200 delattr (self , "vdiInfo" )
12001201 delattr (self , "allVDIs" )
@@ -1224,12 +1225,11 @@ def _undoAllVHDJournals(self):
12241225 # Attempt to reclaim unused space
12251226
12261227
1227- vhdInfo = cowutil .getInfo (vdi .path , lvhdutil .extractUuid , False )
1228+ vhdInfo = cowutil .getInfo (vdi .path , LvmCowUtil .extractUuid , False )
12281229 NewSize = lvmcowutil .calcVolumeSize (vhdInfo .sizeVirt )
12291230 if NewSize < fullSize :
1230- lvhdutil .deflate (self .lvmCache , vdi .lvname , int (NewSize ))
1231- lvhdutil .lvRefreshOnAllSlaves (self .session , self .uuid ,
1232- self .vgname , vdi .lvname , uuid )
1231+ lvmcowutil .deflate (self .lvmCache , vdi .lvname , int (NewSize ))
1232+ LvmCowUtil .refreshVolumeOnAllSlaves (self .session , self .uuid , self .vgname , vdi .lvname , uuid )
12331233 self .lvmCache .remove (jlvName )
12341234 delattr (self , "vdiInfo" )
12351235 delattr (self , "allVDIs" )
@@ -1880,7 +1880,7 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
18801880 self .sr .lvActivator .add (snapUuid , snapLV , False )
18811881 parentRaw = (self .vdi_type == VdiType .RAW )
18821882 self ._cowutil .snapshot (snapPath , self .path , parentRaw , cowutil .getPreallocationVirtSize ())
1883- snapParent = self ._cowutil .getParent (snapPath , lvhdutil .extractUuid )
1883+ snapParent = self ._cowutil .getParent (snapPath , LvmCowUtil .extractUuid )
18841884
18851885 snapVDI = LVHDVDI (self .sr , snapUuid )
18861886 snapVDI .read_only = False
@@ -2106,7 +2106,7 @@ def _determineType(self):
21062106 # when doing attach_from_config, the VG won't be there yet
21072107 return False
21082108
2109- lvs = lvhdutil . getLVInfo (self .sr .lvmCache )
2109+ lvs = LvmCowUtil . getVolumeInfo (self .sr .lvmCache )
21102110 if lvs .get (self .uuid ):
21112111 self ._initFromLVInfo (lvs [self .uuid ])
21122112 return True
@@ -2120,7 +2120,7 @@ def _loadThis(self):
21202120 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
21212121 return
21222122 try :
2123- lvs = lvhdutil . getLVInfo (self .sr .lvmCache , self .lvname )
2123+ lvs = LvmCowUtil . getVolumeInfo (self .sr .lvmCache , self .lvname )
21242124 except util .CommandException as e :
21252125 raise xs_errors .XenError ('VDIUnavailable' ,
21262126 opterr = '%s (LV scan error)' % os .strerror (abs (e .code )))
@@ -2129,7 +2129,7 @@ def _loadThis(self):
21292129 self ._initFromLVInfo (lvs [self .uuid ])
21302130 if VdiType .isCowImage (self .vdi_type ):
21312131 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
2132- vhdInfo = self ._cowutil .getInfo (self .path , lvhdutil .extractUuid , False )
2132+ vhdInfo = self ._cowutil .getInfo (self .path , LvmCowUtil .extractUuid , False )
21332133 if not vhdInfo :
21342134 raise xs_errors .XenError ('VDIUnavailable' , \
21352135 opterr = 'getVHDInfo failed' )
@@ -2146,7 +2146,7 @@ def _chainSetActive(self, active, binary, persistent=False):
21462146 vdiList = {self .uuid : self .lvname }
21472147 if VdiType .isCowImage (self .vdi_type ):
21482148 vdiList = vhdutil .getParentChain (self .lvname ,
2149- lvhdutil .extractUuid , self .sr .vgname )
2149+ LvmCowUtil .extractUuid , self .sr .vgname )
21502150 for uuid , lvName in vdiList .items ():
21512151 binaryParam = binary
21522152 if uuid != self .uuid :
@@ -2181,10 +2181,9 @@ def _prepareThin(self, attach):
21812181 if self .sr .isMaster :
21822182 # the master can prepare the VDI locally
21832183 if attach :
2184- lvhdutil . attachThin (self .sr .journaler , self .sr .uuid , self .uuid )
2184+ self . lvcowutil . attachThin (self .sr .journaler , self .sr .uuid , self .uuid , self . vdi_type )
21852185 else :
2186- lvhdutil .detachThin (self .session , self .sr .lvmCache ,
2187- self .sr .uuid , self .uuid )
2186+ self .lvcowutil .detachThin (self .session , self .sr .lvmCache , self .sr .uuid , self .uuid , self .vdi_type )
21882187 else :
21892188 fn = "attach"
21902189 if not attach :
0 commit comments