Skip to content

Commit 22a6887

Browse files
committed
repair pipeline
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent 72c2a09 commit 22a6887

File tree

11 files changed

+56
-58
lines changed

11 files changed

+56
-58
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: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151

5252
import VDI as sm
5353

54+
from cowutil import getCowUtil
55+
5456
# For RRDD Plugin Registration
5557
from xmlrpc.client import ServerProxy, Transport
5658
from socket import socket, AF_UNIX, SOCK_STREAM
@@ -1930,8 +1932,11 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
19301932
from lock import Lock
19311933
from FileSR import FileVDI
19321934

1933-
parent_uuid = self._cowutil.getParent(self.target.vdi.path,
1934-
FileVDI.extractUuid)
1935+
vdi_type = self.target.get_vdi_type()
1936+
tap_type = VDI._tap_type(vdi_type)
1937+
cowutil = getCowUtil(vdi_type)
1938+
1939+
parent_uuid = cowutil.getParent(self.target.vdi.path, FileVDI.extractUuid)
19351940
if not parent_uuid:
19361941
util.SMlog("ERROR: VDI %s has no parent, not enabling" % \
19371942
self.target.vdi.uuid)
@@ -1959,35 +1964,33 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
19591964
read_cache_path)
19601965
else:
19611966
try:
1962-
self._cowutil.snapshot(read_cache_path, shared_target.path, False)
1967+
cowutil.snapshot(read_cache_path, shared_target.path, False)
19631968
except util.CommandException as e:
19641969
util.SMlog("Error creating parent cache: %s" % e)
19651970
self.alert_no_cache(session, vdi_uuid, local_sr_uuid, e.code)
19661971
return None
19671972

