Skip to content

Commit d75879f

Browse files
committed
linbstor to squasht
1 parent 1fb118e commit d75879f

15 files changed

+349
-230
lines changed

drivers/FileSR.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,32 @@ def replay(self, uuid) -> None:
278278
except:
279279
raise xs_errors.XenError('SRLog')
280280

281-
def _load_vdis_from_type(self, vdi_type: str) -> List[CowImageInfo]:
282-
extension = VDI_TYPE_TO_EXTENSION[vdi_type]
281+
def _loadvdis(self):
282+
if self.vdis:
283+
return
283284

284-
pattern = os.path.join(self.path, "*%s" % extension)
285-
info: List[CowImageInfo] = []
285+
self.image_info = {}
286+
for vdi_type in VDI_COW_TYPES:
287+
extension = VDI_TYPE_TO_EXTENSION[vdi_type]
286288

287-
cowutil = getCowUtil(vdi_type)
288-
try:
289-
info = cowutil.getAllInfoFromVG(pattern, FileVDI.extractUuid)
290-
except util.CommandException as inst:
291-
raise xs_errors.XenError('SRScan', opterr="error VDI-scanning " \
292-
"path %s (%s)" % (self.path, inst))
293-
try:
294-
vdi_uuids = [FileVDI.extractUuid(v) for v in util.ioretry(lambda: glob.glob(pattern))]
295-
if len(info) != len(vdi_uuids):
296-
util.SMlog("VDI scan of %s returns %d VDIs: %s" % (extension, len(info), sorted(info)))
297-
util.SMlog("VDI list of %s returns %d VDIs: %s" % (extension, len(vdi_uuids), sorted(vdi_uuids)))
298-
except:
299-
pass
289+
pattern = os.path.join(self.path, "*%s" % extension)
290+
info = {}
291+
292+
cowutil = getCowUtil(vdi_type)
293+
try:
294+
info = cowutil.getAllInfoFromVG(pattern, FileVDI.extractUuid)
295+
except util.CommandException as inst:
296+
raise xs_errors.XenError('SRScan', opterr="error VDI-scanning " \
297+
"path %s (%s)" % (self.path, inst))
298+
try:
299+
vdi_uuids = [FileVDI.extractUuid(v) for v in util.ioretry(lambda: glob.glob(pattern))]
300+
if len(info) != len(vdi_uuids):
301+
util.SMlog("VDI scan of %s returns %d VDIs: %s" % (extension, len(info), sorted(info)))
302+
util.SMlog("VDI list of %s returns %d VDIs: %s" % (extension, len(vdi_uuids), sorted(vdi_uuids)))
303+
except:
304+
pass
305+
306+
self.image_info.update(info)
300307

301308
for uuid in info.keys():
302309
if info[uuid].error:
@@ -311,16 +318,6 @@ def _load_vdis_from_type(self, vdi_type: str) -> List[CowImageInfo]:
311318
key_hash = cowutil.getKeyHash(vdi_path)
312319
self.vdis[uuid].sm_config_override['key_hash'] = key_hash
313320

314-
return info
315-
316-
def _loadvdis(self):
317-
if self.vdis:
318-
return
319-
320-
self.image_info = {}
321-
for vdi_type in VDI_COW_TYPES:
322-
self.image_info.update(self._load_vdis_from_type(vdi_type))
323-
324321
# raw VDIs and CBT log files
325322
files = util.ioretry(lambda: util.listdir(self.path))
326323
for fn in files:
@@ -499,7 +496,6 @@ def load(self, vdi_uuid) -> None:
499496
self.sr.srcmd.params['o_direct'] = self.sr.o_direct
500497

