Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Jan 13, 2025
1 parent 8f5dd01 commit 9e29a45
Show file tree
Hide file tree
Showing 18 changed files with 1,186 additions and 759 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ SM_LIBS += util
SM_LIBS += verifyVHDsOnSR
SM_LIBS += scsiutil
SM_LIBS += scsi_host_rescan
SM_LIBS += cowutil
SM_LIBS += vhdutil
SM_LIBS += linstorjournaler
SM_LIBS += linstorvhdutil
SM_LIBS += linstorvolumemanager
SM_LIBS += lvhdutil
SM_LIBS += lvhdutil # TODO: Split
SM_LIBS += cifutils
SM_LIBS += xs_errors
SM_LIBS += nfs
Expand Down
1 change: 0 additions & 1 deletion drivers/CephFSSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import cleanup
import lock
import util
import vhdutil
import xs_errors

CAPABILITIES = ["SR_PROBE", "SR_UPDATE",
Expand Down
218 changes: 111 additions & 107 deletions drivers/FileSR.py

Large diffs are not rendered by default.

84 changes: 49 additions & 35 deletions drivers/LVHDSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,24 +724,25 @@ def scan(self, uuid) -> None:
activated = True
lvPath = os.path.join(self.path, lvname)

cowutil = None

if not VdiType.isCowImage(vdi_type):
size = self.lvmCache.getSize( \
lvhdutil.LV_PREFIX[vdi_type] + vdi_uuid)
utilisation = \
util.roundup(lvutil.LVM_SIZE_INCREMENT,
int(size))
else:
parent = \
vhdutil._getVHDParentNoCheck(lvPath)
parent = cowutil.getParentNoCheck(lvPath)

if parent is not None:
sm_config['vhd-parent'] = parent[len( \
lvhdutil.LV_PREFIX[VdiType.VHD]):]
size = vhdutil.getSizeVirt(lvPath)
size = cowutil.getSizeVirt(lvPath)
if self.provision == "thin":
utilisation = \
util.roundup(lvutil.LVM_SIZE_INCREMENT,
vhdutil.calcOverheadEmpty(lvhdutil.MSIZE))
cowutil.calcOverheadEmpty(lvhdutil.MSIZE))
else:
utilisation = lvhdutil.calcSizeVHDLV(int(size))

Expand Down Expand Up @@ -928,6 +929,8 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
lvs = lvhdutil.getLVInfo(self.lvmCache)
baseUuid, clonUuid = jval.split("_")

cowutil = None # TODO

# is there a "base copy" VDI?
if not lvs.get(baseUuid):
# no base copy: make sure the original is there
Expand Down Expand Up @@ -961,7 +964,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
parent = vdis[orig.parentUuid]
self.lvActivator.activate(parent.uuid, parent.lvName, False)
origPath = os.path.join(self.path, orig.lvName)
if not vhdutil.check(origPath):
if cowutil.check(origPath) != cowutil.CheckResult.Success:
util.SMlog("Orig VHD invalid => revert")
self._undoCloneOp(lvs, origUuid, baseUuid, clonUuid)
return
Expand All @@ -970,7 +973,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
clon = vdis[clonUuid]
clonPath = os.path.join(self.path, clon.lvName)
self.lvActivator.activate(clonUuid, clon.lvName, False)
if not vhdutil.check(clonPath):
if cowutil.check(clonPath) != cowutil.CheckResult.Success:
util.SMlog("Clon VHD invalid => revert")
self._undoCloneOp(lvs, origUuid, baseUuid, clonUuid)
return
Expand All @@ -990,13 +993,16 @@ def _undoCloneOp(self, lvs, origUuid, baseUuid, clonUuid):
origRefcountBinary = RefCounter.check(origUuid, ns)[1]
origRefcountNormal = 0

# TODO
cowutil = None

# un-hide the parent
if VdiType.isCowImage(base.vdiType):
self.lvActivator.activate(baseUuid, base.name, False)
origRefcountNormal = 1
vhdInfo = vhdutil.getVHDInfo(basePath, lvhdutil.extractUuid, False)
if vhdInfo.hidden:
vhdutil.setHidden(basePath, False)
cow_info = cowutil.getInfo(basePath, lvhdutil.extractUuid, False)
if cow_info.hidden:
cowutil.setHidden(basePath, False)
elif base.hidden:
self.lvmCache.setHidden(base.name, False)

