pyocf: make open/close explicit

Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
Jan Musial
2022-06-20 14:59:40 +02:00
parent abc726d7f8
commit a0c6995189
23 changed files with 168 additions and 109 deletions

View File

@@ -251,6 +251,8 @@ class Rio:
self.errors.update({thread.name: thread.errors})
self.error_count += len(thread.errors)
self.global_jobspec.target.close()
return self
def __del__(self):
@@ -275,6 +277,8 @@ class Rio:
queues = cycle(queues)
self.global_jobspec.target.open()
for job in jobs:
spec = job.merge(self.global_jobspec)
thread = Rio.RioThread(spec, next(queues))

View File

@@ -444,6 +444,7 @@ class ErrorDevice(Volume):
uuid=None,
):
self.vol = vol
self.vol.open()
super().__init__(uuid)
self.error_sectors = error_sectors or set()
self.error_seq_no = error_seq_no or {IoDir.WRITE: -1, IoDir.READ: -1}
@@ -523,6 +524,10 @@ class ErrorDevice(Volume):
def get_copy(self):
return self.vol.get_copy()
def close(self):
super().close()
self.vol.close()
class TraceDevice(Volume):
class IoType(IntEnum):

View File

@@ -13,12 +13,10 @@ from .volume import Volume
class CacheVolume(OcfInternalVolume):
def __init__(self, cache, open=False, uuid=None):
def __init__(self, cache, uuid=None):
super().__init__(cache, uuid)
self.cache = cache
self.lib = cache.owner.lib
if open:
self.open()
def get_c_handle(self):
return self.cache.get_c_front_volume()

View File

@@ -10,12 +10,10 @@ from .volume import Volume
class CoreVolume(OcfInternalVolume):
def __init__(self, core, open=False, uuid=None):
def __init__(self, core, uuid=None):
super().__init__(core, uuid)
self.core = core
self.lib = core.cache.owner.lib
if open:
self.open()
def get_c_handle(self):
return self.core.get_c_front_volume()

View File

@@ -11,7 +11,7 @@ from .volume import Volume, VOLUME_POISON
from pyocf.utils import Size
from pyocf.types.data import Data
from pyocf.types.io import IoDir, Io
from pyocf.types.shared import OcfCompletion
from pyocf.types.shared import OcfCompletion, OcfError
class OcfInternalVolume(Volume):
@@ -20,9 +20,8 @@ class OcfInternalVolume(Volume):
self.parent = parent
def __alloc_io(self, addr, _bytes, _dir, _class, _flags):
vol = self.parent.get_front_volume()
queue = self.parent.get_default_queue() # TODO multiple queues?
return vol.new_io(queue, addr, _bytes, _dir, _class, _flags)
return self.new_io(queue, addr, _bytes, _dir, _class, _flags)
def _alloc_io(self, io):
exp_obj_io = self.__alloc_io(
@@ -33,7 +32,6 @@ class OcfInternalVolume(Volume):
io.contents._flags,
)
lib = OcfLib.getInstance()
cdata = OcfLib.getInstance().ocf_io_get_data(io)
OcfLib.getInstance().ocf_io_set_data(byref(exp_obj_io), cdata, 0)
@@ -87,6 +85,7 @@ class OcfInternalVolume(Volume):
raise NotImplementedError
def _exp_obj_md5(self, read_size):
self.open()
logging.getLogger("pyocf").warning(
"Reading whole exported object! This disturbs statistics values"
)
@@ -111,14 +110,23 @@ class OcfInternalVolume(Volume):
read_buffer_all.copy(read_buffer, position, 0, read_size)
position += read_size
self.close()
return read_buffer_all.md5()
def open(self):
ret = super().open()
if ret:
return ret
handle = self.get_c_handle()
return Volume.s_open(handle, self)
self.handle = handle
return ret
def close(self):
return Volume.s_close(self)
super().close()
self.handle = None
lib = OcfLib.getInstance()

View File

@@ -14,22 +14,23 @@ class ReplicatedVolume(Volume):
super().__init__(uuid)
self.primary = primary
self.secondary = secondary
ret = self.primary.open()
if ret:
raise Exception(f"Couldn't open primary volume. ({ret})")
ret = self.secondary.open()
if ret:
raise Exception(f"Couldn't open secondary volume. ({ret})")
if secondary.get_max_io_size() < primary.get_max_io_size():
raise Exception("secondary volume max io size too small")
if secondary.get_length() < primary.get_length():
raise Exception("secondary volume size too small")
def do_open(self):
ret = self.primary.do_open()
if ret:
return ret
ret = self.secondary.do_open()
if ret:
self.primary.close()
return ret
def open(self):
return super().open()
def do_close(self):
def close(self):
super().close()
self.primary.close()
self.secondary.close()