501498
if self.sr.srcmd.cmd == "vdi_create":
502-
self.vdi_type = getVdiTypeFromImageFormat(self.sr.preferred_image_formats[0])
503499
self.key_hash = None
504500
if "vdi_sm_config" in self.sr.srcmd.params:
505501
if "key_hash" in self.sr.srcmd.params["vdi_sm_config"]:
@@ -511,6 +507,10 @@ def load(self, vdi_uuid) -> None:
511507
raise xs_errors.XenError('VDIType',
512508
opterr='Invalid VDI type %s' % vdi_type)
513509
self.vdi_type = self.VDI_TYPE[vdi_type]
510+
511+
if not self.vdi_type:
512+
self.vdi_type = getVdiTypeFromImageFormat(self.sr.preferred_image_formats[0])
513+
self.cowutil = getCowUtil(self.vdi_type)
514514
self.path = os.path.join(self.sr.path, "%s%s" %
515515
(vdi_uuid, VDI_TYPE_TO_EXTENSION[self.vdi_type]))
516516
else:
@@ -609,7 +609,6 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
609609
if util.ioretry(lambda: util.pathexists(self.path)):
610610
raise xs_errors.XenError('VDIExists')
611611

612-
self.cowutil = getCowUtil(self.vdi_type)
613612
if VdiType.isCowImage(self.vdi_type):
614613
try:
615614
size = self.cowutil.validateAndRoundImageSize(int(size))
@@ -815,9 +814,10 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
815814

816815
dest = None
817816
dst = None
817+
extension = VDI_TYPE_TO_EXTENSION[self.vdi_type]
818818
if snap_type == VDI.SNAPSHOT_DOUBLE:
819819
dest = util.gen_uuid()
820-
dst = os.path.join(self.sr.path, "%s.%s" % (dest, self.vdi_type))
820+
dst = os.path.join(self.sr.path, "%s.%s" % (dest, extension))
821821
args.append(dest)
822822

823823
if self.hidden:
@@ -832,8 +832,8 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
832832

833833
newuuid = util.gen_uuid()
834834
src = self.path
835-
newsrc = os.path.join(self.sr.path, "%s%s" % (newuuid, VDI_TYPE_TO_EXTENSION[self.vdi_type]))
836-
newsrcname = "%s.%s" % (newuuid, self.vdi_type)
835+
newsrc = os.path.join(self.sr.path, "%s%s" % (newuuid, extension))
836+
newsrcname = "%s.%s" % (newuuid, extension)
837837

838838
if not self._checkpath(src):
839839
raise xs_errors.XenError('VDIUnavailable', \
@@ -881,8 +881,8 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
881881
dstparent != newuuid):
882882
util.ioretry(lambda: self._unlink(newsrc))
883883
introduce_parent = False
884-
except:
885-
pass
884+
except Exception as e:
885+
raise
886886

887887
# Introduce the new VDI records
888888
leaf_vdi = None

drivers/LVMSR.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from refcounter import RefCounter
4141
from ipc import IPCFlag
4242
from constants import NS_PREFIX_LVM, VG_LOCATION, VG_PREFIX
43-
from cowutil import getCowUtil, getVdiTypeFromImageFormat
43+
from cowutil import CowUtil, getCowUtil, getVdiTypeFromImageFormat
4444
from lvmcowutil import LV_PREFIX, LvmCowUtil
4545
from lvmanager import LVActivator
4646
from vditype import VdiType

drivers/LinstorSR.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
from sm_typing import Optional, override
17+
from sm_typing import Any, Optional, override
1818

1919
from constants import CBTLOG_TAG
2020

@@ -381,6 +381,17 @@ def load(self, sr_uuid) -> None:
381381
self._linstor = None # Ensure that LINSTOR attribute exists.
382382
self._journaler = None
383383

384+
# Used to handle reconnect calls on LINSTOR object attached to the SR.
385+
class LinstorProxy:
386+
def __init__(self, sr: LinstorSR) -> None:
387+
self.sr = sr
388+
389+
def __getattr__(self, attr: str) -> Any:
390+
assert self.sr, "Cannot use `LinstorProxy` without valid `LinstorVolumeManager` instance"
391+
return getattr(self.sr._linstor, attr)
392+
393+
self._linstor_proxy = LinstorProxy(self)
394+
384395
self._group_name = self.dconf['group-name']
385396