Expand Down Expand Up @@ -1047,13 +1053,15 @@ def _completeCloneOp(self, vdis, origUuid, baseUuid, clonUuid):

cleanup.abort(self.uuid)

cowutil = None # TODO

# make sure the parent is hidden and read-only
if not base.hidden:
if not VdiType.isCowImage(base.vdiType):
self.lvmCache.setHidden(base.lvName)
else:
basePath = os.path.join(self.path, base.lvName)
vhdutil.setHidden(basePath)
cowutil.setHidden(basePath)
if not base.lvReadonly:
self.lvmCache.setReadonly(base.lvName, True)

Expand Down Expand Up @@ -1196,6 +1204,8 @@ def _undoAllVHDJournals(self):
if len(journals) == 0:
return
self._loadvdis()
# TODO
cowutil = None
for uuid, jlvName in journals:
vdi = self.vdis[uuid]
util.SMlog("Found VHD journal %s, reverting %s" % (uuid, vdi.path))
Expand All @@ -1205,13 +1215,15 @@ def _undoAllVHDJournals(self):
lvhdutil.inflate(self.journaler, self.uuid, vdi.uuid, fullSize)
try:
jFile = os.path.join(self.path, jlvName)
vhdutil.revert(vdi.path, jFile)
cowutil.revert(vdi.path, jFile)
except util.CommandException:
util.logException("VHD journal revert")
vhdutil.check(vdi.path)
cowutil.check(vdi.path)
util.SMlog("VHD revert failed but VHD ok: removing journal")
# Attempt to reclaim unused space
vhdInfo = vhdutil.getVHDInfo(vdi.path, lvhdutil.extractUuid, False)


vhdInfo = cowutil.getInfo(vdi.path, lvhdutil.extractUuid, False)
NewSize = lvhdutil.calcSizeVHDLV(vhdInfo.sizeVirt)
if NewSize < fullSize:
lvhdutil.deflate(self.lvmCache, vdi.lvname, int(NewSize))
Expand Down Expand Up @@ -1373,7 +1385,9 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
if self.exists:
raise xs_errors.XenError('VDIExists')

size = vhdutil.validate_and_round_vhd_size(int(size))
self._cowutil = None # TODO

size = self._cowutil.validateAndRoundImageSize(int(size))

util.SMlog("LVHDVDI.create: type = %s, %s (size=%s)" % \
(self.vdi_type, self.path, size))
Expand All @@ -1384,7 +1398,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
else:
if self.sr.provision == "thin":
lvSize = util.roundup(lvutil.LVM_SIZE_INCREMENT,
vhdutil.calcOverheadEmpty(lvhdutil.MSIZE))
self._cowutil.calcOverheadEmpty(lvhdutil.MSIZE))
elif self.sr.provision == "thick":
lvSize = lvhdutil.calcSizeVHDLV(int(size))

Expand All @@ -1395,8 +1409,8 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
if not VdiType.isCowImage(self.vdi_type):
self.size = self.sr.lvmCache.getSize(self.lvname)
else:
vhdutil.create(self.path, int(size), False, lvhdutil.MSIZE_MB)
self.size = vhdutil.getSizeVirt(self.path)
self._cowutil.create(self.path, int(size), False, lvhdutil.MSIZE_MB)
self.size = self._cowutil.getSizeVirt(self.path)
self.sr.lvmCache.deactivateNoRefcount(self.lvname)
except util.CommandException as e:
util.SMlog("Unable to create VDI")
Expand Down Expand Up @@ -1554,7 +1568,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
'(current size: %d, new size: %d)' % (self.size, size))
raise xs_errors.XenError('VDISize', opterr='shrinking not allowed')

size = vhdutil.validate_and_round_vhd_size(int(size))
size = self._cowutil.validateAndRoundImageSize(int(size))

