Reflect cache attach API changes in pyocf

The uuid/volume_type pair has been replaced with pointer to volume object.

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2022-05-13 20:02:33 +02:00 committed by Jan Musial
parent bc0e28f1c6
commit 6a9436740b
2 changed files with 25 additions and 8 deletions

View File

@ -63,8 +63,7 @@ class CacheConfig(Structure):
class CacheDeviceConfig(Structure): class CacheDeviceConfig(Structure):
_fields_ = [ _fields_ = [
("_uuid", Uuid), ("_volume", c_void_p),
("_volume_type", c_uint8),
("_perform_test", c_bool), ("_perform_test", c_bool),
("_volume_params", c_void_p), ("_volume_params", c_void_p),
] ]
@ -459,12 +458,23 @@ class Cache:
@staticmethod @staticmethod
def generate_device_config(device, perform_test=True): def generate_device_config(device, perform_test=True):
device_config = CacheDeviceConfig( uuid = Uuid(
_uuid=Uuid(
_data=cast(create_string_buffer(device.uuid.encode("ascii")), c_char_p), _data=cast(create_string_buffer(device.uuid.encode("ascii")), c_char_p),
_size=len(device.uuid) + 1, _size=len(device.uuid) + 1,
), )
_volume_type=device.type_id, volume = c_void_p()
lib = OcfLib.getInstance()
result = lib.ocf_volume_create(
byref(volume),
device.type,
byref(uuid)
)
if result != 0:
raise OcfError("Cache volume initialization failed", result)
device_config = CacheDeviceConfig(
_volume=volume,
_perform_test=perform_test, _perform_test=perform_test,
_volume_params=None, _volume_params=None,
) )

View File

@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause # 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 import weakref
from .logger import LoggerOps, Logger from .logger import LoggerOps, Logger
@ -77,6 +77,11 @@ class OcfCtx:
if result != 0: if result != 0:
raise OcfError("Volume type registration failed", result) raise OcfError("Volume type registration failed", result)
volume_type.type = self.lib.ocf_ctx_get_volume_type(
self.ctx_handle,
volume_type.type_id
)
self.volume_types_count += 1 self.volume_types_count += 1
def unregister_volume_type(self, vol_type): def unregister_volume_type(self, vol_type):
@ -108,3 +113,5 @@ class OcfCtx:
lib = OcfLib.getInstance() 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.argtypes = [c_void_p, c_void_p, c_void_p]
lib.ocf_mngt_cache_get_by_name.restype = c_int 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