386397
self._vdi_shared_time = 0
@@ -1151,7 +1162,7 @@ def _load_vdis_ex(self):
11511162
if not VdiType.isCowImage(vdi_type):
11521163
managed = not volume_metadata.get(HIDDEN_TAG)
11531164
else:
1154-
image_info = self.cowutil.get_info(vdi_uuid)
1165+
image_info = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type)).get_info(vdi_uuid)
11551166
managed = not image_info.hidden
11561167
if image_info.parentUuid:
11571168
sm_config['vhd-parent'] = image_info.parentUuid
@@ -1207,7 +1218,7 @@ def _load_vdis_ex(self):
12071218
# TODO: Replace pylint comment with this feature when possible:
12081219
# https://github.com/PyCQA/pylint/pull/2926
12091220
vdi.sm_config_override['key_hash'] = \
1210-
self._vhdutil.get_key_hash(vdi_uuid) # pylint: disable = E1120
1221+
vdi.linstorcowutil.get_key_hash(vdi_uuid) # pylint: disable = E1120
12111222

12121223
# 4.c. Update CBT status of disks either just added
12131224
# or already in XAPI.
@@ -1292,12 +1303,13 @@ def _get_vdi_path_and_parent(self, vdi_uuid, volume_name):
12921303
return (device_path, None)
12931304

12941305
# Otherwise it's a COW and a parent can exist.
1295-
if self._cowutil.check(vdi_uuid) != cowutil.CheckResult.Success:
1306+
linstorcowutil = LinstorCowUtil(self.session, self._linstor, getCowUtil(vdi_type))
1307+
if linstorcowutil.check(vdi_uuid) != cowutil.CheckResult.Success:
12961308
return (None, None)
12971309

