pyocf: Update to use forward API
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
committed by
Michal Mielewczyk
parent
0cd2393aaf
commit
c9cd217a08
@@ -20,13 +20,13 @@ def test_discard_propagation(pyocf_ctx):
|
||||
|
||||
pyocf_ctx.register_volume_type(TraceDevice)
|
||||
|
||||
def trace_discard(vol, io, io_type):
|
||||
def trace_discard(vol, io_type, rw, addr, nbytes, flags):
|
||||
nonlocal discards
|
||||
|
||||
if io_type == TraceDevice.IoType.Discard:
|
||||
if vol.uuid not in discards:
|
||||
discards[vol.uuid] = []
|
||||
discards[vol.uuid].append((io.contents._addr, io.contents._bytes))
|
||||
discards[vol.uuid].append((addr, nbytes))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
from pyocf.types.cache import Cache
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.io import IoDir, Sync
|
||||
from pyocf.types.io import Io, IoDir, Sync
|
||||
from pyocf.types.volume import RamVolume, IoFlags, TraceDevice
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
@@ -18,22 +18,19 @@ def test_flush_propagation(pyocf_ctx):
|
||||
|
||||
pyocf_ctx.register_volume_type(TraceDevice)
|
||||
|
||||
def trace_flush(vol, io, io_type):
|
||||
def trace_flush(vol, io_type, rw, addr, nbytes, flags):
|
||||
nonlocal flushes
|
||||
|
||||
if io_type == TraceDevice.IoType.Flush or int(io.contents._flags) & IoFlags.FLUSH:
|
||||
if io_type == TraceDevice.IoType.Flush:
|
||||
if vol.uuid not in flushes:
|
||||
flushes[vol.uuid] = []
|
||||
flushes[vol.uuid].append((io.contents._addr, io.contents._bytes))
|
||||
flushes[vol.uuid].append((addr, nbytes))
|
||||
|
||||
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)
|
||||
@@ -44,9 +41,7 @@ def test_flush_propagation(pyocf_ctx):
|
||||
flushes = {}
|
||||
|
||||
vol.open()
|
||||
io = vol.new_io(queue, addr, size, IoDir.WRITE, 0, IoFlags.FLUSH)
|
||||
data = Data(byte_count=0)
|
||||
io.set_data(data, 0)
|
||||
io = vol.new_io(queue, 0, 0, IoDir.WRITE, 0, 0)
|
||||
|
||||
completion = Sync(io).submit_flush()
|
||||
vol.close()
|
||||
@@ -62,9 +57,4 @@ def test_flush_propagation(pyocf_ctx):
|
||||
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()
|
||||
|
||||
@@ -48,6 +48,14 @@ class FlushValVolume(RamVolume):
|
||||
self.flush_last = True
|
||||
super().submit_flush(flush)
|
||||
|
||||
def forward_io(self, token, rw, addr, nbytes, offset):
|
||||
self.flush_last = False
|
||||
super().forward_io(token, rw, addr, nbytes, offset)
|
||||
|
||||
def forward_flush(self, token):
|
||||
self.flush_last = True
|
||||
super().forward_flush(token)
|
||||
|
||||
|
||||
def test_flush_after_mngmt(pyocf_ctx):
|
||||
"""
|
||||
|
||||
@@ -166,12 +166,9 @@ def setup_tracing(backends):
|
||||
TraceDevice.IoType.Data: [],
|
||||
}
|
||||
|
||||
def trace(vol, io, io_type):
|
||||
if int(io.contents._flags) & IoFlags.FLUSH:
|
||||
io_type = TraceDevice.IoType.Flush
|
||||
|
||||
def trace(vol, io_type, rw, addr, nbytes, flags):
|
||||
io_trace[vol][io_type].append(
|
||||
IoEvent(io.contents._dir, io.contents._addr, io.contents._bytes)
|
||||
IoEvent(rw, addr, nbytes)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user