Merge pull request #122 from KamilLepek/security_tests
Add security fuzzy tests and improve pyocf api
This commit is contained in:
@@ -21,7 +21,7 @@ from enum import IntEnum
|
||||
from datetime import timedelta
|
||||
|
||||
from ..ocf import OcfLib
|
||||
from .shared import Uuid, OcfError, CacheLineSize, CacheLines, OcfCompletion
|
||||
from .shared import Uuid, OcfError, CacheLineSize, CacheLines, OcfCompletion, SeqCutOffPolicy
|
||||
from ..utils import Size, struct_to_dict
|
||||
from .core import Core
|
||||
from .queue import Queue
|
||||
@@ -82,6 +82,18 @@ class CleaningPolicy(IntEnum):
|
||||
DEFAULT = ALRU
|
||||
|
||||
|
||||
class AlruParams(IntEnum):
|
||||
WAKE_UP_TIME = 0,
|
||||
STALE_BUFFER_TIME = 1,
|
||||
FLUSH_MAX_BUFFERS = 2,
|
||||
ACTIVITY_THRESHOLD = 3
|
||||
|
||||
|
||||
class AcpParams(IntEnum):
|
||||
WAKE_UP_TIME = 0,
|
||||
FLUSH_MAX_BUFFERS = 1
|
||||
|
||||
|
||||
class MetadataLayout(IntEnum):
|
||||
STRIPING = 0
|
||||
SEQUENTIAL = 1
|
||||
@@ -168,7 +180,35 @@ class Cache:
|
||||
|
||||
def change_cache_mode(self, cache_mode: CacheMode):
|
||||
self.get_and_write_lock()
|
||||
self.owner.lib.ocf_mngt_cache_set_mode(self.cache_handle, cache_mode)
|
||||
status = self.owner.lib.ocf_mngt_cache_set_mode(self.cache_handle, cache_mode)
|
||||
if status:
|
||||
raise OcfError("Error changing cache mode", status)
|
||||
self.put_and_write_unlock()
|
||||
|
||||
def set_cleaning_policy(self, cleaning_policy: CleaningPolicy):
|
||||
self.get_and_write_lock()
|
||||
status = self.owner.lib.ocf_mngt_cache_cleaning_set_policy(self.cache_handle, cleaning_policy)
|
||||
if status:
|
||||
raise OcfError("Error changing cleaning policy", status)
|
||||
self.put_and_write_unlock()
|
||||
|
||||
def set_cleaning_policy_param(self, cleaning_policy: CleaningPolicy, param_id, param_value):
|
||||
self.get_and_write_lock()
|
||||
status = self.owner.lib.ocf_mngt_cache_cleaning_set_param(
|
||||
self.cache_handle,
|
||||
cleaning_policy,
|
||||
param_id,
|
||||
param_value
|
||||
)
|
||||
if status:
|
||||
raise OcfError("Error setting cleaning policy param", status)
|
||||
self.put_and_write_unlock()
|
||||
|
||||
def set_seq_cut_off_policy(self, policy: SeqCutOffPolicy):
|
||||
self.get_and_write_lock()
|
||||
status = self.owner.lib.ocf_mngt_core_set_seq_cutoff_policy_all(self.cache_handle, policy)
|
||||
if status:
|
||||
raise OcfError("Error setting cache seq cut off policy", status)
|
||||
self.put_and_write_unlock()
|
||||
|
||||
def configure_device(
|
||||
@@ -457,3 +497,10 @@ lib.ocf_mngt_cache_remove_core.argtypes = [c_void_p, c_void_p, c_void_p]
|
||||
lib.ocf_mngt_cache_add_core.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p]
|
||||
lib.ocf_cache_get_name.argtypes = [c_void_p]
|
||||
lib.ocf_cache_get_name.restype = c_char_p
|
||||
lib.ocf_mngt_cache_cleaning_set_policy.argtypes = [c_void_p, c_uint32]
|
||||
lib.ocf_mngt_cache_cleaning_set_policy.restype = c_int
|
||||
lib.ocf_mngt_core_set_seq_cutoff_policy_all.argtypes = [c_void_p, c_uint32]
|
||||
lib.ocf_mngt_core_set_seq_cutoff_policy_all.restype = c_int
|
||||
lib.ocf_mngt_cache_cleaning_set_param.argtypes = [c_void_p, c_uint32, c_uint32, c_uint32]
|
||||
lib.ocf_mngt_cache_cleaning_set_param.restype = c_int
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import logging
|
||||
from datetime import timedelta
|
||||
|
||||
from ..ocf import OcfLib
|
||||
from .shared import Uuid, OcfCompletion, OcfError
|
||||
from .shared import Uuid, OcfCompletion, OcfError, SeqCutOffPolicy
|
||||
from .volume import Volume
|
||||
from .data import Data
|
||||
from .io import Io, IoDir
|
||||
@@ -138,6 +138,13 @@ class Core:
|
||||
"errors": struct_to_dict(errors),
|
||||
}
|
||||
|
||||
def set_seq_cut_off_policy(self, policy: SeqCutOffPolicy):
|
||||
self.cache.get_and_write_lock()
|
||||
status = self.cache.owner.lib.ocf_mngt_core_set_seq_cutoff_policy(self.handle, policy)
|
||||
if status:
|
||||
raise OcfError("Error setting core seq cut off policy", status)
|
||||
self.cache.put_and_write_unlock()
|
||||
|
||||
def reset_stats(self):
|
||||
self.cache.owner.lib.ocf_core_stats_initialize(self.handle)
|
||||
|
||||
@@ -168,3 +175,5 @@ lib.ocf_volume_new_io.argtypes = [c_void_p]
|
||||
lib.ocf_volume_new_io.restype = c_void_p
|
||||
lib.ocf_core_get_volume.argtypes = [c_void_p]
|
||||
lib.ocf_core_get_volume.restype = c_void_p
|
||||
lib.ocf_mngt_core_set_seq_cutoff_policy.argtypes = [c_void_p, c_uint32]
|
||||
lib.ocf_mngt_core_set_seq_cutoff_policy.restype = c_int
|
||||
|
||||
@@ -123,6 +123,13 @@ class CacheLineSize(IntEnum):
|
||||
DEFAULT = LINE_4KiB
|
||||
|
||||
|
||||
class SeqCutOffPolicy(IntEnum):
|
||||
ALWAYS = 0
|
||||
FULL = 1
|
||||
NEVER = 2
|
||||
DEFAULT = FULL
|
||||
|
||||
|
||||
class CacheLines(S):
|
||||
def __init__(self, count: int, line_size: CacheLineSize):
|
||||
self.bytes = count * line_size
|
||||
|
||||
@@ -15,7 +15,6 @@ def print_buffer(buf, length, offset=0, width=16, stop_after_zeros=0):
|
||||
|
||||
for addr in range(offset, end, width):
|
||||
cur_line = buf[addr : min(end, addr + width)]
|
||||
all_zeros = True
|
||||
byteline = ""
|
||||
asciiline = ""
|
||||
if not any(cur_line):
|
||||
|
||||
Reference in New Issue
Block a user