Skip to content

Commit aabeac9

Browse files
committed
repair pipeline
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent d75879f commit aabeac9

File tree

9 files changed

+47
-45
lines changed

9 files changed

+47
-45
lines changed

drivers/LVMSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
941941
raise util.SMException("base copy %s not present, " \
942942
"but no original %s found" % (baseUuid, origUuid))
943943

944+
vdis = LvmCowUtil.getVDIInfo(self.lvmCache)
944945
base = vdis[baseUuid]
945946
cowutil = getCowUtil(base.vdiType)
946947

@@ -954,7 +955,6 @@ def _handleInterruptedCloneOp(self, origUuid, jval, forceUndo=False):
954955
self._undoCloneOp(cowutil, lvs, origUuid, baseUuid, clonUuid)
955956
return
956957

957-
vdis = LvmCowUtil.getVDIInfo(self.lvmCache)
958958
if vdis[origUuid].scanError or (clonUuid and vdis[clonUuid].scanError):
959959
util.SMlog("One or both leaves invalid => revert")
960960
self._undoCloneOp(cowutil, lvs, origUuid, baseUuid, clonUuid)

drivers/LinstorSR.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import xmlrpc.client
5757
import xs_errors
5858

59-
from cowutil import getCowUtil, getVdiTypeFromImageFormat
59+
from cowutil import getVdiTypeFromImageFormat
6060
from srmetadata import \
6161
NAME_LABEL_TAG, NAME_DESCRIPTION_TAG, IS_A_SNAPSHOT_TAG, SNAPSHOT_OF_TAG, \
6262
TYPE_TAG, VDI_TYPE_TAG, READ_ONLY_TAG, SNAPSHOT_TIME_TAG, \
@@ -156,7 +156,7 @@ def attach_thin(session, journaler, linstor, sr_uuid, vdi_uuid):
156156

157157
device_path = linstor.get_device_path(vdi_uuid)
158158

159-
linstorcowutil = LinstorCowUtil(session, linstor, getCowUtil(vdi_type))
159+
linstorcowutil = LinstorCowUtil(session, linstor, vdi_type)
160160

161161
# If the virtual COW size is lower than the LINSTOR volume size,
162162
# there is nothing to do.
@@ -201,7 +201,7 @@ def check_vbd_count():
201201
util.retry(check_vbd_count, maxretry=10, period=1)
202202

203203
device_path = linstor.get_device_path(vdi_uuid)
204-
linstorcowutil = LinstorCowUtil(session, linstor, getCowUtil(vdi_type))
204+
linstorcowutil = LinstorCowUtil(session, linstor, vdi_type)
205205
new_volume_size = LinstorVolumeManager.round_up_volume_size(
206206
# TODO: Replace pylint comment with this feature when possible:
207207
# https://github.com/PyCQA/pylint/pull/2926
@@ -1162,7 +1162,7 @@ def _load_vdis_ex(self):
11621162
if not VdiType.isCowImage(vdi_type):
11631163
managed = not volume_metadata.get(HIDDEN_TAG)
11641164
else:
1165-
image_info = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type)).get_info(vdi_uuid)
1165+
image_info = LinstorCowUtil(self.session, self._linstor, vdi_type).get_info(vdi_uuid)
11661166
managed = not image_info.hidden
11671167
if image_info.parentUuid:
11681168
sm_config['vhd-parent'] = image_info.parentUuid
@@ -1303,7 +1303,7 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
13031303
return (device_path, None)
13041304

13051305
# Otherwise it's a COW and a parent can exist.
1306-
linstorcowutil = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type))
1306+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, vdi_type)
13071307
if linstorcowutil.check(vdi_uuid) != cowutil.CheckResult.Success:
13081308
return (None, None)
13091309

@@ -1419,7 +1419,7 @@ def _undo_clone(self, volume_names, vdi_uuid, base_uuid, snap_uuid):
14191419
util.SMlog('*** INTERRUPTED CLONE OP: rollback fail')
14201420
return
14211421

1422-
linstorcowutil = LinstorCowUtil(self.session, self._linstor, getCowUtil(base_type))
1422+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, base_type)
14231423

