Skip to content

Commit 9e29a45

Browse files
committed
in progress
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent 8f5dd01 commit 9e29a45

18 files changed

+1186
-759
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ SM_LIBS += util
3434
SM_LIBS += verifyVHDsOnSR
3535
SM_LIBS += scsiutil
3636
SM_LIBS += scsi_host_rescan
37+
SM_LIBS += cowutil
3738
SM_LIBS += vhdutil
3839
SM_LIBS += linstorjournaler
3940
SM_LIBS += linstorvhdutil
4041
SM_LIBS += linstorvolumemanager
41-
SM_LIBS += lvhdutil
42+
SM_LIBS += lvhdutil # TODO: Split
4243
SM_LIBS += cifutils
4344
SM_LIBS += xs_errors
4445
SM_LIBS += nfs

drivers/CephFSSR.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import cleanup
4040
import lock
4141
import util
42-
import vhdutil
4342
import xs_errors
4443

4544
CAPABILITIES = ["SR_PROBE", "SR_UPDATE",

drivers/FileSR.py

Lines changed: 111 additions & 107 deletions
Large diffs are not rendered by default.

drivers/LVHDSR.py

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

drivers/LinstorSR.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class LinstorSR(SR.SR):
305305
# SR methods.
306306
# --------------------------------------------------------------------------
307307

308+
_linstor: Optional[LinstorVolumeManager] = None
309+
308310
@override
309311
@staticmethod
310312
def handles(type) -> bool:
@@ -1286,7 +1288,7 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
12861288
return (device_path, None)
12871289

12881290
# Otherwise it's a VHD and a parent can exist.
1289-
if not self._vhdutil.check(vdi_uuid):
1291+
if self._cowutil.check(vdi_uuid) != cowutil.CheckResult.Success:
12901292
return (None, None)
12911293

12921294
vhd_info = self._vhdutil.get_vhd_info(vdi_uuid)
@@ -1660,8 +1662,10 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16601662
assert self.ty
16611663
assert self.vdi_type
16621664

1665+
self._cowutil = None # TODO
1666+
16631667
# 2. Compute size and check space available.
1664-
size = vhdutil.validate_and_round_vhd_size(int(size))
1668+
size = self._cowutil.validateAndRoundImageSize(int(size))
16651669
volume_size = LinstorVhdUtil.compute_volume_size(size, self.vdi_type)
16661670
util.SMlog(
16671671
'LinstorVDI.create: type={}, vhd-size={}, volume-size={}'
@@ -1692,16 +1696,18 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16921696

16931697
self._update_device_name(volume_info.name)
16941698

1699+
self.cowutil = None # TODO
1700+
16951701
if not VdiType.isCowImage(self.vdi_type):
16961702
self.size = volume_info.virtual_size
16971703
else:
1698-
self.sr._vhdutil.create(
1704+
self._cowutil.create(
16991705
self.path, size, False, self.MAX_METADATA_VIRT_SIZE
17001706
)
1701-
self.size = self.sr._vhdutil.get_size_virt(self.uuid)
1707+
self.size = self._cowutil.get_size_virt(self.uuid)
17021708

17031709
if self._key_hash:
1704-
self.sr._vhdutil.set_key(self.path, self._key_hash)
1710+
self._cowutil.set_key(self.path, self._key_hash) # TODO: Check supported before call
17051711

17061712
# Because vhdutil commands modify the volume data,
17071713
# we must retrieve a new time the utilization size.
@@ -1933,7 +1939,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19331939
raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI')
19341940

19351941
# Compute the virtual VHD and DRBD volume size.
1936-
size = vhdutil.validate_and_round_vhd_size(int(size))
1942+
size = self._cowutil.validateAndRoundImageSize(int(size))
19371943
volume_size = LinstorVhdUtil.compute_volume_size(size, self.vdi_type)
19381944
util.SMlog(
19391945
'LinstorVDI.resize: type={}, vhd-size={}, volume-size={}'
@@ -2286,12 +2292,12 @@ def _create_snapshot(self, snap_uuid, snap_of_uuid=None):
22862292

22872293
# 2. Write the snapshot content.
22882294
is_raw = (self.vdi_type == VdiType.RAW)
2289-
self.sr._vhdutil.snapshot(
2295+
self._cowutil.snapshot(
22902296
snap_path, self.path, is_raw, self.MAX_METADATA_VIRT_SIZE
22912297
)
22922298

22932299
# 3. Get snapshot parent.
2294-
snap_parent = self.sr._vhdutil.get_parent(snap_uuid)
2300+
snap_parent = self._cowutil.get_parent(snap_uuid)
22952301

22962302
# 4. Update metadata.
22972303
util.SMlog('Set VDI {} metadata of snapshot'.format(snap_uuid))
@@ -2384,7 +2390,7 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
23842390
'VDIUnavailable',
23852391
opterr='failed to get VHD depth'
23862392
)
2387-
elif depth >= vhdutil.MAX_CHAIN_SIZE:
2393+
elif depth >= self._cowutil.getMaxChainLength():
23882394
raise xs_errors.XenError('SnapshotChainTooLong')
23892395

23902396
# Ensure we have a valid path if we don't have a local diskful.

0 commit comments

Comments
 (0)