Skip to content

Commit a41b393

Browse files
committed
linstor fixes
1 parent 24591b1 commit a41b393

3 files changed

Lines changed: 43 additions & 37 deletions

File tree

drivers/LinstorSR.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ def detach(self, sr_uuid, vdi_uuid) -> None:
18941894
while vdi_uuid:
18951895
try:
18961896
path = self._linstor.build_device_path(self._linstor.get_volume_name(vdi_uuid))
1897-
parent_vdi_uuid = self.sr.linstorcowutil.get_info(vdi_uuid).parentUuid
1897+
parent_vdi_uuid = self.linstorcowutil.get_info(vdi_uuid).parentUuid
18981898
except Exception:
18991899
break
19001900

@@ -1957,11 +1957,11 @@ def resize(self, sr_uuid, vdi_uuid, size) -> str:
19571957
self._linstor.resize(self.uuid, new_volume_size)
19581958
else:
19591959
if new_volume_size != old_volume_size:
1960-
self.sr.linstorcowutil.inflate(
1960+
self.linstorcowutil.inflate(
19611961
self.sr._journaler, self.uuid, self.path,
19621962
new_volume_size, old_volume_size
19631963
)
1964-
self.sr.linstorcowutil.set_size_virt_fast(self.path, size)
1964+
self.linstorcowutil.set_size_virt_fast(self.path, size)
19651965

19661966
# Reload size attributes.
19671967
self._load_this()
@@ -1995,8 +1995,8 @@ def compose(self, sr_uuid, vdi1, vdi2) -> None:
19951995
if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, self.uuid):
19961996
raise util.SMException('Failed to pause VDI {}'.format(self.uuid))
19971997
try:
1998-
self.sr.linstorcowutil.set_parent(self.path, parent_path, False)
1999-
self.sr.linstorcowutil.set_hidden(parent_path)
1998+
self.linstorcowutil.set_parent(self.path, parent_path, False)
1999+
self.linstorcowutil.set_hidden(parent_path)
20002000
self.sr.session.xenapi.VDI.set_managed(
20012001
self.sr.srcmd.params['args'][0], False
20022002
)
@@ -2120,7 +2120,7 @@ def _load_this(self):
21202120
self.size = volume_info.virtual_size
21212121
self.parent = ''
21222122
else:
2123-
image_info = self.sr.linstorcowutil.get_info(self.uuid)
2123+
image_info = self.linstorcowutil.get_info(self.uuid)
21242124
self.hidden = image_info.hidden
21252125
self.size = image_info.sizeVirt
21262126
self.parent = image_info.parentUuid

drivers/linstor-manager

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ import XenAPI
2727
import XenAPIPlugin
2828

2929
from json import JSONEncoder
30+
from functools import partial
31+
3032
from cowutil import getCowUtil
3133
from linstorcowutil import LinstorCowUtil
3234
from linstorjournaler import LinstorJournaler
3335
from linstorvolumemanager import get_controller_uri, get_local_volume_openers, LinstorVolumeManager
36+
3437
import json
3538
import LinstorSR
3639
import lock
@@ -282,7 +285,7 @@ def get_ip_addr_of_pif(session, pif_uuid):
282285
return ip_addr
283286

284287

285-
def extract_uuid(device_path):
288+
def extract_uuid(linstor, device_path):
286289
return linstor.get_volume_uuid_from_device_path(
287290
device_path.rstrip('\n')
288291
)
@@ -419,7 +422,7 @@ def get_info(session, args):
419422
)
420423

421424
image_info = cowutil.getInfo(
422-
device_path, extract_uuid, include_parent, False
425+
device_path, partial(extract_uuid, linstor), include_parent, False
423426
)
424427
return json.dumps(image_info.__dict__)
425428
except Exception as e:
@@ -449,7 +452,7 @@ def get_parent(session, args):
449452
logger=util.SMlog
450453
)
451454

452-
return cowutil.getParent(device_path, extract_uuid)
455+
return cowutil.getParent(device_path, partial(extract_uuid, linstor))
453456
except Exception as e:
454457
util.SMlog('linstor-manager:get_parent error: {}'.format(e))
455458
raise

drivers/linstorcowutil.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def log_failed_call(target_host, next_target, device_path, vdi_uuid, remote_meth
7777
target_host, device_path, vdi_uuid, remote_method, next_target, e
7878
), priority=util.LOG_DEBUG)
7979