19681973
# local write node
1969-
leaf_size = self._cowutil.getSizeVirt(self.target.vdi.path)
1974+
leaf_size = cowutil.getSizeVirt(self.target.vdi.path)
19701975
local_leaf_path = "%s/%s.vhdcache" % \
19711976
(local_sr.path, self.target.vdi.uuid)
19721977
if util.pathexists(local_leaf_path):
19731978
util.SMlog("Local leaf node (%s) already exists, deleting" % \
19741979
local_leaf_path)
19751980
os.unlink(local_leaf_path)
19761981
try:
1977-
self._cowutil.snapshot(local_leaf_path, read_cache_path, False,
1982+
cowutil.snapshot(local_leaf_path, read_cache_path, False,
19781983
msize=leaf_size, checkEmpty=False)
19791984
except util.CommandException as e:
19801985
util.SMlog("Error creating leaf cache: %s" % e)
19811986
self.alert_no_cache(session, vdi_uuid, local_sr_uuid, e.code)
19821987
return None
19831988

1984-
local_leaf_size = self._cowutil.getSizeVirt(local_leaf_path)
1989+
local_leaf_size = cowutil.getSizeVirt(local_leaf_path)
19851990
if leaf_size > local_leaf_size:
19861991
util.SMlog("Leaf size %d > local leaf cache size %d, resizing" %
19871992
(leaf_size, local_leaf_size))
1988-
self._cowutil.setSizeVirtFast(local_leaf_path, leaf_size)
1989-
1990-
vdi_type = self.target.get_vdi_type()
1993+
cowutil.setSizeVirtFast(local_leaf_path, leaf_size)
19911994

19921995
prt_tapdisk = Tapdisk.find_by_path(read_cache_path)
19931996
if not prt_tapdisk:
@@ -2000,15 +2003,12 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
20002003
blktap.set_pool_name("lcache-parent-pool-%s" % blktap.minor)
20012004
# no need to change pool_size since each parent tapdisk is in
20022005
# its own pool
2003-
prt_tapdisk = \
2004-
Tapdisk.launch_on_tap(blktap, read_cache_path,
2005-
'vhd', parent_options)
2006+
prt_tapdisk = Tapdisk.launch_on_tap(blktap, read_cache_path, tap_type, parent_options)
20062007
except:
20072008
blktap.free()
20082009
raise
20092010

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

20132013
util.SMlog("Parent tapdisk: %s" % prt_tapdisk)
20142014
leaf_tapdisk = Tapdisk.find_by_path(local_leaf_path)
@@ -2021,9 +2021,7 @@ def _setup_cache(self, session, sr_uuid, vdi_uuid, local_sr_uuid,
20212021
child_options["secondary"] = secondary
20222022
child_options["standby"] = scratch_mode
20232023
try:
2024-
leaf_tapdisk = \
2025-
Tapdisk.launch_on_tap(blktap, local_leaf_path,
2026-
'vhd', child_options)
2024+
leaf_tapdisk = Tapdisk.launch_on_tap(blktap, local_leaf_path, tap_type, child_options)
20272025
except:
20282026
blktap.free()
20292027
raise
@@ -2077,8 +2075,8 @@ def _remove_cache(self, session, local_sr_uuid):
20772075
from lock import Lock
20782076
from FileSR import FileVDI
20792077

2080-
parent_uuid = self._cowutil.getParent(self.target.vdi.path,
2081-
FileVDI.extractUuid)
2078+
vdi_type = self.target.get_vdi_type()
2079+
parent_uuid = getCowUtil(vdi_type).getParent(self.target.vdi.path, FileVDI.extractUuid)
20822080
if not parent_uuid:
20832081
util.SMlog("ERROR: No parent for VDI %s, ignore" % \
20842082
self.target.vdi.uuid)

drivers/cleanup.py

Lines changed: 8 additions & 13 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
@@ -802,7 +802,6 @@ def __str__(self) -> str:
802802

803803
def validate(self, fast=False) -> None:
804804
if self.cowutil.check(self.path, fast=fast) != CowUtil.CheckResult.Success:
805-
print(f"TO_REMOVE 5 => '{str(self.cowutil.check(self.path, fast=fast))}' : '{CowUtil.CheckResult.Success}' ")
806805
raise util.SMException("COW image %s corrupted" % self)
807806

808807
def _clear(self):
@@ -932,8 +931,6 @@ def _coalesceCowImage(self, timeOut):
932931
Util.log(" Running COW coalesce on %s" % self)
933932
abortTest = lambda: IPCFlag(self.sr.uuid).test(FLAG_TYPE_ABORT)
934933
try:
935-
print(f"TO_REMOVE 2")
936-
937934
util.fistpoint.activate_custom_fn(
938935
"cleanup_coalesceVHD_inject_failure",
939936
util.inject_failure)
@@ -946,7 +943,6 @@ def _coalesceCowImage(self, timeOut):
946943
parent = ""
947944
try:
948945
parent = self.getParent()
949-
print(f"TO_REMOVE 1 {parent} {self._vdi_is_raw(parent)}")
950946
if not self._vdi_is_raw(parent):
951947
# Repair error is logged and ignored. Error reraised later
952948
util.SMlog('Coalesce failed on %s, attempting repair on ' \
@@ -1528,7 +1524,7 @@ def load(self, info=None) -> None:
15281524

15291525
self.fileName = self.sr._linstor.get_volume_name(self.uuid)
15301526
self.path = self.sr._linstor.build_device_path(self.fileName)
1531-
self.linstorcowutil = LinstorCowUtil(self.xapi.session, self.sr._linstor, self.cowutil)
1527+
self.linstorcowutil = LinstorCowUtil(self.sr.xapi.session, self.sr._linstor, self.cowutil)
15321528

15331529
if not info:
15341530
try:
@@ -1597,7 +1593,7 @@ def deflate(self):
15971593

15981594
def inflateFully(self):
15991595
if VdiType.isCowImage(self.vdi_type):
1600-
self.inflate(linstorcowutil.compute_volume_size(self.sizeVirt, self.vdi_type))
1596+
self.inflate(self.linstorcowutil.compute_volume_size(self.sizeVirt))
16011597

16021598
@override
16031599
def rename(self, uuid) -> None:
@@ -1786,7 +1782,7 @@ def _setSizeVirt(self, size) -> None:
17861782
jfile, self.cowutil.getResizeJournalSize(), persistent=False, volume_name=jfile
17871783
)
17881784
try:
1789-
self.inflate(linstorcowutil.compute_volume_size(size, self.vdi_type))
1785+
self.inflate(self.linstorcowutil.compute_volume_size(size))
17901786
self.linstorcowutil.set_size_virt(size, jfile)
17911787
finally:
17921788
try:
@@ -1810,9 +1806,7 @@ def _inflateParentForCoalesce(self):
18101806
def _calcExtraSpaceForCoalescing(self) -> int:
18111807
if not VdiType.isCowImage(self.parent.vdi_type):
18121808
return 0
1813-
size_coalesced = linstorcowutil.compute_volume_size(
1814-
self._getCoalescedSizeData(), self.vdi_type
1815-
)
1809+
size_coalesced = self.linstorcowutil.compute_volume_size(self._getCoalescedSizeData())
18161810
Util.log("Coalesced size = %s" % Util.num2str(size_coalesced))
18171811
return size_coalesced - self.parent.getDrbdSize()
18181812

@@ -2122,7 +2116,6 @@ def coalesce(self, vdi, dryRun=False):
21222116
self.cleanup()
21232117
raise
21242118
else:
2125-
print(f"TO_REMOVE 3 {e}")
21262119
self._failedCoalesceTargets.append(vdi)
21272120
Util.logException("coalesce")
21282121
Util.log("Coalesce failed, skipping")
@@ -3447,7 +3440,9 @@ def _finishCoalesceLeaf(self, parent) -> None:
34473440

34483441
@override
34493442
def _calcExtraSpaceNeeded(self, child, parent) -> int:
3450-
return linstorcowutil.compute_volume_size(parent.sizeVirt, parent.vdi_type) - parent.getDrbdSize()
3443+
return LinstorCowUtil(
3444+
self.xapi.session, self._linstor, parent.vdi_type
3445+
).compute_volume_size(parent.sizeVirt) - parent.getDrbdSize()
34513446

34523447
def _hasValidDevicePath(self, uuid):
34533448
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: 7 additions & 5 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

@@ -585,7 +587,7 @@ def remote_call():
585587
)
586588
return util.retry(remote_call, 5, 2)
587589

588-
def _zeroize(path, size):
590+
def _zeroize(self, path, size):
589591
if not util.zeroOut(path, size, self._cowutil.getFooterSize()):
590592
raise xs_errors.XenError(
591593
'EIO',

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

drivers/verifyVHDsOnSR.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
import sys
2525
import util
2626
import lvutil
27-
import vhdutil
2827

2928
import VDI
3029

3130
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
3231
from lock import Lock
33-
from lvmcowutil import LV_PREFIX
32+
from lvmcowutil import LV_PREFIX, LvmCowUtil
3433
from refcounter import RefCounter
3534
from vditype import VdiType
3635

@@ -116,10 +115,11 @@ def checkAllVHD(sr_uuid):
116115
VHDs_total = 0
117116

118117
vg_name = VG_PREFIX + sr_uuid
119-
pattern = "%s*" % LV_PREFIX[VdiType.VHD]
118+
vdi_type = VdiType.VHD
119+
pattern = "%s*" % LV_PREFIX[vdi_type]
120120

121121
# Do a vhd scan and gets all the VHDs
122-
vhds = CowUtil.getAllInfoFromVG(pattern, LvmCowUtil.extractUuid, vg_name)
122+
vhds = getCowUtil(vdi_type).getAllInfoFromVG(pattern, LvmCowUtil.extractUuid, vg_name)
123123
VHDs_total = len(vhds)
124124

125125
# Build VHD chain, that way it will be easier to activate all the VHDs

0 commit comments

Comments
 (0)