14241424
# Un-hide the parent.
14251425
self._linstor.update_volume_metadata(base_uuid, {READ_ONLY_TAG: False})
@@ -1468,7 +1468,8 @@ def _undo_clone(self, volume_names, vdi_uuid, base_uuid, snap_uuid):
14681468
# Inflate to the right size.
14691469
if VdiType.isCowImage(base_type):
14701470
vdi = self.vdi(vdi_uuid)
1471-
volume_size = linstorcowutil.compute_volume_size(vdi.size, vdi.vdi_type)
1471+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, vdi.vdi_type)
1472+
volume_size = linstorcowutil.compute_volume_size(vdi.size)
14721473
linstorcowutil.inflate(
14731474
self._journaler, vdi_uuid, vdi.path,
14741475
volume_size, vdi.capacity
@@ -1667,7 +1668,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16671668

16681669
# 2. Compute size and check space available.
16691670
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
1670-
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1671+
volume_size = self.linstorcowutil.compute_volume_size(size)
16711672
util.SMlog(
16721673
'LinstorVDI.create: type={}, cow-size={}, volume-size={}'
16731674
.format(self.vdi_type, size, volume_size)
@@ -1831,7 +1832,7 @@ def attach(self, sr_uuid, vdi_uuid) -> str:
18311832
if (
18321833
not VdiType.isCowImage(self.vdi_type) or
18331834
not writable or
1834-
self.capacity >= self.linstorcowutil.compute_volume_size(self.size, self.vdi_type)
1835+
self.capacity >= self.linstorcowutil.compute_volume_size(self.size)
18351836
):
18361837
need_inflate = False
18371838

@@ -1876,7 +1877,7 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
18761877

18771878
# The VDI is already deflated if the COW image size + metadata is
18781879
# equal to the LINSTOR volume size.
1879-
volume_size = self.linstorcowutil.compute_volume_size(self.size, self.vdi_type)
1880+
volume_size = self.linstorcowutil.compute_volume_size(self.size)
18801881
already_deflated = self.capacity <= volume_size
18811882

18821883
if already_deflated:
@@ -1939,7 +1940,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19391940

19401941
# Compute the virtual COW and DRBD volume size.
19411942
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
1942-
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1943+
volume_size = self.linstorcowutil.compute_volume_size(size)
19431944
util.SMlog(
19441945
'LinstorVDI.resize: type={}, cow-size={}, volume-size={}'
19451946
.format(self.vdi_type, size, volume_size)
@@ -1964,7 +1965,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19641965
# VDI is currently deflated, so keep it deflated.
19651966
new_volume_size = old_volume_size
19661967
else:
1967-
new_volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
1968+
new_volume_size = self.linstorcowutil.compute_volume_size(size)
19681969
assert new_volume_size >= old_volume_size
19691970

19701971
space_needed = new_volume_size - old_volume_size

drivers/blktap2.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,11 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
19301930
from lock import Lock
19311931
from FileSR import FileVDI
19321932

1933-
parent_uuid = self._cowutil.getParent(self.target.vdi.path,
1934-
FileVDI.extractUuid)
1933+
vdi_type = self.target.get_vdi_type()
1934+
tap_type = VDI._tap_type(vdi_type)
1935+
cowutil = getCowUtil(vdi_type)
1936+
1937+
parent_uuid = cowutil.getParent(self.target.vdi.path, FileVDI.extractUuid)
19351938
if not parent_uuid:
19361939
util.SMlog("ERROR: VDI %s has no parent, not enabling" % \
19371940
self.target.vdi.uuid)
@@ -1959,35 +1962,33 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
19591962
read_cache_path)
19601963
else:
19611964
try:
1962-
self._cowutil.snapshot(read_cache_path, shared_target.path, False)
1965+
cowutil.snapshot(read_cache_path, shared_target.path, False)
19631966
except util.CommandException as e:
19641967
util.SMlog("Error creating parent cache: %s" % e)
19651968
self.alert_no_cache(session, vdi_uuid, local_sr_uuid, e.code)
19661969
return None
19671970

19681971
# local write node
1969-
leaf_size = self._cowutil.getSizeVirt(self.target.vdi.path)
1972+
leaf_size = cowutil.getSizeVirt(self.target.vdi.path)
19701973
local_leaf_path = "%s/%s.vhdcache" % \
19711974
(local_sr.path, self.target.vdi.uuid)
19721975
if util.pathexists(local_leaf_path):
19731976
util.SMlog("Local leaf node (%s) already exists, deleting" % \
19741977
local_leaf_path)
19751978
os.unlink(local_leaf_path)
19761979
try:
1977-
self._cowutil.snapshot(local_leaf_path, read_cache_path, False,
1980+
cowutil.snapshot(local_leaf_path, read_cache_path, False,
19781981
msize=leaf_size, checkEmpty=False)
19791982
except util.CommandException as e:
19801983
util.SMlog("Error creating leaf cache: %s" % e)
19811984
self.alert_no_cache(session, vdi_uuid, local_sr_uuid, e.code)
19821985
return None
19831986

1984-
local_leaf_size = self._cowutil.getSizeVirt(local_leaf_path)
1987+
local_leaf_size = cowutil.getSizeVirt(local_leaf_path)
19851988
if leaf_size > local_leaf_size:
19861989
util.SMlog("Leaf size %d > local leaf cache size %d, resizing" %
19871990
(leaf_size, local_leaf_size))
1988-
self._cowutil.setSizeVirtFast(local_leaf_path, leaf_size)
1989-
1990-
vdi_type = self.target.get_vdi_type()
1991+
cowutil.setSizeVirtFast(local_leaf_path, leaf_size)
19911992

19921993
prt_tapdisk = Tapdisk.find_by_path(read_cache_path)
19931994
if not prt_tapdisk:
@@ -2000,15 +2001,12 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
20002001
blktap.set_pool_name("lcache-parent-pool-%s" % blktap.minor)
20012002
# no need to change pool_size since each parent tapdisk is in
20022003
# its own pool
2003-
prt_tapdisk = \
2004-
Tapdisk.launch_on_tap(blktap, read_cache_path,
2005-
'vhd', parent_options)
2004+
prt_tapdisk = Tapdisk.launch_on_tap(blktap, read_cache_path, tap_type, parent_options)
20062005
except:
20072006
blktap.free()
20082007
raise
20092008

2010-
secondary = "%s:%s" % (self.target.get_vdi_type(),
2011-
self.PhyLink.from_uuid(sr_uuid, vdi_uuid).readlink())
2009+
secondary = "%s:%s" % (vdi_type, self.PhyLink.from_uuid(sr_uuid, vdi_uuid).readlink())
20122010

20132011
util.SMlog("Parent tapdisk: %s" % prt_tapdisk)
20142012
leaf_tapdisk = Tapdisk.find_by_path(local_leaf_path)
@@ -2021,9 +2019,7 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
20212019
child_options["secondary"] = secondary
20222020
child_options["standby"] = scratch_mode
20232021
try:
2024-
leaf_tapdisk = \
2025-
Tapdisk.launch_on_tap(blktap, local_leaf_path,
2026-
'vhd', child_options)
2022+
leaf_tapdisk = Tapdisk.launch_on_tap(blktap, local_leaf_path, tap_type, child_options)
20272023
except:
20282024
blktap.free()
20292025
raise

drivers/cleanup.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Script to coalesce and garbage collect COW-based SR's in the background
1919
#
2020

21-
from sm_typing import Optional, override
21+
from sm_typing import Any, Optional, override
2222

2323
import os
2424
import os.path
@@ -1528,7 +1528,7 @@ def load(self, info=None) -> None:
15281528

15291529
self.fileName = self.sr._linstor.get_volume_name(self.uuid)
15301530
self.path = self.sr._linstor.build_device_path(self.fileName)
1531-
self.linstorcowutil = LinstorCowUtil(self.xapi.session, self.sr._linstor, self.cowutil)
1531+
self.linstorcowutil = LinstorCowUtil(self.sr.xapi.session, self.sr._linstor, self.cowutil)
15321532

15331533
if not info:
15341534
try:
@@ -1597,7 +1597,7 @@ def deflate(self):
15971597

15981598
def inflateFully(self):
15991599
if VdiType.isCowImage(self.vdi_type):
1600-
self.inflate(linstorcowutil.compute_volume_size(self.sizeVirt, self.vdi_type))
1600+
self.inflate(self.linstorcowutil.compute_volume_size(self.sizeVirt))
16011601

16021602
@override
16031603
def rename(self, uuid) -> None:
@@ -1786,7 +1786,7 @@ def _setSizeVirt(self, size) -> None:
17861786
jfile, self.cowutil.getResizeJournalSize(), persistent=False, volume_name=jfile
17871787
)
17881788
try:
1789-
self.inflate(linstorcowutil.compute_volume_size(size, self.vdi_type))
1789+
self.inflate(self.linstorcowutil.compute_volume_size(size))
17901790
self.linstorcowutil.set_size_virt(size, jfile)
17911791
finally:
17921792
try:
@@ -1810,9 +1810,7 @@ def _inflateParentForCoalesce(self):
18101810
def _calcExtraSpaceForCoalescing(self) -> int:
18111811
if not VdiType.isCowImage(self.parent.vdi_type):
18121812
return 0
1813-
size_coalesced = linstorcowutil.compute_volume_size(
1814-
self._getCoalescedSizeData(), self.vdi_type
1815-
)
1813+
size_coalesced = self.linstorcowutil.compute_volume_size(self._getCoalescedSizeData())
18161814
Util.log("Coalesced size = %s" % Util.num2str(size_coalesced))
18171815
return size_coalesced - self.parent.getDrbdSize()
18181816

@@ -3447,7 +3445,9 @@ def _finishCoalesceLeaf(self, parent) -> None:
34473445

34483446
@override
34493447
def _calcExtraSpaceNeeded(self, child, parent) -> int:
3450-
return linstorcowutil.compute_volume_size(parent.sizeVirt, parent.vdi_type) - parent.getDrbdSize()
3448+
return LinstorCowUtil(
3449+
self.xapi.session, self._linstor, parent.vdi_type
3450+
).compute_volume_size(parent.sizeVirt) - parent.getDrbdSize()
34513451

34523452
def _hasValidDevicePath(self, uuid):
34533453
try:

drivers/cowutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def check(
243243
path: str,
244244
ignoreMissingFooter: Optional[bool] = False,
245245
fast: Optional[bool] = False
246-
) -> CheckResult:
246+
) -> CowUtil.CheckResult:
247247
pass
248248

249249
@abstractmethod

drivers/linstorcowutil.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,17 @@ def _force_deflate(self, cowutil_inst, path, newSize, oldSize, zeroize):
404404
# Helpers.
405405
# --------------------------------------------------------------------------
406406

407-
def compute_volume_size(cls, virtual_size: int) -> int:
408-
if VdiType.isCowImage(vdi_type):
407+
def compute_volume_size(self, virtual_size: int) -> int:
408+
if VdiType.isCowImage(self._vdi_type):
409409
# All LINSTOR VDIs have the metadata area preallocated for
410410
# the maximum possible virtual size (for fast online VDI.resize).
411-
meta_overhead = self._cowutil.calcOverheadEmpty(self.MAX_SIZE) # TODO: getDefaultPreallocaqatio... + max
411+
meta_overhead = self._cowutil.calcOverheadEmpty(
412+
max(virtual_size, self._cowutil.getDefaultPreallocationSizeVirt())
413+
)
412414
bitmap_overhead = self._cowutil.calcOverheadBitmap(virtual_size)
413415
virtual_size += meta_overhead + bitmap_overhead
414416
else:
415-
raise Exception('Invalid image type: {}'.format(vdi_type))
417+
raise Exception('Invalid image type: {}'.format(self._vdi_type))
416418

417419
return LinstorVolumeManager.round_up_volume_size(virtual_size)
418420

drivers/lvmcowutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import lock
2929
import util
30-
import XenAPI
30+
import XenAPI # pylint: disable=import-error
3131

3232
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
3333
from cowutil import CowImageInfo, CowUtil, getCowUtil

mocks/XenAPI/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ def xapi_local():
77
pass
88

99
class Session(object):
10-
pass
10+
def __getattr__(self, name):
11+
pass

tests/test_vhdutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from sm_typing import override
12

23
import unittest
34
import zlib
@@ -15,6 +16,7 @@
1516

1617

1718
class TestVhdUtil(unittest.TestCase):
19+
@override
1820
def setUp(self):
1921
self.vhdutil = vhdutil.VhdUtil()
2022

0 commit comments

Comments
 (0)