Merge pull request #726 from arutk/fipm
flush handling fixes and enhanced tests
This commit is contained in:
@@ -102,6 +102,12 @@ class Io(Structure):
|
||||
def submit_discard(self):
|
||||
return OcfLib.getInstance().ocf_volume_submit_discard(byref(self))
|
||||
|
||||
def submit_flush(self):
|
||||
return OcfLib.getInstance().ocf_volume_submit_flush(byref(self))
|
||||
|
||||
def submit_discard(self):
|
||||
return OcfLib.getInstance().ocf_volume_submit_discard(byref(self))
|
||||
|
||||
def set_data(self, data: Data, offset: int = 0):
|
||||
self.data = data
|
||||
OcfLib.getInstance().ocf_io_set_data(byref(self), data, offset)
|
||||
|
@@ -22,6 +22,7 @@ from ctypes import (
|
||||
)
|
||||
from hashlib import md5
|
||||
import weakref
|
||||
from enum import IntEnum
|
||||
|
||||
from .io import Io, IoOps, IoDir
|
||||
from .queue import Queue
|
||||
@@ -32,6 +33,10 @@ from .data import Data
|
||||
from .queue import Queue
|
||||
|
||||
|
||||
class IoFlags(IntEnum):
|
||||
FLUSH = 1
|
||||
|
||||
|
||||
class VolumeCaps(Structure):
|
||||
_fields_ = [("_atomic_writes", c_uint32, 1)]
|
||||
|
||||
@@ -350,6 +355,11 @@ class RamVolume(Volume):
|
||||
discard.contents._end(discard, -OcfErrorCode.OCF_ERR_NOT_SUPP)
|
||||
|
||||
def do_submit_io(self, io):
|
||||
flags = int(io.contents._flags)
|
||||
if flags & IoFlags.FLUSH:
|
||||
self.do_submit_flush(io)
|
||||
return
|
||||
|
||||
try:
|
||||
io_priv = cast(OcfLib.getInstance().ocf_io_get_priv(io), POINTER(VolumeIoPriv))
|
||||
offset = io_priv.contents._offset
|
||||
@@ -463,6 +473,56 @@ class ErrorDevice(Volume):
|
||||
return self.vol.get_copy()
|
||||
|
||||
|
||||
class TraceDevice(Volume):
|
||||
class IoType(IntEnum):
|
||||
Data = 1
|
||||
Flush = 2
|
||||
Discard = 3
|
||||
|
||||
def __init__(self, vol, trace_fcn=None, uuid=None):
|
||||
self.vol = vol
|
||||
super().__init__(uuid)
|
||||
self.trace_fcn = trace_fcn
|
||||
|
||||
def _trace(self, io, io_type):
|
||||
submit = True
|
||||
|
||||
if self.trace_fcn:
|
||||
submit = self.trace_fcn(self, io, io_type)
|
||||
|
||||
return submit
|
||||
|
||||
def do_submit_io(self, io):
|
||||
submit = self._trace(io, TraceDevice.IoType.Data)
|
||||
|
||||
if submit:
|
||||
self.vol.do_submit_io(io)
|
||||
|
||||
def do_submit_flush(self, io):
|
||||
submit = self._trace(io, TraceDevice.IoType.Flush)
|
||||
|
||||
if submit:
|
||||
self.vol.do_submit_flush(io)
|
||||
|
||||
def get_length(self):
|
||||
return self.vol.get_length()
|
||||
|
||||
def get_max_io_size(self):
|
||||
return self.vol.get_max_io_size()
|
||||
|
||||
def do_submit_discard(self, discard):
|
||||
return self.vol.do_submit_discard(discard)
|
||||
|
||||
def dump(self, offset=0, size=0, ignore=VOLUME_POISON, **kwargs):
|
||||
return self.vol.dump(offset, size, ignore=ignore, **kwargs)
|
||||
|
||||
def md5(self):
|
||||
return self.vol.md5()
|
||||
|
||||
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]
|
||||
|
72
tests/functional/tests/engine/test_flush.py
Normal file
72
tests/functional/tests/engine/test_flush.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#
|
||||
# Copyright(c) 2022-2022 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
from ctypes import c_int
|
||||
|
||||
from pyocf.types.cache import Cache
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.io import IoDir
|
||||
from pyocf.types.volume import RamVolume, IoFlags, TraceDevice
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
from pyocf.types.shared import OcfCompletion
|
||||
|
||||
|
||||
def test_flush_propagation(pyocf_ctx):
|
||||
flushes = {}
|
||||
|
||||
pyocf_ctx.register_volume_type(TraceDevice)
|
||||
|
||||
def trace_flush(vol, io, io_type):
|
||||
nonlocal flushes
|
||||
|
||||
if io_type == TraceDevice.IoType.Flush or int(io.contents._flags) & IoFlags.FLUSH:
|
||||
if vol.uuid not in flushes:
|
||||
flushes[vol.uuid] = []
|
||||
flushes[vol.uuid].append((io.contents._addr, io.contents._bytes))
|
||||
|
||||
return True
|
||||
|
||||
cache_device = TraceDevice(RamVolume(Size.from_MiB(50)), trace_fcn=trace_flush)
|
||||
core_device = TraceDevice(RamVolume(Size.from_MiB(100)), trace_fcn=trace_flush)
|
||||
|
||||
addr = Size.from_MiB(2).B
|
||||
size = Size.from_MiB(1).B
|
||||
|
||||
cache = Cache.start_on_device(cache_device)
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
|
||||
queue = cache.get_default_queue()
|
||||
vol = CoreVolume(core, open=True)
|
||||
|
||||
flushes = {}
|
||||
|
||||
io = vol.new_io(queue, addr, size, IoDir.WRITE, 0, IoFlags.FLUSH)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
data = Data(byte_count=0)
|
||||
io.set_data(data, 0)
|
||||
|
||||
io.submit_flush()
|
||||
completion.wait()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
||||
assert cache_device.uuid in flushes
|
||||
assert core_device.uuid in flushes
|
||||
|
||||
cache_flushes = flushes[cache_device.uuid]
|
||||
core_flushes = flushes[core_device.uuid]
|
||||
|
||||
assert len(cache_flushes) == 1
|
||||
assert len(core_flushes) == 1
|
||||
|
||||
assert core_flushes[0] == (addr, size)
|
||||
|
||||
# empty flush expected to be sent to cache device
|
||||
assert cache_flushes[0] == (0, 0)
|
||||
|
||||
cache.stop()
|
87
tests/functional/tests/engine/test_large_io.py
Normal file
87
tests/functional/tests/engine/test_large_io.py
Normal file
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
from ctypes import c_int
|
||||
|
||||
from pyocf.types.cache import Cache
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.io import IoDir
|
||||
from pyocf.types.volume import RamVolume, IoFlags
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
from pyocf.types.shared import OcfCompletion
|
||||
|
||||
|
||||
def test_large_flush(pyocf_ctx):
|
||||
cache_device = RamVolume(Size.from_MiB(50))
|
||||
core_device = RamVolume(Size.from_MiB(100))
|
||||
|
||||
cache = Cache.start_on_device(cache_device)
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
|
||||
queue = cache.get_default_queue()
|
||||
vol = CoreVolume(core, open=True)
|
||||
|
||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, IoFlags.FLUSH)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
data = Data(byte_count=0)
|
||||
io.set_data(data, 0)
|
||||
io.submit_flush()
|
||||
completion.wait()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
||||
cache.stop()
|
||||
|
||||
|
||||
def test_large_discard(pyocf_ctx):
|
||||
cache_device = RamVolume(Size.from_MiB(50))
|
||||
core_device = RamVolume(Size.from_MiB(100))
|
||||
|
||||
cache = Cache.start_on_device(cache_device)
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
|
||||
queue = cache.get_default_queue()
|
||||
vol = CoreVolume(core, open=True)
|
||||
|
||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
data = Data(byte_count=0)
|
||||
io.set_data(data, 0)
|
||||
io.submit_discard()
|
||||
completion.wait()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
||||
cache.stop()
|
||||
|
||||
|
||||
def test_large_io(pyocf_ctx):
|
||||
cache_device = RamVolume(Size.from_MiB(50))
|
||||
core_device = RamVolume(Size.from_MiB(100))
|
||||
|
||||
cache = Cache.start_on_device(cache_device)
|
||||
core = Core.using_device(core_device)
|
||||
cache.add_core(core)
|
||||
|
||||
queue = cache.get_default_queue()
|
||||
vol = CoreVolume(core, open=True)
|
||||
|
||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
data = Data(byte_count=core_device.size.bytes)
|
||||
io.set_data(data)
|
||||
io.submit()
|
||||
completion.wait()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
||||
cache.stop()
|
Reference in New Issue
Block a user