Merge pull request #702 from robertbaldyga/v22.6-composite-volume

Introduce composite volume
This commit is contained in:
Adam Rutkowski
2022-06-02 13:36:21 +02:00
committed by GitHub
20 changed files with 1079 additions and 148 deletions

View File

@@ -63,8 +63,7 @@ class CacheConfig(Structure):
class CacheDeviceConfig(Structure):
_fields_ = [
("_uuid", Uuid),
("_volume_type", c_uint8),
("_volume", c_void_p),
("_perform_test", c_bool),
("_volume_params", c_void_p),
]
@@ -257,7 +256,7 @@ class Cache:
raise OcfError("Failed to detach failover cache device", c.results["error"])
def standby_activate(self, device, open_cores=True):
device_cfg = Cache.generate_device_config(device)
device_cfg = self.generate_device_config(device)
activate_cfg = CacheStandbyActivateConfig(_device=device_cfg, _open_cores=open_cores,)
@@ -457,14 +456,24 @@ class Cache:
if status:
raise OcfError("Error adding partition to cache", status)
@staticmethod
def generate_device_config(device, perform_test=True):
def generate_device_config(self, device, perform_test=True):
uuid = Uuid(
_data=cast(create_string_buffer(device.uuid.encode("ascii")), c_char_p),
_size=len(device.uuid) + 1,
)
volume = c_void_p()
lib = OcfLib.getInstance()
result = lib.ocf_volume_create(
byref(volume),
self.owner.ocf_volume_type[type(device)],
byref(uuid)
)
if result != 0:
raise OcfError("Cache volume initialization failed", result)
device_config = CacheDeviceConfig(
_uuid=Uuid(
_data=cast(create_string_buffer(device.uuid.encode("ascii")), c_char_p),
_size=len(device.uuid) + 1,
),
_volume_type=device.type_id,
_volume=volume,
_perform_test=perform_test,
_volume_params=None,
)
@@ -477,7 +486,7 @@ class Cache:
self.device = device
self.device_name = device.uuid
device_config = Cache.generate_device_config(device, perform_test=perform_test)
device_config = self.generate_device_config(device, perform_test=perform_test)
attach_cfg = CacheAttachConfig(
_device=device_config,
@@ -505,7 +514,7 @@ class Cache:
self.device = device
self.device_name = device.uuid
device_config = Cache.generate_device_config(device, perform_test=False)
device_config = self.generate_device_config(device, perform_test=False)
attach_cfg = CacheAttachConfig(
_device=device_config,
@@ -533,7 +542,7 @@ class Cache:
self.device = device
self.device_name = device.uuid
device_config = Cache.generate_device_config(device, perform_test=perform_test)
device_config = self.generate_device_config(device, perform_test=perform_test)
attach_cfg = CacheAttachConfig(
_device=device_config,
@@ -570,7 +579,7 @@ class Cache:
self.device = device
self.device_name = device.uuid
device_config = Cache.generate_device_config(device)
device_config = self.generate_device_config(device)
attach_cfg = CacheAttachConfig(
_device=device_config,
@@ -917,3 +926,5 @@ lib.ocf_mngt_add_partition_to_cache.argtypes = [
]
lib.ocf_mngt_cache_io_classes_configure.restype = c_int
lib.ocf_mngt_cache_io_classes_configure.argtypes = [c_void_p, c_void_p]
lib.ocf_volume_create.restype = c_int
lib.ocf_volume_create.argtypes = [c_void_p, c_void_p, c_void_p]

View File

@@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#
from ctypes import c_void_p, Structure, c_char_p, cast, pointer, byref, c_int
from ctypes import c_void_p, Structure, c_char_p, cast, pointer, byref, c_int, c_uint8
import weakref
from .logger import LoggerOps, Logger
@@ -37,6 +37,7 @@ class OcfCtx:
self.lib = lib
self.volume_types_count = 1
self.volume_types = {}
self.ocf_volume_type = {}
self.caches = []
self.cfg = OcfCtxCfg(
@@ -77,6 +78,11 @@ class OcfCtx:
if result != 0:
raise OcfError("Volume type registration failed", result)
self.ocf_volume_type[volume_type] = self.lib.ocf_ctx_get_volume_type(
self.ctx_handle,
volume_type.type_id
)
self.volume_types_count += 1
def unregister_volume_type(self, vol_type):
@@ -86,6 +92,7 @@ class OcfCtx:
self.lib.ocf_ctx_unregister_volume_type(self.ctx_handle, vol_type.type_id)
del self.volume_types[vol_type.type_id]
del self.ocf_volume_type[vol_type]
def cleanup_volume_types(self):
for k, vol_type in list(self.volume_types.items()):
@@ -108,3 +115,5 @@ class OcfCtx:
lib = OcfLib.getInstance()
lib.ocf_mngt_cache_get_by_name.argtypes = [c_void_p, c_void_p, c_void_p]
lib.ocf_mngt_cache_get_by_name.restype = c_int
lib.ocf_ctx_get_volume_type.argtypes = [c_void_p, c_uint8]
lib.ocf_ctx_get_volume_type.restype = c_void_p

View File

@@ -47,7 +47,9 @@ class VolumeOps(Structure):
SUBMIT_METADATA = CFUNCTYPE(None, c_void_p)
SUBMIT_DISCARD = CFUNCTYPE(None, c_void_p)
SUBMIT_WRITE_ZEROES = CFUNCTYPE(None, c_void_p)
OPEN = CFUNCTYPE(c_int, c_void_p)
ON_INIT = CFUNCTYPE(c_int, c_void_p)
ON_DEINIT = CFUNCTYPE(None, c_void_p)
OPEN = CFUNCTYPE(c_int, c_void_p, c_void_p)
CLOSE = CFUNCTYPE(None, c_void_p)
GET_MAX_IO_SIZE = CFUNCTYPE(c_uint, c_void_p)
GET_LENGTH = CFUNCTYPE(c_uint64, c_void_p)
@@ -58,6 +60,8 @@ class VolumeOps(Structure):
("_submit_metadata", SUBMIT_METADATA),
("_submit_discard", SUBMIT_DISCARD),
("_submit_write_zeroes", SUBMIT_WRITE_ZEROES),
("_on_init", ON_INIT),
("_on_deinit", ON_DEINIT),
("_open", OPEN),
("_close", CLOSE),
("_get_length", GET_LENGTH),
@@ -124,8 +128,16 @@ class Volume:
def _submit_write_zeroes(write_zeroes):
raise NotImplementedError
@VolumeOps.ON_INIT
def _on_init(ref):
return 0
@VolumeOps.ON_DEINIT
def _on_deinit(ref):
return
@VolumeOps.OPEN
def _open(ref):
def _open(ref, params):
uuid_ptr = cast(OcfLib.getInstance().ocf_volume_get_uuid(ref), POINTER(Uuid))
uuid = str(uuid_ptr.contents._data, encoding="ascii")
try:
@@ -161,6 +173,8 @@ class Volume:
_close=_close,
_get_max_io_size=_get_max_io_size,
_get_length=_get_length,
_on_init=_on_init,
_on_deinit=_on_deinit,
)
return Volume._ops_[cls]