if size == self.size:
return VDI.VDI.get_params(self)
Expand All @@ -1581,8 +1595,8 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
if lvSizeNew != lvSizeOld:
lvhdutil.inflate(self.sr.journaler, self.sr.uuid, self.uuid,
lvSizeNew)
vhdutil.setSizeVirtFast(self.path, size)
self.size = vhdutil.getSizeVirt(self.path)
self._cowutil.setSizeVirtFast(self.path, size)
self.size = self._cowutil.getSizeVirt(self.path)
self.utilisation = self.sr.lvmCache.getSize(self.lvname)

vdi_ref = self.sr.srcmd.params['vdi_ref']
Expand Down Expand Up @@ -1612,8 +1626,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
self.sr.lvActivator.activate(self.uuid, self.lvname, False)
self.sr.lvActivator.activate(parent_uuid, parent_lvname, False)

vhdutil.setParent(self.path, parent_path, False)
vhdutil.setHidden(parent_path)
self._cowutil.setParent(self.path, parent_path, False)
self._cowutil.setHidden(parent_path)
self.sr.session.xenapi.VDI.set_managed(self.sr.srcmd.params['args'][0], False)

if not blktap2.VDI.tap_refresh(self.session, self.sr.uuid, self.uuid,
Expand All @@ -1630,11 +1644,11 @@ def reset_leaf(self, sr_uuid, vdi_uuid):
self.sr.lvActivator.activate(self.uuid, self.lvname, False)

# safety check
if not vhdutil.hasParent(self.path):
if not self._cowutil.hasParent(self.path):
raise util.SMException("ERROR: VDI %s has no parent, " + \
"will not reset contents" % self.uuid)

vhdutil.killData(self.path)
self._cowutil.killData(self.path)

def _attach(self):
self._chainSetActive(True, True, True)
Expand Down Expand Up @@ -1722,19 +1736,19 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
opterr='VDI unavailable: %s' % (self.path))

if VdiType.isCowImage(self.vdi_type):
depth = vhdutil.getDepth(self.path)
depth = self._cowutil.getDepth(self.path)
if depth == -1:
raise xs_errors.XenError('VDIUnavailable', \
opterr='failed to get VHD depth')
elif depth >= vhdutil.MAX_CHAIN_SIZE:
elif depth >= self._cowutil.getMaxChainLength():
raise xs_errors.XenError('SnapshotChainTooLong')

self.issnap = self.session.xenapi.VDI.get_is_a_snapshot( \
self.sr.srcmd.params['vdi_ref'])

fullpr = lvhdutil.calcSizeVHDLV(self.size)
thinpr = util.roundup(lvutil.LVM_SIZE_INCREMENT, \
vhdutil.calcOverheadEmpty(lvhdutil.MSIZE))
self._cowutil.calcOverheadEmpty(lvhdutil.MSIZE))
lvSizeOrig = thinpr
lvSizeClon = thinpr

Expand Down Expand Up @@ -1815,7 +1829,7 @@ def _snapshot(self, snapType, cloneOp=False, cbtlog=None, cbt_consistency=None):
if not VdiType.isCowImage(self.vdi_type):
self.sr.lvmCache.setHidden(self.lvname)
else:
vhdutil.setHidden(self.path)
self._cowutil.setHidden(self.path)
util.fistpoint.activate("LVHDRT_clone_vdi_after_parent_hidden", self.sr.uuid)

# set the base copy to ReadOnly
Expand Down Expand Up @@ -1859,8 +1873,8 @@ def _createSnap(self, snapUuid, snapSizeLV, isNew):
RefCounter.set(snapUuid, 1, 0, lvhdutil.NS_PREFIX_LVM + self.sr.uuid)
self.sr.lvActivator.add(snapUuid, snapLV, False)
parentRaw = (self.vdi_type == VdiType.RAW)
vhdutil.snapshot(snapPath, self.path, parentRaw, lvhdutil.MSIZE_MB)
snapParent = vhdutil.getParent(snapPath, lvhdutil.extractUuid)
self._cowutil.snapshot(snapPath, self.path, parentRaw, lvhdutil.MSIZE_MB)
snapParent = self._cowutil.getParent(snapPath, lvhdutil.extractUuid)

