@@ -724,24 +724,25 @@ def scan(self, uuid) -> None:
724724 activated = True
725725 lvPath = os .path .join (self .path , lvname )
726726
727+ cowutil = None
728+
727729 if not VdiType .isCowImage (vdi_type ):
728730 size = self .lvmCache .getSize ( \
729731 lvhdutil .LV_PREFIX [vdi_type ] + vdi_uuid )
730732 utilisation = \
731733 util .roundup (lvutil .LVM_SIZE_INCREMENT ,
732734 int (size ))
733735 else :
734- parent = \
735- vhdutil ._getVHDParentNoCheck (lvPath )
736+ parent = cowutil .getParentNoCheck (lvPath )
736737
737738 if parent is not None :
738739 sm_config ['vhd-parent' ] = parent [len ( \
739740 lvhdutil .LV_PREFIX [VdiType .VHD ]):]
740- size = vhdutil .getSizeVirt (lvPath )
741+ size = cowutil .getSizeVirt (lvPath )
741742 if self .provision == "thin" :
742743 utilisation = \
743744 util .roundup (lvutil .LVM_SIZE_INCREMENT ,
744- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
745+ cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
745746 else :
746747 utilisation = lvhdutil .calcSizeVHDLV (int (size ))
747748
@@ -928,6 +929,8 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
928929 lvs = lvhdutil .getLVInfo (self .lvmCache )
929930 baseUuid , clonUuid = jval .split ("_" )
930931
932+ cowutil = None # TODO
933+
931934 # is there a "base copy" VDI?
932935 if not lvs .get (baseUuid ):
933936 # no base copy: make sure the original is there
@@ -961,7 +964,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
961964 parent = vdis [orig .parentUuid ]
962965 self .lvActivator .activate (parent .uuid , parent .lvName , False )
963966 origPath = os .path .join (self .path , orig .lvName )
964- if not vhdutil .check (origPath ):
967+ if cowutil .check (origPath ) != cowutil . CheckResult . Success :
965968 util .SMlog ("Orig VHD invalid => revert" )
966969 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
967970 return
@@ -970,7 +973,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
970973 clon = vdis [clonUuid ]
971974 clonPath = os .path .join (self .path , clon .lvName )
972975 self .lvActivator .activate (clonUuid , clon .lvName , False )
973- if not vhdutil .check (clonPath ):
976+ if cowutil .check (clonPath ) != cowutil . CheckResult . Success :
974977 util .SMlog ("Clon VHD invalid => revert" )
975978 self ._undoCloneOp (lvs , origUuid , baseUuid , clonUuid )
976979 return
@@ -990,13 +993,16 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
990993 origRefcountBinary = RefCounter .check (origUuid , ns )[1 ]
991994 origRefcountNormal = 0
992995
996+ # TODO
997+ cowutil = None
998+
993999 # un-hide the parent
9941000 if VdiType .isCowImage (base .vdiType ):
9951001 self .lvActivator .activate (baseUuid , base .name , False )
9961002 origRefcountNormal = 1
997- vhdInfo = vhdutil . getVHDInfo (basePath , lvhdutil .extractUuid , False )
998- if vhdInfo .hidden :
999- vhdutil .setHidden (basePath , False )
1003+ cow_info = cowutil . getInfo (basePath , lvhdutil .extractUuid , False )
1004+ if cow_info .hidden :
1005+ cowutil .setHidden (basePath , False )
10001006 elif base .hidden :
10011007 self .lvmCache .setHidden (base .name , False )
10021008
@@ -1047,13 +1053,15 @@ def _completeCloneOp(self, vdis, origUuid, baseUuid, clonUuid):
10471053
10481054 cleanup .abort (self .uuid )
10491055
1056+ cowutil = None # TODO
1057+
10501058 # make sure the parent is hidden and read-only
10511059 if not base .hidden :
10521060 if not VdiType .isCowImage (base .vdiType ):
10531061 self .lvmCache .setHidden (base .lvName )
10541062 else :
10551063 basePath = os .path .join (self .path , base .lvName )
1056- vhdutil .setHidden (basePath )
1064+ cowutil .setHidden (basePath )
10571065 if not base .lvReadonly :
10581066 self .lvmCache .setReadonly (base .lvName , True )
10591067
@@ -1196,6 +1204,8 @@ def _undoAllVHDJournals(self):
11961204 if len (journals ) == 0 :
11971205 return
11981206 self ._loadvdis ()
1207+ # TODO
1208+ cowutil = None
11991209 for uuid , jlvName in journals :
12001210 vdi = self .vdis [uuid ]
12011211 util .SMlog ("Found VHD journal %s, reverting %s" % (uuid , vdi .path ))
@@ -1205,13 +1215,15 @@ def _undoAllVHDJournals(self):
12051215 lvhdutil .inflate (self .journaler , self .uuid , vdi .uuid , fullSize )
12061216 try :
12071217 jFile = os .path .join (self .path , jlvName )
1208- vhdutil .revert (vdi .path , jFile )
1218+ cowutil .revert (vdi .path , jFile )
12091219 except util .CommandException :
12101220 util .logException ("VHD journal revert" )
1211- vhdutil .check (vdi .path )
1221+ cowutil .check (vdi .path )
12121222 util .SMlog ("VHD revert failed but VHD ok: removing journal" )
12131223 # Attempt to reclaim unused space
1214- vhdInfo = vhdutil .getVHDInfo (vdi .path , lvhdutil .extractUuid , False )
1224+
1225+
1226+ vhdInfo = cowutil .getInfo (vdi .path , lvhdutil .extractUuid , False )
12151227 NewSize = lvhdutil .calcSizeVHDLV (vhdInfo .sizeVirt )
12161228 if NewSize < fullSize :
12171229 lvhdutil .deflate (self .lvmCache , vdi .lvname , int (NewSize ))
@@ -1373,7 +1385,9 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13731385 if self .exists :
13741386 raise xs_errors .XenError ('VDIExists' )
13751387
1376- size = vhdutil .validate_and_round_vhd_size (int (size ))
1388+ self ._cowutil = None # TODO
1389+
1390+ size = self ._cowutil .validateAndRoundImageSize (int (size ))
13771391
13781392 util .SMlog ("LVHDVDI.create: type = %s, %s (size=%s)" % \
13791393 (self .vdi_type , self .path , size ))
@@ -1384,7 +1398,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13841398 else :
13851399 if self .sr .provision == "thin" :
13861400 lvSize = util .roundup (lvutil .LVM_SIZE_INCREMENT ,
1387- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
1401+ self . _cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
13881402 elif self .sr .provision == "thick" :
13891403 lvSize = lvhdutil .calcSizeVHDLV (int (size ))
13901404
@@ -1395,8 +1409,8 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
13951409 if not VdiType .isCowImage (self .vdi_type ):
13961410 self .size = self .sr .lvmCache .getSize (self .lvname )
13971411 else :
1398- vhdutil .create (self .path , int (size ), False , lvhdutil .MSIZE_MB )
1399- self .size = vhdutil .getSizeVirt (self .path )
1412+ self . _cowutil .create (self .path , int (size ), False , lvhdutil .MSIZE_MB )
1413+ self .size = self . _cowutil .getSizeVirt (self .path )
14001414 self .sr .lvmCache .deactivateNoRefcount (self .lvname )
14011415 except util .CommandException as e :
14021416 util .SMlog ("Unable to create VDI" )
@@ -1554,7 +1568,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
15541568 '(current size: %d, new size: %d)' % (self .size , size ))
15551569 raise xs_errors .XenError ('VDISize' , opterr = 'shrinking not allowed' )
15561570
1557- size = vhdutil . validate_and_round_vhd_size (int (size ))
1571+ size = self . _cowutil . validateAndRoundImageSize (int (size ))
15581572
15591573 if size == self .size :
15601574 return VDI .VDI .get_params (self )
@@ -1581,8 +1595,8 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
15811595 if lvSizeNew != lvSizeOld :
15821596 lvhdutil .inflate (self .sr .journaler , self .sr .uuid , self .uuid ,
15831597 lvSizeNew )
1584- vhdutil .setSizeVirtFast (self .path , size )
1585- self .size = vhdutil .getSizeVirt (self .path )
1598+ self . _cowutil .setSizeVirtFast (self .path , size )
1599+ self .size = self . _cowutil .getSizeVirt (self .path )
15861600 self .utilisation = self .sr .lvmCache .getSize (self .lvname )
15871601
15881602 vdi_ref = self .sr .srcmd .params ['vdi_ref' ]
@@ -1612,8 +1626,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
16121626 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
16131627 self .sr .lvActivator .activate (parent_uuid , parent_lvname , False )
16141628
1615- vhdutil .setParent (self .path , parent_path , False )
1616- vhdutil .setHidden (parent_path )
1629+ self . _cowutil .setParent (self .path , parent_path , False )
1630+ self . _cowutil .setHidden (parent_path )
16171631 self .sr .session .xenapi .VDI .set_managed (self .sr .srcmd .params ['args' ][0 ], False )
16181632
16191633 if not blktap2 .VDI .tap_refresh (self .session , self .sr .uuid , self .uuid ,
@@ -1630,11 +1644,11 @@ def reset_leaf(self, sr_uuid, vdi_uuid):
16301644 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
16311645
16321646 # safety check
1633- if not vhdutil .hasParent (self .path ):
1647+ if not self . _cowutil .hasParent (self .path ):
16341648 raise util .SMException ("ERROR: VDI %s has no parent, " + \
16351649 "will not reset contents" % self .uuid )
16361650
1637- vhdutil .killData (self .path )
1651+ self . _cowutil .killData (self .path )
16381652
16391653 def _attach (self ):
16401654 self ._chainSetActive (True , True , True )
@@ -1722,19 +1736,19 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
17221736 opterr = 'VDI unavailable: %s' % (self .path ))
17231737
17241738 if VdiType .isCowImage (self .vdi_type ):
1725- depth = vhdutil .getDepth (self .path )
1739+ depth = self . _cowutil .getDepth (self .path )
17261740 if depth == - 1 :
17271741 raise xs_errors .XenError ('VDIUnavailable' , \
17281742 opterr = 'failed to get VHD depth' )
1729- elif depth >= vhdutil . MAX_CHAIN_SIZE :
1743+ elif depth >= self . _cowutil . getMaxChainLength () :
17301744 raise xs_errors .XenError ('SnapshotChainTooLong' )
17311745
17321746 self .issnap = self .session .xenapi .VDI .get_is_a_snapshot ( \
17331747 self .sr .srcmd .params ['vdi_ref' ])
17341748
17351749 fullpr = lvhdutil .calcSizeVHDLV (self .size )
17361750 thinpr = util .roundup (lvutil .LVM_SIZE_INCREMENT , \
1737- vhdutil .calcOverheadEmpty (lvhdutil .MSIZE ))
1751+ self . _cowutil .calcOverheadEmpty (lvhdutil .MSIZE ))
17381752 lvSizeOrig = thinpr
17391753 lvSizeClon = thinpr
17401754
@@ -1815,7 +1829,7 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
18151829 if not VdiType .isCowImage (self .vdi_type ):
18161830 self .sr .lvmCache .setHidden (self .lvname )
18171831 else :
1818- vhdutil .setHidden (self .path )
1832+ self . _cowutil .setHidden (self .path )
18191833 util .fistpoint .activate ("LVHDRT_clone_vdi_after_parent_hidden" , self .sr .uuid )
18201834
18211835 # set the base copy to ReadOnly
@@ -1859,8 +1873,8 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
18591873 RefCounter .set (snapUuid , 1 , 0 , lvhdutil .NS_PREFIX_LVM + self .sr .uuid )
18601874 self .sr .lvActivator .add (snapUuid , snapLV , False )
18611875 parentRaw = (self .vdi_type == VdiType .RAW )
1862- vhdutil .snapshot (snapPath , self .path , parentRaw , lvhdutil .MSIZE_MB )
1863- snapParent = vhdutil .getParent (snapPath , lvhdutil .extractUuid )
1876+ self . _cowutil .snapshot (snapPath , self .path , parentRaw , lvhdutil .MSIZE_MB )
1877+ snapParent = self . _cowutil .getParent (snapPath , lvhdutil .extractUuid )
18641878
18651879 snapVDI = LVHDVDI (self .sr , snapUuid )
18661880 snapVDI .read_only = False
@@ -2067,15 +2081,15 @@ def _determineType(self):
20672081 # LVM commands can be costly, so check the file directly first in case
20682082 # the LV is active
20692083 found = False
2070- for t in lvhdutil .VDI_TYPES :
2071- lvname = "%s%s" % (lvhdutil . LV_PREFIX [ t ] , self .uuid )
2084+ for vdiType , prefix in lvhdutil .LV_PREFIX :
2085+ lvname = "%s%s" % (prefix , self .uuid )
20722086 path = os .path .join (self .sr .path , lvname )
20732087 if util .pathexists (path ):
20742088 if found :
20752089 raise xs_errors .XenError ('VDILoad' ,
20762090 opterr = "multiple VDI's: uuid %s" % self .uuid )
20772091 found = True
2078- self .vdi_type = t
2092+ self .vdi_type = vdiType
20792093 self .lvname = lvname
20802094 self .path = path
20812095 if found :
@@ -2109,7 +2123,7 @@ def _loadThis(self):
21092123 self ._initFromLVInfo (lvs [self .uuid ])
21102124 if VdiType .isCowImage (self .vdi_type ):
21112125 self .sr .lvActivator .activate (self .uuid , self .lvname , False )
2112- vhdInfo = vhdutil . getVHDInfo (self .path , lvhdutil .extractUuid , False )
2126+ vhdInfo = self . _cowutil . getInfo (self .path , lvhdutil .extractUuid , False )
21132127 if not vhdInfo :
21142128 raise xs_errors .XenError ('VDIUnavailable' , \
21152129 opterr = 'getVHDInfo failed' )
@@ -2153,7 +2167,7 @@ def _markHidden(self):
21532167 if not VdiType .isCowImage (self .vdi_type ):
21542168 self .sr .lvmCache .setHidden (self .lvname )
21552169 else :
2156- vhdutil .setHidden (self .path )
2170+ self . _cowutil .setHidden (self .path )
21572171 self .hidden = 1
21582172
21592173 def _prepareThin (self , attach ):
0 commit comments