Skip to content

Commit ddd5764

Browse files
committed
in progress
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.fr>
1 parent 88900c6 commit ddd5764

18 files changed

+1185
-758
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: 110 additions & 106 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
@@ -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):

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)