pyocf: separate get_conf() from stats in Cache

Configuration parameters are available in standby mode, while
stats are not. Need to separate the two.

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2022-03-30 14:55:32 +02:00
parent 3d83e1f004
commit a504821302
2 changed files with 52 additions and 42 deletions

View File

@ -756,40 +756,27 @@ class Cache:
def get_volume(self): def get_volume(self):
return Volume.get_instance(lib.ocf_cache_get_volume(self.cache_handle)) return Volume.get_instance(lib.ocf_cache_get_volume(self.cache_handle))
def get_stats(self): def get_conf(self):
cache_info = CacheInfo() cache_info = CacheInfo()
usage = UsageStats()
req = RequestsStats()
block = BlocksStats()
errors = ErrorsStats()
self.read_lock() self.read_lock()
status = self.owner.lib.ocf_cache_get_info(self.cache_handle, byref(cache_info)) status = self.owner.lib.ocf_cache_get_info(self.cache_handle, byref(cache_info))
if status:
self.read_unlock()
raise OcfError("Failed getting cache info", status)
status = self.owner.lib.ocf_stats_collect_cache(
self.cache_handle, byref(usage), byref(req), byref(block), byref(errors)
)
if status:
self.read_unlock() self.read_unlock()
raise OcfError("Failed getting stats", status)
if status:
raise OcfError("Failed getting cache info", status)
line_size = CacheLineSize(cache_info.cache_line_size) line_size = CacheLineSize(cache_info.cache_line_size)
cache_name = self.owner.lib.ocf_cache_get_name(self).decode("ascii") cache_name = self.owner.lib.ocf_cache_get_name(self).decode("ascii")
self.read_unlock()
return { return {
"conf": {
"attached": cache_info.attached, "attached": cache_info.attached,
"volume_type": self.owner.volume_types[cache_info.volume_type], "volume_type": self.owner.volume_types[cache_info.volume_type],
"size": CacheLines(cache_info.size, line_size), "size": CacheLines(cache_info.size, line_size),
"inactive": { "inactive": {
"occupancy": CacheLines( "occupancy": CacheLines(cache_info.inactive.occupancy.value, line_size),
cache_info.inactive.occupancy.value, line_size
),
"dirty": CacheLines(cache_info.inactive.dirty.value, line_size), "dirty": CacheLines(cache_info.inactive.dirty.value, line_size),
"clean": CacheLines(cache_info.inactive.clean.value, line_size), "clean": CacheLines(cache_info.inactive.clean.value, line_size),
}, },
@ -811,7 +798,29 @@ class Cache:
"metadata_footprint": Size(cache_info.metadata_footprint), "metadata_footprint": Size(cache_info.metadata_footprint),
"metadata_end_offset": Size(cache_info.metadata_end_offset), "metadata_end_offset": Size(cache_info.metadata_end_offset),
"cache_name": cache_name, "cache_name": cache_name,
}, }
def get_stats(self):
usage = UsageStats()
req = RequestsStats()
block = BlocksStats()
errors = ErrorsStats()
self.read_lock()
conf = self.get_conf()
status = self.owner.lib.ocf_stats_collect_cache(
self.cache_handle, byref(usage), byref(req), byref(block), byref(errors)
)
self.read_unlock()
if status:
raise OcfError("Failed getting stats", status)
return {
"conf": conf,
"block": struct_to_dict(block), "block": struct_to_dict(block),
"req": struct_to_dict(req), "req": struct_to_dict(req),
"usage": struct_to_dict(usage), "usage": struct_to_dict(usage),

View File

@ -27,5 +27,6 @@ class CacheVolume(ExpObjVolume):
) )
def md5(self): def md5(self):
cache_line_size = int(self.cache.get_stats()['conf']['cache_line_size']) out = self.cache.get_conf()
cache_line_size = int(out['cache_line_size'])
return self._exp_obj_md5(cache_line_size) return self._exp_obj_md5(cache_line_size)