@@ -725,24 +725,25 @@ def scan(self, uuid) -> None:
725725 activated = True
726726 lvPath = os .path .join (self .path , lvname )
727727
728+ cowutil = None
729+
728730 if not VdiType .isCowImage (vdi_type ):
729731 size = self .lvmCache .getSize ( \
730732 lvhdutil .LV_PREFIX [vdi_type ] + vdi_uuid )
731733 utilisation = \
732734 util .roundup (lvutil .LVM_SIZE_INCREMENT ,
733735 int (size ))
734736 else :
735- parent = \
736- vhdutil ._getVHDParentNoCheck (lvPath )
737+ parent = cowutil .getParentNoCheck (lvPath )
737738
738739 if parent is not None :
739740 sm_config ['vhd-parent' ] = parent [len ( \
740741 lvhdutil .LV_PREFIX [VdiType .VHD ]):]
741- size = vhdutil .getSizeVirt (lvPath )
742+ size = cowutil .getSizeVirt (lvPath )
742743 if self .provision == "thin" :
743744 utilisation = \
744745 util .roundup (lvutil .LVM_SIZE_INCREMENT ,
745- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
746+ cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
746747 else :
747748 utilisation = lvhdutil .calcSizeVHDLV (int (size ))
748749
@@ -929,6 +930,8 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
929930 lvs = lvhdutil .getLVInfo (self .lvmCache )
930931 baseUuid , clonUuid = jval .split ("_" )
931932
933+ cowutil = None # TODO
934+
932935 # is there a "base copy" VDI?
933936 if not lvs .get (baseUuid ):
934937 # no base copy: make sure the original is there
@@ -962,7 +965,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
962965 parent = vdis [orig .parentUuid ]
963966 self .lvActivator .activate (parent .uuid , parent .lvName , False )
964967 origPath = os .path .join (self .path , orig .lvName )
965- if not vhdutil .check (origPath ):
968+ if cowutil .check (origPath ) != cowutil . CheckResult . Success :
966969 util .SMlog ("Orig VHD invalid => revert" )
967970 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
968971 return
@@ -971,7 +974,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
971974 clon = vdis [clonUuid ]
972975 clonPath = os .path .join (self .path , clon .lvName )
973976 self .lvActivator .activate (clonUuid , clon .lvName , False )
974- if not vhdutil .check (clonPath ):
977+ if cowutil .check (clonPath ) != cowutil . CheckResult . Success :
975978 util .SMlog ("Clon VHD invalid => revert" )
976979 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
977980 return
@@ -991,13 +994,16 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
991994 origRefcountBinary = RefCounter .check (origUuid , ns )[1 ]
992995 origRefcountNormal = 0
993996
997+ # TODO
998+ cowutil = None
999+
9941000 # un-hide the parent
9951001 if VdiType .isCowImage (base .vdiType ):
9961002 self .lvActivator .activate (baseUuid , base .name , False )
9971003 origRefcountNormal = 1
998- vhdInfo = vhdutil . getVHDInfo (basePath , lvhdutil .extractUuid , False )
999- if vhdInfo .hidden :
1000- vhdutil .setHidden (basePath , False )
1004+ cow_info = cowutil . getInfo (basePath , lvhdutil .extractUuid , False )
1005+ if cow_info .hidden :
1006+ cowutil .setHidden (basePath , False )
10011007 elif base .hidden :
10021008 self .lvmCache .setHidden (base .name , False )
10031009
@@ -1048,13 +1054,15 @@ def _completeCloneOp(self, vdis, origUuid, baseUuid, clonUuid):
10481054
10491055 cleanup .abort (self .uuid )
10501056
1057+ cowutil = None # TODO
1058+
10511059 # make sure the parent is hidden and read-only
10521060 if not base .hidden :
10531061 if not VdiType .isCowImage (base .vdiType ):
10541062 self .lvmCache .setHidden (base .lvName )
10551063 else :
10561064 basePath = os .path .join (self .path , base .lvName )
1057- vhdutil .setHidden (basePath )
1065+ cowutil .setHidden (basePath )
10581066 if not base .lvReadonly :
10591067 self .lvmCache .setReadonly (base .lvName , True )
10601068
@@ -1197,6 +1205,8 @@ def _undoAllVHDJournals(self):
11971205 if len (journals ) == 0 :
11981206 return
11991207 self ._loadvdis ()
1208+ # TODO
1209+ cowutil = None
12001210 for uuid , jlvName in journals :
12011211 vdi = self .vdis [uuid ]
12021212 util .SMlog ("Found VHD journal %s, reverting %s" % (uuid , vdi .path ))
@@ -1206,13 +1216,15 @@ def _undoAllVHDJournals(self):
12061216 lvhdutil .inflate (self .journaler , self .uuid , vdi .uuid , fullSize )
12071217 try :
12081218 jFile = os .path .join (self .path , jlvName )
1209- vhdutil .revert (vdi .path , jFile )
1219+ cowutil .revert (vdi .path , jFile )
12101220 except util .CommandException :
12111221 util .logException ("VHD journal revert" )
1212- vhdutil .check (vdi .path )
1222+ cowutil .check (vdi .path )
12131223 util .SMlog ("VHD revert failed but VHD ok: removing journal" )
12141224 # Attempt to reclaim unused space
1215- vhdInfo = vhdutil .getVHDInfo (vdi .path , lvhdutil .extractUuid , False )
1225+
1226+
1227+ vhdInfo = cowutil .getInfo (vdi .path , lvhdutil .extractUuid , False )
12161228 NewSize = lvhdutil .calcSizeVHDLV (vhdInfo .sizeVirt )
12171229 if NewSize < fullSize :
12181230 lvhdutil .deflate (self .lvmCache , vdi .lvname , int (NewSize ))
@@ -1374,7 +1386,9 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13741386 if self .exists :
13751387 raise xs_errors .XenError ('VDIExists' )
13761388
1377- size = vhdutil .validate_and_round_vhd_size (int (size ))
1389+ self ._cowutil = None # TODO
1390+
1391+ size = self ._cowutil .validateAndRoundImageSize (int (size ))
13781392
13791393 util .SMlog ("LVHDVDI.create: type = %s, %s (size=%s)" % \
13801394 (self .vdi_type , self .path , size ))
@@ -1385,7 +1399,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13851399 else :
13861400 if self .sr .provision == "thin" :
13871401 lvSize = util .roundup (lvutil .LVM_SIZE_INCREMENT ,
1388- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
1402+ self . _cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
13891403 elif self .sr .provision == "thick" :
13901404 lvSize = lvhdutil .calcSizeVHDLV (int (size ))
13911405
@@ -1396,8 +1410,8 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13961410 if not VdiType .isCowImage (self .vdi_type ):
13971411 self .size = self .sr .lvmCache .getSize (self .lvname )
13981412 else :
1399- vhdutil .create (self .path , int (size ), False , lvhdutil .MSIZE_MB )
1400- self .size = vhdutil .getSizeVirt (self .path )
1413+ self . _cowutil .create (self .path , int (size ), False , lvhdutil .MSIZE_MB )
1414+ self .size = self . _cowutil .getSizeVirt (self .path )
14011415 self .sr .lvmCache .deactivateNoRefcount (self .lvname )
14021416 except util .CommandException as e :
14031417 util .SMlog ("Unable to create VDI" )
@@ -1555,7 +1569,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
15551569 '(current size: %d, new size: %d)' % (self .size , size ))
15561570 raise xs_errors .XenError ('VDISize' , opterr = 'shrinking not allowed' )
15571571
1558- size = vhdutil . validate_and_round_vhd_size (int (size ))
1572+ size = self . _cowutil . validateAndRoundImageSize (int (size ))
15591573
15601574 if size == self .size :
15611575 return VDI .VDI .get_params (self )
@@ -1582,8 +1596,8 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
15821596 if lvSizeNew != lvSizeOld :
15831597 lvhdutil .inflate (self .sr .journaler , self .sr .uuid , self .uuid ,
15841598 lvSizeNew )
1585- vhdutil .setSizeVirtFast (self .path , size )
1586- self .size = vhdutil .getSizeVirt (self .path )
1599+ self . _cowutil .setSizeVirtFast (self .path , size )
1600+ self .size = self . _cowutil .getSizeVirt (self .path )
15871601 self .utilisation = self .sr .lvmCache .getSize (self .lvname )
15881602
15891603 vdi_ref = self .sr .srcmd .params ['vdi_ref' ]
@@ -1613,8 +1627,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
16131627 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
16141628 self .sr .lvActivator .activate (parent_uuid , parent_lvname , False )
16151629
1616- vhdutil .setParent (self .path , parent_path , False )
1617- vhdutil .setHidden (parent_path )
1630+ self . _cowutil .setParent (self .path , parent_path , False )
1631+ self . _cowutil .setHidden (parent_path )
16181632 self .sr .session .xenapi .VDI .set_managed (self .sr .srcmd .params ['args' ][0 ], False )
16191633
16201634 if not blktap2 .VDI .tap_refresh (self .session , self .sr .uuid , self .uuid ,
@@ -1631,11 +1645,11 @@ def reset_leaf(self, sr_uuid, vdi_uuid):
16311645 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
16321646
16331647 # safety check
1634- if not vhdutil .hasParent (self .path ):
1648+ if not self . _cowutil .hasParent (self .path ):
16351649 raise util .SMException ("ERROR: VDI %s has no parent, " + \
16361650 "will not reset contents" % self .uuid )
16371651
1638- vhdutil .killData (self .path )
1652+ self . _cowutil .killData (self .path )
16391653
16401654 def _attach (self ):
16411655 self ._chainSetActive (True , True , True )
@@ -1723,19 +1737,19 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
17231737 opterr = 'VDI unavailable: %s' % (self .path ))
17241738
17251739 if VdiType .isCowImage (self .vdi_type ):
1726- depth = vhdutil .getDepth (self .path )
1740+ depth = self . _cowutil .getDepth (self .path )
17271741 if depth == - 1 :
17281742 raise xs_errors .XenError ('VDIUnavailable' , \
17291743 opterr = 'failed to get VHD depth' )
1730- elif depth >= vhdutil . MAX_CHAIN_SIZE :
1744+ elif depth >= self . _cowutil . getMaxChainLength () :
17311745 raise xs_errors .XenError ('SnapshotChainTooLong' )
17321746
17331747 self .issnap = self .session .xenapi .VDI .get_is_a_snapshot ( \
17341748 self .sr .srcmd .params ['vdi_ref' ])
17351749
17361750 fullpr = lvhdutil .calcSizeVHDLV (self .size )
17371751 thinpr = util .roundup (lvutil .LVM_SIZE_INCREMENT , \
1738- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
1752+ self . _cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
17391753 lvSizeOrig = thinpr
17401754 lvSizeClon = thinpr
17411755
@@ -1816,7 +1830,7 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
18161830 if not VdiType .isCowImage (self .vdi_type ):
18171831 self .sr .lvmCache .setHidden (self .lvname )
18181832 else :
1819- vhdutil .setHidden (self .path )
1833+ self . _cowutil .setHidden (self .path )
18201834 util .fistpoint .activate ("LVHDRT_clone_vdi_after_parent_hidden" , self .sr .uuid )
18211835
18221836 # set the base copy to ReadOnly
@@ -1860,8 +1874,8 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
18601874 RefCounter .set (snapUuid , 1 , 0 , lvhdutil .NS_PREFIX_LVM + self .sr .uuid )
18611875 self .sr .lvActivator .add (snapUuid , snapLV , False )
18621876 parentRaw = (self .vdi_type == VdiType .RAW )
1863- vhdutil .snapshot (snapPath , self .path , parentRaw , lvhdutil .MSIZE_MB )
1864- snapParent = vhdutil .getParent (snapPath , lvhdutil .extractUuid )
1877+ self . _cowutil .snapshot (snapPath , self .path , parentRaw , lvhdutil .MSIZE_MB )
1878+ snapParent = self . _cowutil .getParent (snapPath , lvhdutil .extractUuid )
18651879
18661880 snapVDI = LVHDVDI (self .sr , snapUuid )
18671881 snapVDI .read_only = False
@@ -2068,15 +2082,15 @@ def _determineType(self):
20682082 # LVM commands can be costly, so check the file directly first in case
20692083 # the LV is active
20702084 found = False
2071- for t in lvhdutil .VDI_TYPES :
2072- lvname = "%s%s" % (lvhdutil . LV_PREFIX [ t ] , self .uuid )
2085+ for vdiType , prefix in lvhdutil .LV_PREFIX :
2086+ lvname = "%s%s" % (prefix , self .uuid )
20732087 path = os .path .join (self .sr .path , lvname )
20742088 if util .pathexists (path ):
20752089 if found :
20762090 raise xs_errors .XenError ('VDILoad' ,
20772091 opterr = "multiple VDI's: uuid %s" % self .uuid )
20782092 found = True
2079- self .vdi_type = t
2093+ self .vdi_type = vdiType
20802094 self .lvname = lvname
20812095 self .path = path
20822096 if found :
@@ -2110,7 +2124,7 @@ def _loadThis(self):
21102124 self ._initFromLVInfo (lvs [self .uuid ])
21112125 if VdiType .isCowImage (self .vdi_type ):
21122126 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
2113- vhdInfo = vhdutil . getVHDInfo (self .path , lvhdutil .extractUuid , False )
2127+ vhdInfo = self . _cowutil . getInfo (self .path , lvhdutil .extractUuid , False )
21142128 if not vhdInfo :
21152129 raise xs_errors .XenError ('VDIUnavailable' , \
21162130 opterr = 'getVHDInfo failed' )
@@ -2154,7 +2168,7 @@ def _markHidden(self):
21542168 if not VdiType .isCowImage (self .vdi_type ):
21552169 self .sr .lvmCache .setHidden (self .lvname )
21562170 else :
2157- vhdutil .setHidden (self .path )
2171+ self . _cowutil .setHidden (self .path )
21582172 self .hidden = 1
21592173
21602174 def _prepareThin (self , attach ):
0 commit comments