80-
def linstorhostcall(local_method, remote_method):
80+
def linstorhostcall(local_method, remote_method=None):
81+
if not remote_method:
82+
remote_method = local_method
83+
8184
def decorated(response_parser):
8285
def wrapper(*args, **kwargs):
8386
self = args[0]
@@ -216,7 +219,7 @@ def check(self, vdi_uuid, ignore_missing_footer=False, fast=False):
216219
}
217220
return self._check(vdi_uuid, **kwargs)
218221

219-
@linstorhostcall(CowUtil.check, 'check')
222+
@linstorhostcall('check')
220223
def _check(self, vdi_uuid, response):
221224
return CowUtil.CheckResult(response)
222225

@@ -227,7 +230,7 @@ def get_info(self, vdi_uuid, include_parent=True):
227230
}
228231
return self._get_info(vdi_uuid, self._extract_uuid, **kwargs)
229232

230-
@linstorhostcall(CowUtil.getInfo, 'getInfo')
233+
@linstorhostcall('getInfo')
231234
def _get_info(self, vdi_uuid, response):
232235
obj = json.loads(response)
233236

@@ -242,42 +245,42 @@ def _get_info(self, vdi_uuid, response):
242245

243246
return image_info
244247

245-
@linstorhostcall(CowUtil.hasParent, 'hasParent')
248+
@linstorhostcall('hasParent')
246249
def has_parent(self, vdi_uuid, response):
247250
return util.strtobool(response)
248251

249252
def get_parent(self, vdi_uuid):
250253
return self._get_parent(vdi_uuid, self._extract_uuid)
251254

252-
@linstorhostcall(CowUtil.getParent, 'getParent')
255+
@linstorhostcall('getParent')
253256
def _get_parent(self, vdi_uuid, response):
254257
return response
255258

256-
@linstorhostcall(CowUtil.getSizeVirt, 'getSizeVirt')
259+
@linstorhostcall('getSizeVirt')
257260
def get_size_virt(self, vdi_uuid, response):
258261
return int(response)
259262

260-
@linstorhostcall(CowUtil.getMaxResizeSize, 'getMaxResizeSize')
263+
@linstorhostcall('getMaxResizeSize')
261264
def get_max_resize_size(self, vdi_uuid, response):
262265
return int(response)
263266

264-
@linstorhostcall(CowUtil.getSizePhys, 'getSizePhys')
267+
@linstorhostcall('getSizePhys')
265268
def get_size_phys(self, vdi_uuid, response):
266269
return int(response)
267270

268-
@linstorhostcall(CowUtil.getAllocatedSize, 'getAllocatedSize')
271+
@linstorhostcall('getAllocatedSize')
269272
def get_allocated_size(self, vdi_uuid, response):
270273
return int(response)
271274

272-
@linstorhostcall(CowUtil.getDepth, 'getDepth')
275+
@linstorhostcall('getDepth')
273276
def get_depth(self, vdi_uuid, response):
274277
return int(response)
275278

276-
@linstorhostcall(CowUtil.getKeyHash, 'getKeyHash')
279+
@linstorhostcall('getKeyHash')
277280
def get_key_hash(self, vdi_uuid, response):
278281
return response or None
279282

280-
@linstorhostcall(CowUtil.getBlockBitmap, 'getBlockBitmap')
283+
@linstorhostcall('getBlockBitmap')
281284
def get_block_bitmap(self, vdi_uuid, response):
282285
return base64.b64decode(response)
283286

@@ -297,31 +300,31 @@ def _get_drbd_size(self, cowutil_inst, path):
297300

298301
@linstormodifier()
299302
def create(self, path, size, static, msize=0):
300-
return self._call_local_method_or_fail(CowUtil.create, path, size, static, msize)
303+
return self._call_local_method_or_fail(self._cowutil.create, path, size, static, msize)
301304

302305
@linstormodifier()
303306
def set_size_phys(self, path, size, debug=True):
304-
return self._call_local_method_or_fail(CowUtil.setSizePhys, path, size, debug)
307+
return self._call_local_method_or_fail(self._cowutil.setSizePhys, path, size, debug)
305308

306309
@linstormodifier()
307310
def set_parent(self, path, parentPath, parentRaw=False):
308-
return self._call_local_method_or_fail(CowUtil.setParent, path, parentPath, parentRaw)
311+
return self._call_local_method_or_fail(self._cowutil.setParent, path, parentPath, parentRaw)
309312

310313
@linstormodifier()
311314
def set_hidden(self, path, hidden=True):
312-
return self._call_local_method_or_fail(CowUtil.setHidden, path, hidden)
315+
return self._call_local_method_or_fail(self._cowutil.setHidden, path, hidden)
313316

