pyocf: Move core/cache md5() logic to volume

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2022-03-23 10:45:01 +01:00
parent 16c85c1560
commit 0e8d02235a
6 changed files with 44 additions and 43 deletions

View File

@@ -175,36 +175,6 @@ class Core:
def reset_stats(self):
self.cache.owner.lib.ocf_core_stats_initialize(self.handle)
def exp_obj_md5(self):
logging.getLogger("pyocf").warning(
"Reading whole exported object! This disturbs statistics values"
)
cache_line_size = int(self.cache.get_stats()['conf']['cache_line_size'])
read_buffer_all = Data(self.device.size)
read_buffer = Data(cache_line_size)
position = 0
while position < read_buffer_all.size:
io = self.new_io(self.cache.get_default_queue(), position,
cache_line_size, IoDir.READ, 0, 0)
io.set_data(read_buffer)
cmpl = OcfCompletion([("err", c_int)])
io.callback = cmpl.callback
io.submit()
cmpl.wait()
if cmpl.results["err"]:
raise Exception("Error reading whole exported object")
read_buffer_all.copy(read_buffer, position, 0, cache_line_size)
position += cache_line_size
return read_buffer_all.md5()
lib = OcfLib.getInstance()
lib.ocf_core_get_uuid_wrapper.restype = POINTER(Uuid)
lib.ocf_core_get_uuid_wrapper.argtypes = [c_void_p]

View File

@@ -20,12 +20,12 @@ class CacheVolume(ExpObjVolume):
if open:
self.open()
def md5(self):
data = self._read()
return data.md5()
def open(self):
return Volume.open(
self.lib.ocf_cache_get_front_volume(self.cache.handle),
self
)
def md5(self):
cache_line_size = int(self.cache.get_stats()['conf']['cache_line_size'])
return self._exp_obj_md5(cache_line_size)

View File

@@ -17,11 +17,11 @@ class CoreVolume(ExpObjVolume):
if open:
self.open()
def md5(self):
return self.core.exp_obj_md5()
def open(self):
return Volume.open(
self.lib.ocf_core_get_front_volume(self.core.handle),
self
)
def md5(self):
return self._exp_obj_md5(4096)

View File

@@ -3,6 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#
import logging
from ctypes import c_int, c_void_p, CFUNCTYPE, byref, c_uint32, c_uint64, cast, POINTER
from ..ocf import OcfLib
@@ -87,6 +88,34 @@ class ExpObjVolume(Volume):
def md5(self):
raise NotImplementedError
def _exp_obj_md5(self, read_size):
logging.getLogger("pyocf").warning(
"Reading whole exported object! This disturbs statistics values"
)
read_buffer_all = Data(self.parent.device.size)
read_buffer = Data(read_size)
position = 0
while position < read_buffer_all.size:
io = self.new_io(self.parent.get_default_queue(), position,
read_size, IoDir.READ, 0, 0)
io.set_data(read_buffer)
cmpl = OcfCompletion([("err", c_int)])
io.callback = cmpl.callback
io.submit()
cmpl.wait()
if cmpl.results["err"]:
raise Exception("Error reading whole exported object")
read_buffer_all.copy(read_buffer, position, 0, read_size)
position += read_size
return read_buffer_all.md5()
lib = OcfLib.getInstance()
lib.ocf_volume_get_max_io_size.argtypes = [c_void_p]