pyocf: format all .py files with black -l 100

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2022-05-09 16:27:19 +02:00
parent 3a1b6fd718
commit 83bb7317bf
32 changed files with 284 additions and 565 deletions

View File

@@ -14,10 +14,7 @@ class OcfLib:
def getInstance(cls):
if cls.__lib__ is None:
lib = cdll.LoadLibrary(
os.path.join(
os.path.dirname(inspect.getfile(inspect.currentframe())),
"libocf.so",
)
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), "libocf.so",)
)
lib.ocf_volume_get_uuid.restype = c_void_p
lib.ocf_volume_get_uuid.argtypes = [c_void_p]

View File

@@ -154,12 +154,7 @@ class Rio:
data = Data(self.jobspec.bs) # TODO pattern and verify
io = self.jobspec.target.new_io(
self.queue,
next(iogen),
self.jobspec.bs,
iodir,
0,
0,
self.queue, next(iogen), self.jobspec.bs, iodir, 0, 0,
)
io.set_data(data)
io.callback = self.get_io_cb()

View File

@@ -41,6 +41,7 @@ from .stats.shared import UsageStats, RequestsStats, BlocksStats, ErrorsStats
from .ctx import OcfCtx
from .volume import RamVolume, Volume
class Backfill(Structure):
_fields_ = [("_max_queue_size", c_uint32), ("_queue_unblock_size", c_uint32)]
@@ -76,7 +77,7 @@ class CacheAttachConfig(Structure):
("_open_cores", c_bool),
("_force", c_bool),
("_discard_on_start", c_bool),
("_disable_cleaner", c_bool)
("_disable_cleaner", c_bool),
]
@@ -214,8 +215,7 @@ class Cache:
_cache_line_size=self.cache_line_size,
_metadata_volatile=self.metadata_volatile,
_backfill=Backfill(
_max_queue_size=self.max_queue_size,
_queue_unblock_size=self.queue_unblock_size,
_max_queue_size=self.max_queue_size, _queue_unblock_size=self.queue_unblock_size,
),
_locked=locked,
_pt_unaligned_io=self.pt_unaligned_io,
@@ -259,9 +259,7 @@ class Cache:
def standby_activate(self, device, open_cores=True):
device_cfg = Cache.generate_device_config(device)
activate_cfg = CacheStandbyActivateConfig(
_device=device_cfg, _open_cores=open_cores,
)
activate_cfg = CacheStandbyActivateConfig(_device=device_cfg, _open_cores=open_cores,)
self.write_lock()
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
@@ -297,9 +295,7 @@ class Cache:
if c.results["error"]:
raise OcfError("Error changing cleaning policy", c.results["error"])
def set_cleaning_policy_param(
self, cleaning_policy: CleaningPolicy, param_id, param_value
):
def set_cleaning_policy_param(self, cleaning_policy: CleaningPolicy, param_id, param_value):
self.write_lock()
status = self.owner.lib.ocf_mngt_cache_cleaning_set_param(
@@ -351,9 +347,7 @@ class Cache:
def set_seq_cut_off_policy(self, policy: SeqCutOffPolicy):
self.write_lock()
status = self.owner.lib.ocf_mngt_core_set_seq_cutoff_policy_all(
self.cache_handle, policy
)
status = self.owner.lib.ocf_mngt_core_set_seq_cutoff_policy_all(self.cache_handle, policy)
self.write_unlock()
@@ -382,9 +376,7 @@ class Cache:
self.write_unlock()
if status:
raise OcfError(
"Error setting cache seq cut off policy promotion count", status
)
raise OcfError("Error setting cache seq cut off policy promotion count", status)
def get_partition_info(self, part_id: int):
ioclass_info = IoClassInfo()
@@ -410,13 +402,7 @@ class Cache:
}
def add_partition(
self,
part_id: int,
name: str,
min_size: int,
max_size: int,
priority: int,
valid: bool,
self, part_id: int, name: str, min_size: int, max_size: int, priority: int, valid: bool,
):
self.write_lock()
@@ -432,12 +418,7 @@ class Cache:
raise OcfError("Error adding partition to cache", status)
def configure_partition(
self,
part_id: int,
name: str,
max_size: int,
priority: int,
cache_mode=CACHE_MODE_NONE,
self, part_id: int, name: str, max_size: int, priority: int, cache_mode=CACHE_MODE_NONE,
):
ioclasses_info = IoClassesInfo()
@@ -491,12 +472,7 @@ class Cache:
return device_config
def attach_device(
self,
device,
force=False,
perform_test=False,
cache_line_size=None,
open_cores=False,
self, device, force=False, perform_test=False, cache_line_size=None, open_cores=False,
):
self.device = device
self.device_name = device.uuid
@@ -505,9 +481,7 @@ class Cache:
attach_cfg = CacheAttachConfig(
_device=device_config,
_cache_line_size=cache_line_size
if cache_line_size
else self.cache_line_size,
_cache_line_size=cache_line_size if cache_line_size else self.cache_line_size,
_open_cores=open_cores,
_force=force,
_discard_on_start=False,
@@ -517,17 +491,14 @@ class Cache:
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
self.owner.lib.ocf_mngt_cache_attach(
self.cache_handle, byref(attach_cfg), c, None
)
self.owner.lib.ocf_mngt_cache_attach(self.cache_handle, byref(attach_cfg), c, None)
c.wait()
self.write_unlock()
if c.results["error"]:
raise OcfError(
f"Attaching cache device failed",
c.results["error"],
f"Attaching cache device failed", c.results["error"],
)
def standby_attach(self, device, force=False):
@@ -548,17 +519,14 @@ class Cache:
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
self.owner.lib.ocf_mngt_cache_standby_attach(
self.cache_handle, byref(attach_cfg), c, None
)
self.owner.lib.ocf_mngt_cache_standby_attach(self.cache_handle, byref(attach_cfg), c, None)
c.wait()
self.write_unlock()
if c.results["error"]:
raise OcfError(
f"Attaching to standby cache failed",
c.results["error"],
f"Attaching to standby cache failed", c.results["error"],
)
def standby_load(self, device, perform_test=True):
@@ -577,9 +545,7 @@ class Cache:
self.write_lock()
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
self.owner.lib.ocf_mngt_cache_standby_load(
self.cache_handle, byref(attach_cfg), c, None
)
self.owner.lib.ocf_mngt_cache_standby_load(self.cache_handle, byref(attach_cfg), c, None)
c.wait()
self.write_unlock()
@@ -616,9 +582,7 @@ class Cache:
self.write_lock()
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
self.owner.lib.ocf_mngt_cache_load(
self.cache_handle, byref(attach_cfg), c, None
)
self.owner.lib.ocf_mngt_cache_load(self.cache_handle, byref(attach_cfg), c, None)
c.wait()
self.write_unlock()
@@ -689,10 +653,7 @@ class Cache:
core_handle = c_void_p()
result = self.owner.lib.ocf_core_get_by_name(
self.cache_handle,
name.encode("ascii"),
len(name),
byref(core_handle),
self.cache_handle, name.encode("ascii"), len(name), byref(core_handle),
)
if result != 0:
raise OcfError("Failed getting core by name", result)
@@ -714,12 +675,7 @@ class Cache:
self.write_lock()
c = OcfCompletion(
[
("cache", c_void_p),
("core", c_void_p),
("priv", c_void_p),
("error", c_int),
]
[("cache", c_void_p), ("core", c_void_p), ("priv", c_void_p), ("error", c_int),]
)
self.owner.lib.ocf_mngt_cache_add_core(self.cache_handle, byref(cfg), c, None)
@@ -908,6 +864,7 @@ class Cache:
def settle(self):
Queue.settle_many(self.io_queues + [self.mngt_queue])
lib = OcfLib.getInstance()
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]