314317
@linstormodifier()
315318
def set_key(self, path, key_hash):
316-
return self._call_local_method_or_fail(CowUtil.setKey, path, key_hash)
319+
return self._call_local_method_or_fail(self._cowutil.setKey, path, key_hash)
317320

318321
@linstormodifier()
319322
def kill_data(self, path):
320-
return self._call_local_method_or_fail(CowUtil.killData, path)
323+
return self._call_local_method_or_fail(self._cowutil.killData, path)
321324

322325
@linstormodifier()
323326
def snapshot(self, path, parent, parentRaw, msize=0, checkEmpty=True):
324-
return self._call_local_method_or_fail(CowUtil.snapshot, path, parent, parentRaw, msize, checkEmpty)
327+
return self._call_local_method_or_fail(self._cowutil.snapshot, path, parent, parentRaw, msize, checkEmpty)
325328

326329
def inflate(self, journaler, vdi_uuid, vdi_path, new_size, old_size):
327330
# Only inflate if the LINSTOR volume capacity is not enough.
@@ -377,30 +380,30 @@ def set_size_virt(self, path, size, jFile):
377380
'size': size,
378381
'jFile': jFile
379382
}
380-
return self._call_method(CowUtil.setSizeVirt, 'setSizeVirt', path, use_parent=False, **kwargs)
383+
return self._call_method(self._cowutil.setSizeVirt, 'setSizeVirt', path, use_parent=False, **kwargs)
381384

382385
@linstormodifier()
383386
def set_size_virt_fast(self, path, size):
384387
kwargs = {
385388
'size': size
386389
}
387-
return self._call_method(CowUtil.setSizeVirtFast, 'setSizeVirtFast', path, use_parent=False, **kwargs)
390+
return self._call_method(self._cowutil.setSizeVirtFast, 'setSizeVirtFast', path, use_parent=False, **kwargs)
388391

389392
@linstormodifier()
390393
def force_parent(self, path, parentPath, parentRaw=False):
391394
kwargs = {
392395
'parentPath': str(parentPath),
393396
'parentRaw': parentRaw
394397
}
395-
return self._call_method(CowUtil.setParent, 'setParent', path, use_parent=False, **kwargs)
398+
return self._call_method(self._cowutil.setParent, 'setParent', path, use_parent=False, **kwargs)
396399

397400
@linstormodifier()
398401
def force_coalesce(self, path):
399-
return int(self._call_method(CowUtil.coalesce, 'coalesce', path, use_parent=True))
402+
return int(self._call_method(self._cowutil.coalesce, 'coalesce', path, use_parent=True))
400403

401404
@linstormodifier()
402405
def force_repair(self, path):
403-
return self._call_method(CowUtil.repair, 'repair', path, use_parent=False)
406+
return self._call_method(self._cowutil.repair, 'repair', path, use_parent=False)
404407

405408
@linstormodifier()
406409
def force_deflate(self, path, newSize, oldSize, zeroize):
@@ -478,12 +481,12 @@ def _raise_openers_exception(self, device_path, e):
478481

479482
def _call_local_method(self, local_method, device_path, *args, **kwargs):
480483
if isinstance(local_method, str):
481-
local_method = getattr(self, local_method)
484+
local_method = getattr(self._cowutil, local_method)
482485

483486
try:
484487
def local_call():
485488
try:
486-
return local_method(self._cowutil, device_path, *args, **kwargs)
489+
return local_method(device_path, *args, **kwargs)
487490
except util.CommandException as e:
488491
if e.code == errno.EROFS or e.code == errno.EMEDIUMTYPE:
489492
raise ErofsLinstorCallException(e) # Break retry calls.
@@ -510,7 +513,7 @@ def _call_method(self, local_method, remote_method, device_path, use_parent, *ar
510513
# we must check where this last one is open instead of the child.
511514

512515
if isinstance(local_method, str):
513-
local_method = getattr(self, local_method)
516+
local_method = getattr(self._cowutil, local_method)
514517

515518
# A. Try to write locally...
516519
try:
@@ -569,7 +572,7 @@ def remote_call():
569572

570573
if no_host_found:
571574
try:
572-
return local_method(self._cowutil, device_path, *args, **kwargs)
575+
return local_method(device_path, *args, **kwargs)
573576
except Exception as e:
574577
self._raise_openers_exception(device_path, e)
575578

0 commit comments

Comments
 (0)