From 1bdf4a13ae63539935f33904aae575f38cc3dffd Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Fri, 3 Jun 2022 10:36:12 +0200 Subject: [PATCH] pyocf: Improve volume instance lifecycle handling We need a strong reference to volume for as long as OCF has it open. For that I changed instance tracking dictionary from weakvalue to normal. This way I made sure that GC won't clean up Volume before its closed. Signed-off-by: Jan Musial --- tests/functional/pyocf/types/volume.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/functional/pyocf/types/volume.py b/tests/functional/pyocf/types/volume.py index 12eeae0..3984d43 100644 --- a/tests/functional/pyocf/types/volume.py +++ b/tests/functional/pyocf/types/volume.py @@ -89,7 +89,7 @@ VOLUME_POISON = 0x13 class Volume: - _instances_ = weakref.WeakValueDictionary() + _instances_ = {} _uuid_ = weakref.WeakValueDictionary() _ops_ = {} _props_ = {} @@ -183,8 +183,8 @@ class Volume: if volume.opened: return -OcfErrorCode.OCF_ERR_NOT_OPEN_EXC - Volume._instances_[ref] = volume volume.handle = ref + Volume._instances_[ref] = volume ret = volume.do_open() if ret == 0: @@ -228,11 +228,11 @@ class Volume: @classmethod def get_instance(cls, ref): - instance = cls._instances_[ref] - if instance is None: + if ref not in cls._instances_: print("tried to access {} but it's gone".format(ref)) + return None - return instance + return cls._instances_[ref] @classmethod def get_by_uuid(cls, uuid): @@ -273,7 +273,7 @@ class Volume: return 0 def do_close(self): - pass + del Volume._instances_[self.handle] def get_length(self): raise NotImplementedError