1298-
vhd_info = self._vhdutil.get_vhd_info(vdi_uuid)
1299-
if vhd_info:
1300-
return (device_path, vhd_info.parentUuid)
1310+
image_info = linstorcowutil.get_info(vdi_uuid)
1311+
if image_info:
1312+
return (device_path, image_info.parentUuid)
13011313
except Exception as e:
13021314
util.SMlog(
13031315
'Failed to get VDI path and parent, ignoring: {}'
@@ -1654,7 +1666,7 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16541666
assert self.vdi_type
16551667

16561668
# 2. Compute size and check space available.
1657-
size = self.cowutil.validateAndRoundImageSize(int(size))
1669+
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
16581670
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
16591671
util.SMlog(
16601672
'LinstorVDI.create: type={}, cow-size={}, volume-size={}'
@@ -1685,18 +1697,16 @@ def create(self, sr_uuid, vdi_uuid, size) -> str:
16851697

16861698
self._update_device_name(volume_info.name)
16871699

1688-
self.cowutil = None # TODO
1689-
16901700
if not VdiType.isCowImage(self.vdi_type):
16911701
self.size = volume_info.virtual_size
16921702
else:
1693-
self.cowutil.create(
1694-
self.path, size, False, self.cowutil.getDefaultPreallocationSizeVirt()
1703+
self.linstorcowutil.create(
1704+
self.path, size, False, self.linstorcowutil.cowutil.getDefaultPreallocationSizeVirt()
16951705
)
1696-
self.size = self.cowutil.get_size_virt(self.uuid)
1706+
self.size = self.linstorcowutil.get_size_virt(self.uuid)
16971707

16981708
if self._key_hash:
1699-
self.cowutil.set_key(self.path, self._key_hash)
1709+
self.linstorcowutil.set_key(self.path, self._key_hash)
17001710

17011711
# Because cowutil commands modify the volume data,
17021712
# we must retrieve a new time the utilization size.
@@ -1902,7 +1912,7 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
19021912
while vdi_uuid:
19031913
try:
19041914
path = self._linstor.build_device_path(self._linstor.get_volume_name(vdi_uuid))
1905-
parent_vdi_uuid = self.sr.cowutil.get_info(vdi_uuid).parentUuid
1915+
parent_vdi_uuid = self.sr.linstorcowutil.get_info(vdi_uuid).parentUuid
19061916
except Exception:
19071917
break
19081918

@@ -1928,7 +1938,7 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19281938
raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI')
19291939

19301940
# Compute the virtual COW and DRBD volume size.
1931-
size = self.cowutil.validateAndRoundImageSize(int(size))
1941+
size = self.linstorcowutil.cowutil.validateAndRoundImageSize(int(size))
19321942
volume_size = self.linstorcowutil.compute_volume_size(size, self.vdi_type)
19331943
util.SMlog(
19341944
'LinstorVDI.resize: type={}, cow-size={}, volume-size={}'
@@ -2003,8 +2013,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
20032013
if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, self.uuid):
20042014
raise util.SMException('Failed to pause VDI {}'.format(self.uuid))
20052015
try:
2006-
self.sr.cowutil.set_parent(self.path, parent_path, False)
2007-
self.sr.cowutil.set_hidden(parent_path)
2016+
self.sr.linstorcowutil.set_parent(self.path, parent_path, False)
2017+
self.sr.linstorcowutil.set_hidden(parent_path)
20082018
self.sr.session.xenapi.VDI.set_managed(
20092019
self.sr.srcmd.params['args'][0], False
20102020
)
@@ -2128,7 +2138,7 @@ def _load_this(self):
21282138
self.size = volume_info.virtual_size
21292139
self.parent = ''
21302140
else:
2131-
image_info = self.sr.cowutil.get_info(self.uuid)
2141+
image_info = self.sr.linstorcowutil.get_info(self.uuid)
21322142
self.hidden = image_info.hidden
21332143
self.size = image_info.sizeVirt
21342144
self.parent = image_info.parentUuid
@@ -2227,6 +2237,10 @@ def _prepare_thin(self, attach):
22272237
# Generic helpers.
22282238
# --------------------------------------------------------------------------
22292239

2240+
def _set_type(self, vdi_type: str) -> None:
2241+
self.vdi_type = vdi_type
2242+
self.linstorcowutil = LinstorCowUtil(self.session, self.sr._linstor_proxy, self.vdi_type)
2243+
22302244
def _determine_type_and_path(self):
22312245
"""
22322246
Determine whether this is a RAW or a COW VDI.
@@ -2281,12 +2295,12 @@ def _create_snapshot(self, snap_vdi_type, snap_uuid, snap_of_uuid=None):
22812295

22822296
# 2. Write the snapshot content.
22832297
is_raw = (self.vdi_type == VdiType.RAW)
2284-
self.cowutil.snapshot(
2298+
self.linstorcowutil.snapshot(
22852299
snap_path, self.path, is_raw, max(self.size, cowutil.getDefaultPreallocationSizeVirt())
22862300
)
22872301

22882302
# 3. Get snapshot parent.
2289-
snap_parent = self.cowutil.get_parent(snap_uuid)
2303+
snap_parent = self.linstorcowutil.get_parent(snap_uuid)
22902304

22912305
# 4. Update metadata.
22922306
util.SMlog('Set VDI {} metadata of snapshot'.format(snap_uuid))
@@ -2381,7 +2395,7 @@ def _snapshot(self, snap_type, cbtlog=None, cbt_consistency=None):
23812395
'VDIUnavailable',
23822396
opterr='failed to get COW depth'
23832397
)
2384-
elif depth >= self._cowutil.getMaxChainLength():
2398+
elif depth >= self.linstorcowutil.cowutil.getMaxChainLength():
23852399
raise xs_errors.XenError('SnapshotChainTooLong')
23862400

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

0 commit comments

Comments
 (0)