Make open_cores load viable by adding getter for cores

Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
Jan Musial 2022-02-22 11:31:13 +01:00
parent 53d2c5a197
commit 973a474b37
2 changed files with 31 additions and 2 deletions

View File

@ -38,6 +38,7 @@ from .stats.cache import CacheInfo
from .ioclass import IoClassesInfo, IoClassInfo from .ioclass import IoClassesInfo, IoClassInfo
from .stats.shared import UsageStats, RequestsStats, BlocksStats, ErrorsStats from .stats.shared import UsageStats, RequestsStats, BlocksStats, ErrorsStats
from .ctx import OcfCtx from .ctx import OcfCtx
from .volume import Volume
class Backfill(Structure): class Backfill(Structure):
@ -593,6 +594,27 @@ class Cache:
def write_unlock(self): def write_unlock(self):
self.owner.lib.ocf_mngt_cache_unlock(self.cache_handle) self.owner.lib.ocf_mngt_cache_unlock(self.cache_handle)
def get_core_by_name(self, name: str):
core_handle = c_void_p()
result = self.owner.lib.ocf_core_get_by_name(
self.cache_handle,
name.encode("ascii"),
len(name),
byref(core_handle),
)
if result != 0:
raise OcfError("Failed getting core by name", result)
uuid = self.owner.lib.ocf_core_get_uuid_wrapper(core_handle)
device = Volume.get_by_uuid(uuid.contents._data.decode("ascii"))
core = Core(device)
core.cache = self
core.handle = core_handle
self.cores.append(core)
return core
def add_core(self, core: Core, try_add=False): def add_core(self, core: Core, try_add=False):
cfg = core.get_config() cfg = core.get_config()
@ -741,6 +763,11 @@ class Cache:
self.mngt_queue.put() self.mngt_queue.put()
del self.io_queues[:] del self.io_queues[:]
self.started = False
for core in self.cores:
core.cache = None
core.handle = None
self.write_unlock() self.write_unlock()
self.device = None self.device = None
self.started = False self.started = False

View File

@ -19,6 +19,7 @@ from ctypes import (
cast, cast,
byref, byref,
create_string_buffer, create_string_buffer,
POINTER,
) )
from datetime import timedelta from datetime import timedelta
@ -58,7 +59,6 @@ class Core:
def __init__( def __init__(
self, self,
device: Volume, device: Volume,
try_add: bool,
name: str = "core", name: str = "core",
seq_cutoff_threshold: int = DEFAULT_SEQ_CUTOFF_THRESHOLD, seq_cutoff_threshold: int = DEFAULT_SEQ_CUTOFF_THRESHOLD,
seq_cutoff_promotion_count: int = DEFAULT_SEQ_CUTOFF_PROMOTION_COUNT, seq_cutoff_promotion_count: int = DEFAULT_SEQ_CUTOFF_PROMOTION_COUNT,
@ -73,7 +73,7 @@ class Core:
@classmethod @classmethod
def using_device(cls, device, **kwargs): def using_device(cls, device, **kwargs):
c = cls(device=device, try_add=False, **kwargs) c = cls(device=device, **kwargs)
return c return c
@ -222,6 +222,8 @@ class Core:
lib = OcfLib.getInstance() lib = OcfLib.getInstance()
lib.ocf_core_get_uuid_wrapper.restype = POINTER(Uuid)
lib.ocf_core_get_uuid_wrapper.argtypes = [c_void_p]
lib.ocf_core_get_volume.restype = c_void_p lib.ocf_core_get_volume.restype = c_void_p
lib.ocf_volume_new_io.argtypes = [ lib.ocf_volume_new_io.argtypes = [
c_void_p, c_void_p,