Skip to content

Commit 0d0eb5b

Browse files
KuruyiaNambrok
authored andcommitted
feat(linstor): use client when possible to construct journaler (#143)
This adds an argument to the constructor of `LinstorJournaler` so it can be constructed with a pre-configured LINSTOR client instead of letting `LinstorJournaler` construct its own client with the given URI. Either a URI or a client needs to be passed to the constructor. If both are passed, the client takes precedence. A `native_client` property has been added to the `LinstorVolumeManager` class so its LINSTOR client can be used outside of this class. The instantiation sites of the `LinstorJournaler` class were updated to use `LinstorVolumeManager`'s client where available. Signed-off-by: Alexandre Sollier <alexandre.sollier@vates.tech>
1 parent b246952 commit 0d0eb5b

6 files changed

Lines changed: 46 additions & 15 deletions

File tree

drivers/LinstorSR.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,9 @@ def load_vdi(vdi_uuid, multi_cowutil):
13101310
def _get_journaler(self):
13111311
if not self._journaler:
13121312
self._journaler = LinstorJournaler(
1313-
self._linstor.uri, self._group_name, logger=util.SMlog
1313+
self._group_name,
1314+
native_client=self._linstor.native_client,
1315+
logger=util.SMlog
13141316
)
13151317
return self._journaler
13161318

drivers/cleanup.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,6 +3627,7 @@ def __getattr__(self, attr: str) -> Any:
36273627
assert self.sr, "Cannot use `LinstorProxy` without valid `LinstorVolumeManager` instance"
36283628
return getattr(self.sr._linstor, attr)
36293629

3630+
self._linstor = None
36303631
self._linstor_proxy = LinstorProxy(self)
36313632
self._reloadLinstor(journaler_only=True)
36323633

@@ -3676,17 +3677,19 @@ def _reloadLinstor(self, journaler_only=False):
36763677
group_name = dconf['group-name']
36773678

36783679
controller_uri = get_controller_uri()
3679-
self.journaler = LinstorJournaler(
3680-
controller_uri, group_name, logger=util.SMlog
3681-
)
36823680

3683-
if journaler_only:
3684-
return
3681+
if not journaler_only:
3682+
self._linstor = LinstorVolumeManager(
3683+
controller_uri,
3684+
group_name,
3685+
repair=True,
3686+
logger=util.SMlog
3687+
)
36853688

3686-
self._linstor = LinstorVolumeManager(
3687-
controller_uri,
3689+
self.journaler = LinstorJournaler(
36883690
group_name,
3689-
repair=True,
3691+
uri=None if self._linstor else controller_uri,
3692+
native_client=self._linstor.native_client if self._linstor else None,
36903693
logger=util.SMlog
36913694
)
36923695

drivers/linstor-manager

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,16 @@ def attach(session, args):
352352
group_name = args['groupName']
353353

354354
controller_uri = get_controller_uri()
355-
journaler = LinstorJournaler(
356-
controller_uri, group_name, logger=util.SMlog
357-
)
358355
linstor = LinstorVolumeManager(
359356
controller_uri,
360357
group_name,
361358
logger=util.SMlog
362359
)
360+
journaler = LinstorJournaler(
361+
group_name,
362+
native_client=linstor.native_client,
363+
logger=util.SMlog
364+
)
363365
LinstorSR.attach_thin(session, journaler, linstor, sr_uuid, vdi_uuid)
364366
return str(True)
365367
except Exception as e:

drivers/linstorjournaler.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,19 @@ class LinstorJournaler:
5050
def default_logger(*args):
5151
print(args)
5252

53-
def __init__(self, uri, group_name, logger=default_logger.__func__):
53+
def __init__(
54+
self,
55+
group_name,
56+
uri=None,
57+
native_client=None,
58+
logger=default_logger.__func__
59+
):
5460
self._namespace = '{}journal/'.format(
5561
LinstorVolumeManager._build_sr_namespace()
5662
)
5763
self._logger = logger
5864
self._journal = self._create_journal_instance(
59-
uri, group_name, self._namespace
65+
group_name, self._namespace, uri=uri, native_client=native_client
6066
)
6167

6268
def create(self, type, identifier, value):
@@ -144,7 +150,19 @@ def _reset_namespace(self):
144150
self._journal.namespace = self._namespace
145151

146152
@classmethod
147-
def _create_journal_instance(cls, uri, group_name, namespace):
153+
def _create_journal_instance(cls, group_name, namespace, *, uri=None, native_client=None):
154+
if not uri and not native_client:
155+
raise LinstorVolumeManagerError(
156+
'Either a URI to the LINSTOR controller or a LINSTOR client must be provided'
157+
)
158+
159+
if native_client:
160+
return linstor.KV(
161+
LinstorVolumeManager._build_group_name(group_name),
162+
existing_client=native_client,
163+
namespace=namespace
164+
)
165+
148166
def connect(uri):
149167
if not uri:
150168
uri = get_controller_uri()

drivers/linstorvolumemanager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ def __init__(
413413
def uri(self) -> str:
414414
return self._uri
415415

416+
@property
417+
def native_client(self) -> linstor.Linstor:
418+
return self._linstor
419+
416420
@property
417421
def group_name(self):
418422
"""

mocks/linstor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Linstor(object):
2+
pass

0 commit comments

Comments
 (0)