pyocf: use device.handle for device config if available

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2022-06-08 21:24:27 +02:00
parent eb3439666d
commit 6195967483
3 changed files with 102 additions and 26 deletions

View File

@@ -502,20 +502,24 @@ class Cache:
raise OcfError("Error adding partition to cache", status)
def alloc_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()
if not device.handle:
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)
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)
else:
volume = device.handle
device_config = CacheDeviceConfig(
_volume=volume,

View File

@@ -267,6 +267,7 @@ class Volume:
self.reset_stats()
self.is_online = True
self.opened = False
self.handle = None
def do_open(self):
return 0