snapVDI = LVHDVDI(self.sr, snapUuid)
snapVDI.read_only = False
Expand Down Expand Up @@ -2067,15 +2081,15 @@ def _determineType(self):
# LVM commands can be costly, so check the file directly first in case
# the LV is active
found = False
for t in lvhdutil.VDI_TYPES:
lvname = "%s%s" % (lvhdutil.LV_PREFIX[t], self.uuid)
for vdiType, prefix in lvhdutil.LV_PREFIX:
lvname = "%s%s" % (prefix, self.uuid)
path = os.path.join(self.sr.path, lvname)
if util.pathexists(path):
if found:
raise xs_errors.XenError('VDILoad',
opterr="multiple VDI's: uuid %s" % self.uuid)
found = True
self.vdi_type = t
self.vdi_type = vdiType
self.lvname = lvname
self.path = path
if found:
Expand Down Expand Up @@ -2109,7 +2123,7 @@ def _loadThis(self):
self._initFromLVInfo(lvs[self.uuid])
if VdiType.isCowImage(self.vdi_type):
self.sr.lvActivator.activate(self.uuid, self.lvname, False)
vhdInfo = vhdutil.getVHDInfo(self.path, lvhdutil.extractUuid, False)
vhdInfo = self._cowutil.getInfo(self.path, lvhdutil.extractUuid, False)
if not vhdInfo:
raise xs_errors.XenError('VDIUnavailable', \
opterr='getVHDInfo failed')
Expand Down Expand Up @@ -2153,7 +2167,7 @@ def _markHidden(self):
if not VdiType.isCowImage(self.vdi_type):
self.sr.lvmCache.setHidden(self.lvname)
else:
vhdutil.setHidden(self.path)
self._cowutil.setHidden(self.path)
self.hidden = 1

def _prepareThin(self, attach):
Expand Down
24 changes: 15 additions & 9 deletions drivers/LinstorSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ class LinstorSR(SR.SR):
# SR methods.
# --------------------------------------------------------------------------

_linstor: Optional[LinstorVolumeManager] = None

@override
@staticmethod
def handles(type) -> bool:
Expand Down Expand Up @@ -1286,7 +1288,7 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
return (device_path, None)

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

vhd_info = self._vhdutil.get_vhd_info(vdi_uuid)
Expand Down Expand Up @@ -1660,8 +1662,10 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
assert self.ty
assert self.vdi_type

self._cowutil = None # TODO

# 2. Compute size and check space available.
size = vhdutil.validate_and_round_vhd_size(int(size))
size = self._cowutil.validateAndRoundImageSize(int(size))
volume_size = LinstorVhdUtil.compute_volume_size(size, self.vdi_type)
util.SMlog(
'LinstorVDI.create: type={}, vhd-size={}, volume-size={}'
Expand Down Expand Up @@ -1692,16 +1696,18 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:

self._update_device_name(volume_info.name)

self.cowutil = None # TODO

if not VdiType.isCowImage(self.vdi_type):
self.size = volume_info.virtual_size
else:
self.sr._vhdutil.create(
self._cowutil.create(
self.path, size, False, self.MAX_METADATA_VIRT_SIZE
)
self.size = self.sr._vhdutil.get_size_virt(self.uuid)
self.size = self._cowutil.get_size_virt(self.uuid)

if self._key_hash:
self.sr._vhdutil.set_key(self.path, self._key_hash)
self._cowutil.set_key(self.path, self._key_hash) # TODO: Check supported before call

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

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

# 2. Write the snapshot content.
is_raw = (self.vdi_type == VdiType.RAW)
self.sr._vhdutil.snapshot(
self._cowutil.snapshot(
snap_path, self.path, is_raw, self.MAX_METADATA_VIRT_SIZE
)

# 3. Get snapshot parent.
snap_parent = self.sr._vhdutil.get_parent(snap_uuid)
snap_parent = self._cowutil.get_parent(snap_uuid)

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

# Ensure we have a valid path if we don't have a local diskful.
Expand Down
Loading

0 comments on commit 9e29a45

Please sign in to comment.