View File

@@ -80,10 +80,7 @@ class Core:
def get_config(self):
cfg = CoreConfig(
_uuid=Uuid(
_data=cast(
create_string_buffer(self.device.uuid.encode("ascii")),
c_char_p,
),
_data=cast(create_string_buffer(self.device.uuid.encode("ascii")), c_char_p,),
_size=len(self.device.uuid) + 1,
),
_name=self.name.encode("ascii"),
@@ -123,9 +120,7 @@ class Core:
self.cache.read_unlock()
raise OcfError("Failed collecting core stats", status)
status = self.cache.owner.lib.ocf_core_get_info(
self.handle, byref(core_info)
)
status = self.cache.owner.lib.ocf_core_get_info(self.handle, byref(core_info))
if status:
self.cache.read_unlock()
raise OcfError("Failed getting core stats", status)
@@ -145,9 +140,7 @@ class Core:
def set_seq_cut_off_policy(self, policy: SeqCutOffPolicy):
self.cache.write_lock()
status = self.cache.owner.lib.ocf_mngt_core_set_seq_cutoff_policy(
self.handle, policy
)
status = self.cache.owner.lib.ocf_mngt_core_set_seq_cutoff_policy(self.handle, policy)
self.cache.write_unlock()
if status:
raise OcfError("Error setting core seq cut off policy", status)
@@ -155,9 +148,7 @@ class Core:
def set_seq_cut_off_threshold(self, threshold):
self.cache.write_lock()
status = self.cache.owner.lib.ocf_mngt_core_set_seq_cutoff_threshold(
self.handle, threshold
)
status = self.cache.owner.lib.ocf_mngt_core_set_seq_cutoff_threshold(self.handle, threshold)
self.cache.write_unlock()
if status:
raise OcfError("Error setting core seq cut off policy threshold", status)
@@ -175,6 +166,7 @@ class Core:
def reset_stats(self):
self.cache.owner.lib.ocf_core_stats_initialize(self.handle)
lib = OcfLib.getInstance()
lib.ocf_core_get_uuid_wrapper.restype = POINTER(Uuid)
lib.ocf_core_get_uuid_wrapper.argtypes = [c_void_p]

View File

@@ -13,6 +13,7 @@ from .shared import OcfError
from ..ocf import OcfLib
from .queue import Queue
class OcfCtxOps(Structure):
_fields_ = [
("data", DataOps),
@@ -41,9 +42,7 @@ class OcfCtx:
self.cfg = OcfCtxCfg(
name=name,
ops=OcfCtxOps(
data=self.data.get_ops(),
cleaner=self.cleaner.get_ops(),
logger=logger.get_ops(),
data=self.data.get_ops(), cleaner=self.cleaner.get_ops(), logger=logger.get_ops(),
),
logger_priv=cast(pointer(logger.get_priv()), c_void_p),
)
@@ -57,13 +56,7 @@ class OcfCtx:
@classmethod
def with_defaults(cls, logger):
return cls(
OcfLib.getInstance(),
b"PyOCF default ctx",
logger,
Data,
Cleaner,
)
return cls(OcfLib.getInstance(), b"PyOCF default ctx", logger, Data, Cleaner,)
@classmethod
def get_default(cls):
@@ -90,9 +83,7 @@ class OcfCtx:
if not vol_type.type_id:
raise Exception("Already unregistered")
self.lib.ocf_ctx_unregister_volume_type(
self.ctx_handle, vol_type.type_id
)
self.lib.ocf_ctx_unregister_volume_type(self.ctx_handle, vol_type.type_id)
del self.volume_types[vol_type.type_id]

View File

@@ -161,9 +161,7 @@ class Data:
@staticmethod
@DataOps.COPY
def _copy(dst, src, skip, seek, size):
return Data.get_instance(dst).copy(
Data.get_instance(src), skip, seek, size
)
return Data.get_instance(dst).copy(Data.get_instance(src), skip, seek, size)
@staticmethod
@DataOps.SECURE_ERASE

View File

@@ -53,9 +53,7 @@ class Io(Structure):
def from_pointer(cls, ref):
c = cls.from_address(ref)
cls._instances_[ref] = c
OcfLib.getInstance().ocf_io_set_cmpl_wrapper(
byref(c), None, None, c.c_end
)
OcfLib.getInstance().ocf_io_set_cmpl_wrapper(byref(c), None, None, c.c_end)
return c
@classmethod

View File

@@ -22,6 +22,7 @@ from ..ocf import OcfLib
logging.basicConfig(level=logging.DEBUG, handlers=[logging.NullHandler()])
class LogLevel(IntEnum):
EMERG = 0
ALERT = 1
@@ -123,9 +124,7 @@ class DefaultLogger(Logger):
self.logger = logging.getLogger(name)
ch = logging.StreamHandler()
fmt = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
fmt = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch.setFormatter(fmt)
ch.setLevel(LevelMapping[level])
self.logger.addHandler(ch)
@@ -140,9 +139,7 @@ class DefaultLogger(Logger):
class FileLogger(Logger):
def __init__(self, f, console_level=None):
super().__init__()
fmt = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
fmt = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
fh = logging.FileHandler(f)
fh.setLevel(logging.DEBUG)

View File

@@ -69,9 +69,7 @@ class OcfCompletion:
class CompletionResult:
def __init__(self, completion_args):
self.completion_args = {
x[0]: i for i, x in enumerate(completion_args)
}
self.completion_args = {x[0]: i for i, x in enumerate(completion_args)}
self.results = None
self.arg_types = [x[1] for x in completion_args]
@@ -131,9 +129,7 @@ class SharedOcfObject(Structure):
return cls._instances_[ref]
except: # noqa E722
logging.getLogger("pyocf").error(
"OcfSharedObject corruption. wanted: {} instances: {}".format(
ref, cls._instances_
)
"OcfSharedObject corruption. wanted: {} instances: {}".format(ref, cls._instances_)
)
return None

View File

@@ -1,4 +1,3 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

View File

@@ -71,6 +71,7 @@ class VolumeProperties(Structure):
("_ops_", VolumeOps),
]
class VolumeIoPriv(Structure):
_fields_ = [("_data", c_void_p), ("_offset", c_uint64)]
@@ -92,18 +93,14 @@ class Volume:
@VolumeOps.SUBMIT_IO
def _submit_io(io):
io_structure = cast(io, POINTER(Io))
volume = Volume.get_instance(
OcfLib.getInstance().ocf_io_get_volume(io_structure)
)
volume = Volume.get_instance(OcfLib.getInstance().ocf_io_get_volume(io_structure))
volume.submit_io(io_structure)
@VolumeOps.SUBMIT_FLUSH
def _submit_flush(flush):
io_structure = cast(flush, POINTER(Io))
volume = Volume.get_instance(
OcfLib.getInstance().ocf_io_get_volume(io_structure)
)
volume = Volume.get_instance(OcfLib.getInstance().ocf_io_get_volume(io_structure))
volume.submit_flush(io_structure)
@@ -114,9 +111,7 @@ class Volume:
@VolumeOps.SUBMIT_DISCARD
def _submit_discard(discard):
io_structure = cast(discard, POINTER(Io))
volume = Volume.get_instance(
OcfLib.getInstance().ocf_io_get_volume(io_structure)
)
volume = Volume.get_instance(OcfLib.getInstance().ocf_io_get_volume(io_structure))
volume.submit_discard(io_structure)
@@ -126,9 +121,7 @@ class Volume:
@VolumeOps.OPEN
def _open(ref):
uuid_ptr = cast(
OcfLib.getInstance().ocf_volume_get_uuid(ref), POINTER(Uuid)
)
uuid_ptr = cast(OcfLib.getInstance().ocf_volume_get_uuid(ref), POINTER(Uuid))
uuid = str(uuid_ptr.contents._data, encoding="ascii")
try:
volume = Volume.get_by_uuid(uuid)
@@ -215,9 +208,7 @@ class Volume:
@staticmethod
@IoOps.SET_DATA
def _io_set_data(io, data, offset):
io_priv = cast(
OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv)
)
io_priv = cast(OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
data = Data.get_instance(data)
io_priv.contents._offset = offset
io_priv.contents._data = data.handle
@@ -227,17 +218,13 @@ class Volume:
@staticmethod
@IoOps.GET_DATA
def _io_get_data(io):
io_priv = cast(
OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv)
)
io_priv = cast(OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
return io_priv.contents._data
def __init__(self, uuid=None):
if uuid:
if uuid in type(self)._uuid_:
raise Exception(
"Volume with uuid {} already created".format(uuid)
)
raise Exception("Volume with uuid {} already created".format(uuid))
self.uuid = uuid
else:
self.uuid = str(id(self))
@@ -314,13 +301,7 @@ class Volume:
self._reject_io(io)
def new_io(
self,
queue: Queue,
addr: int,
length: int,
direction: IoDir,
io_class: int,
flags: int,
self, queue: Queue, addr: int, length: int, direction: IoDir, io_class: int, flags: int,
):
lib = OcfLib.getInstance()
io = lib.ocf_volume_new_io(
@@ -370,8 +351,7 @@ class RamVolume(Volume):
def do_submit_io(self, io):
try:
io_priv = cast(
OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
io_priv = cast(OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
offset = io_priv.contents._offset
if io.contents._dir == IoDir.WRITE:
@@ -407,12 +387,7 @@ class RamVolume(Volume):
class ErrorDevice(Volume):
def __init__(
self,
vol,
error_sectors: set = None,
error_seq_no: dict = None,
armed=True,
uuid=None,
self, vol, error_sectors: set = None, error_seq_no: dict = None, armed=True, uuid=None,
):
self.vol = vol
super().__init__(uuid)
@@ -436,9 +411,7 @@ class ErrorDevice(Volume):
and direction in self.error_seq_no
and self.error_seq_no[direction] <= self.io_seq_no[direction]
)
sector_match = (
self.error_sectors is not None and io.contents._addr in self.error_sectors
)
sector_match = self.error_sectors is not None and io.contents._addr in self.error_sectors
self.io_seq_no[direction] += 1
@@ -489,6 +462,7 @@ class ErrorDevice(Volume):
def get_copy(self):
return self.vol.get_copy()
lib = OcfLib.getInstance()
lib.ocf_io_get_priv.restype = POINTER(VolumeIoPriv)
lib.ocf_io_get_volume.argtypes = [c_void_p]

View File

@@ -21,12 +21,9 @@ class CacheVolume(ExpObjVolume):
self.open()
def open(self):
return Volume.open(
self.lib.ocf_cache_get_front_volume(self.cache.cache_handle),
self
)
return Volume.open(self.lib.ocf_cache_get_front_volume(self.cache.cache_handle), self)
def md5(self):
out = self.cache.get_conf()
cache_line_size = int(out['cache_line_size'])
cache_line_size = int(out["cache_line_size"])
return self._exp_obj_md5(cache_line_size)

View File

@@ -18,10 +18,7 @@ class CoreVolume(ExpObjVolume):
self.open()
def open(self):
return Volume.open(
self.lib.ocf_core_get_front_volume(self.core.handle),
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

@@ -22,9 +22,7 @@ class ExpObjVolume(Volume):
def __alloc_io(self, addr, _bytes, _dir, _class, _flags):
vol = self.parent.get_front_volume()
queue = self.parent.get_default_queue() # TODO multiple queues?
return vol.new_io(
queue, addr, _bytes, _dir, _class, _flags
)
return vol.new_io(queue, addr, _bytes, _dir, _class, _flags)
def _alloc_io(self, io):
exp_obj_io = self.__alloc_io(
@@ -99,8 +97,7 @@ class ExpObjVolume(Volume):
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 = 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)])

View File

@@ -7,13 +7,7 @@ from ctypes import string_at
def print_buffer(
buf,
length,
offset=0,
width=16,
ignore=0,
stop_after_count_ignored=0,
print_fcn=print,
buf, length, offset=0, width=16, ignore=0, stop_after_count_ignored=0, print_fcn=print,
):
end = int(offset) + int(length)
offset = int(offset)
@@ -27,10 +21,7 @@ def print_buffer(
byteline = ""
asciiline = ""
if not any(x != ignore for x in cur_line):
if (
stop_after_count_ignored
and ignored_lines > stop_after_count_ignored
):
if stop_after_count_ignored and ignored_lines > stop_after_count_ignored:
print_fcn(
"<{} bytes of '0x{:02X}' encountered, stopping>".format(
stop_after_count_ignored * width, ignore
@@ -41,11 +32,7 @@ def print_buffer(
continue
if ignored_lines:
print_fcn(
"<{} of '0x{:02X}' bytes omitted>".format(
ignored_lines * width, ignore
)
)
print_fcn("<{} of '0x{:02X}' bytes omitted>".format(ignored_lines * width, ignore))
ignored_lines = 0
for byte in cur_line:
@@ -76,10 +63,7 @@ class Size:
def __init__(self, b: int, sector_aligned: bool = False):
if sector_aligned:
self.bytes = int(
((b + self._SECTOR_SIZE - 1) // self._SECTOR_SIZE)
* self._SECTOR_SIZE
)
self.bytes = int(((b + self._SECTOR_SIZE - 1) // self._SECTOR_SIZE) * self._SECTOR_SIZE)
else:
self.bytes = int(b)