Replace ocf_forward_get_io() with more specific ops
struct ocf_io is going to be removed soon (consolidated with ocf_request). Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
6aa141c247
commit
2d303e8d09
28
inc/ocf_io.h
28
inc/ocf_io.h
@ -236,13 +236,6 @@ void ocf_io_handle(struct ocf_io *io, void *opaque);
|
|||||||
*/
|
*/
|
||||||
ocf_volume_t ocf_io_get_volume(struct ocf_io *io);
|
ocf_volume_t ocf_io_get_volume(struct ocf_io *io);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the original OCF IO associated with forward token
|
|
||||||
*
|
|
||||||
* @param[in] token Forward token
|
|
||||||
*/
|
|
||||||
struct ocf_io *ocf_forward_get_io(ocf_forward_token_t token);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the data to be submitted
|
* @brief Get the data to be submitted
|
||||||
*
|
*
|
||||||
@ -250,6 +243,27 @@ struct ocf_io *ocf_forward_get_io(ocf_forward_token_t token);
|
|||||||
*/
|
*/
|
||||||
ctx_data_t *ocf_forward_get_data(ocf_forward_token_t token);
|
ctx_data_t *ocf_forward_get_data(ocf_forward_token_t token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get io queue of forwarded io
|
||||||
|
*
|
||||||
|
* @param[in] token Forward token
|
||||||
|
*/
|
||||||
|
ocf_queue_t ocf_forward_get_io_queue(ocf_forward_token_t token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get io class of forwarded io
|
||||||
|
*
|
||||||
|
* @param[in] token Forward token
|
||||||
|
*/
|
||||||
|
uint8_t ocf_forward_get_io_class(ocf_forward_token_t token);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get flags of forwarded io
|
||||||
|
*
|
||||||
|
* @param[in] token Forward token
|
||||||
|
*/
|
||||||
|
uint64_t ocf_forward_get_flags(ocf_forward_token_t token);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Forward io to another subvolume
|
* @brief Forward io to another subvolume
|
||||||
*
|
*
|
||||||
|
@ -552,13 +552,6 @@ void ocf_req_forward_core_discard(struct ocf_request *req, uint64_t addr,
|
|||||||
ocf_volume_forward_discard(volume, token, addr, bytes);
|
ocf_volume_forward_discard(volume, token, addr, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ocf_io *ocf_forward_get_io(ocf_forward_token_t token)
|
|
||||||
{
|
|
||||||
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
|
||||||
|
|
||||||
return &req->ioi.io;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx_data_t *ocf_forward_get_data(ocf_forward_token_t token)
|
ctx_data_t *ocf_forward_get_data(ocf_forward_token_t token)
|
||||||
{
|
{
|
||||||
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
||||||
@ -566,6 +559,27 @@ ctx_data_t *ocf_forward_get_data(ocf_forward_token_t token)
|
|||||||
return req->data;
|
return req->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ocf_queue_t ocf_forward_get_io_queue(ocf_forward_token_t token)
|
||||||
|
{
|
||||||
|
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
||||||
|
|
||||||
|
return req->io_queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ocf_forward_get_io_class(ocf_forward_token_t token)
|
||||||
|
{
|
||||||
|
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
||||||
|
|
||||||
|
return req->ioi.io.io_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ocf_forward_get_flags(ocf_forward_token_t token)
|
||||||
|
{
|
||||||
|
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
||||||
|
|
||||||
|
return (token & 1) ? 0 : req->ioi.io.flags;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void _ocf_forward_get(ocf_forward_token_t token)
|
static inline void _ocf_forward_get(ocf_forward_token_t token)
|
||||||
{
|
{
|
||||||
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
struct ocf_request *req = (struct ocf_request *)(token & ~1);
|
||||||
|
@ -67,10 +67,6 @@ class Io(Structure):
|
|||||||
def get_instance(cls, ref):
|
def get_instance(cls, ref):
|
||||||
return cls._instances_[cast(ref, c_void_p).value]
|
return cls._instances_[cast(ref, c_void_p).value]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_by_forward_token(token):
|
|
||||||
return OcfLib.getInstance().ocf_forward_get_io(token)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def forward_get(token):
|
def forward_get(token):
|
||||||
OcfLib.getInstance().ocf_forward_get(token)
|
OcfLib.getInstance().ocf_forward_get(token)
|
||||||
@ -164,9 +160,6 @@ lib = OcfLib.getInstance()
|
|||||||
|
|
||||||
lib.ocf_forward_get.argtypes = [c_uint64]
|
lib.ocf_forward_get.argtypes = [c_uint64]
|
||||||
|
|
||||||
lib.ocf_forward_get_io.argtypes = [c_uint64]
|
|
||||||
lib.ocf_forward_get_io.restype = POINTER(Io)
|
|
||||||
|
|
||||||
lib.ocf_forward_end.argtypes = [c_uint64, c_int]
|
lib.ocf_forward_end.argtypes = [c_uint64, c_int]
|
||||||
|
|
||||||
lib.ocf_io_set_cmpl_wrapper.argtypes = [POINTER(Io), c_void_p, c_void_p, Io.END]
|
lib.ocf_io_set_cmpl_wrapper.argtypes = [POINTER(Io), c_void_p, c_void_p, Io.END]
|
||||||
|
@ -164,7 +164,7 @@ class Volume:
|
|||||||
|
|
||||||
@VolumeOps.OPEN
|
@VolumeOps.OPEN
|
||||||
def _open(ref, params):
|
def _open(ref, params):
|
||||||
uuid_ptr = cast(OcfLib.getInstance().ocf_volume_get_uuid(ref), POINTER(Uuid))
|
uuid_ptr = cast(lib.ocf_volume_get_uuid(ref), POINTER(Uuid))
|
||||||
uuid = str(uuid_ptr.contents._data, encoding="ascii")
|
uuid = str(uuid_ptr.contents._data, encoding="ascii")
|
||||||
try:
|
try:
|
||||||
volume = Volume.get_by_uuid(uuid)
|
volume = Volume.get_by_uuid(uuid)
|
||||||
@ -379,7 +379,6 @@ class Volume:
|
|||||||
def new_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(
|
io = lib.ocf_volume_new_io(
|
||||||
self.handle,
|
self.handle,
|
||||||
queue.handle if queue else c_void_p(),
|
queue.handle if queue else c_void_p(),
|
||||||
@ -520,11 +519,11 @@ class RamVolume(Volume):
|
|||||||
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
||||||
try:
|
try:
|
||||||
if rw == IoDir.WRITE:
|
if rw == IoDir.WRITE:
|
||||||
src_ptr = cast(OcfLib.getInstance().ocf_forward_get_data(token), c_void_p)
|
src_ptr = cast(lib.ocf_forward_get_data(token), c_void_p)
|
||||||
src = Data.get_instance(src_ptr.value).handle.value + offset
|
src = Data.get_instance(src_ptr.value).handle.value + offset
|
||||||
dst = self.data_ptr + addr
|
dst = self.data_ptr + addr
|
||||||
elif rw == IoDir.READ:
|
elif rw == IoDir.READ:
|
||||||
dst_ptr = cast(OcfLib.getInstance().ocf_forward_get_data(token), c_void_p)
|
dst_ptr = cast(lib.ocf_forward_get_data(token), c_void_p)
|
||||||
dst = Data.get_instance(dst_ptr.value).handle.value + offset
|
dst = Data.get_instance(dst_ptr.value).handle.value + offset
|
||||||
src = self.data_ptr + addr
|
src = self.data_ptr + addr
|
||||||
|
|
||||||
@ -756,39 +755,39 @@ class TraceDevice(Volume):
|
|||||||
self.vol.do_submit_discard(io)
|
self.vol.do_submit_discard(io)
|
||||||
|
|
||||||
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
||||||
io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
submit = self._trace(
|
submit = self._trace(
|
||||||
TraceDevice.IoType.Data,
|
TraceDevice.IoType.Data,
|
||||||
rw,
|
rw,
|
||||||
addr,
|
addr,
|
||||||
nbytes,
|
nbytes,
|
||||||
io.contents._flags
|
flags
|
||||||
)
|
)
|
||||||
|
|
||||||
if submit:
|
if submit:
|
||||||
self.vol.do_forward_io(token, rw, addr, nbytes, offset)
|
self.vol.do_forward_io(token, rw, addr, nbytes, offset)
|
||||||
|
|
||||||
def do_forward_flush(self, token):
|
def do_forward_flush(self, token):
|
||||||
io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
submit = self._trace(
|
submit = self._trace(
|
||||||
TraceDevice.IoType.Flush,
|
TraceDevice.IoType.Flush,
|
||||||
IoDir.WRITE,
|
IoDir.WRITE,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
io.contents._flags
|
flags
|
||||||
)
|
)
|
||||||
|
|
||||||
if submit:
|
if submit:
|
||||||
self.vol.do_forward_flush(token)
|
self.vol.do_forward_flush(token)
|
||||||
|
|
||||||
def do_forward_discard(self, token, addr, nbytes):
|
def do_forward_discard(self, token, addr, nbytes):
|
||||||
io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
submit = self._trace(
|
submit = self._trace(
|
||||||
TraceDevice.IoType.Discard,
|
TraceDevice.IoType.Discard,
|
||||||
IoDir.WRITE,
|
IoDir.WRITE,
|
||||||
addr,
|
addr,
|
||||||
nbytes,
|
nbytes,
|
||||||
io.contents._flags
|
flags
|
||||||
)
|
)
|
||||||
|
|
||||||
if submit:
|
if submit:
|
||||||
@ -818,6 +817,8 @@ lib.ocf_io_get_data.argtypes = [c_void_p]
|
|||||||
lib.ocf_io_get_data.restype = c_void_p
|
lib.ocf_io_get_data.restype = c_void_p
|
||||||
lib.ocf_forward_get_data.argtypes = [c_uint64]
|
lib.ocf_forward_get_data.argtypes = [c_uint64]
|
||||||
lib.ocf_forward_get_data.restype = c_void_p
|
lib.ocf_forward_get_data.restype = c_void_p
|
||||||
|
lib.ocf_forward_get_flags.argtypes = [c_uint64]
|
||||||
|
lib.ocf_forward_get_flags.restype = c_uint64
|
||||||
lib.ocf_volume_new_io.argtypes = [
|
lib.ocf_volume_new_io.argtypes = [
|
||||||
c_void_p,
|
c_void_p,
|
||||||
c_void_p,
|
c_void_p,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from ctypes import c_int, c_void_p, CFUNCTYPE, byref, c_uint32, c_uint64, cast, POINTER
|
from ctypes import c_int, c_void_p, CFUNCTYPE, byref, c_uint8, c_uint32, c_uint64, cast, POINTER
|
||||||
|
|
||||||
from ..ocf import OcfLib
|
from ..ocf import OcfLib
|
||||||
from .volume import Volume, VOLUME_POISON
|
from .volume import Volume, VOLUME_POISON
|
||||||
@ -24,16 +24,15 @@ class OcfInternalVolume(Volume):
|
|||||||
queue = self.parent.get_default_queue() # TODO multiple queues?
|
queue = self.parent.get_default_queue() # TODO multiple queues?
|
||||||
return self.new_io(queue, addr, _bytes, _dir, _class, _flags)
|
return self.new_io(queue, addr, _bytes, _dir, _class, _flags)
|
||||||
|
|
||||||
def _alloc_io(self, io, cdata=None, rw=None, addr=None, nbytes=None, offset=0):
|
def _alloc_io(self, io):
|
||||||
exp_obj_io = self.__alloc_io(
|
exp_obj_io = self.__alloc_io(
|
||||||
addr or io.contents._addr,
|
io.contents._addr,
|
||||||
nbytes or io.contents._bytes,
|
io.contents._bytes,
|
||||||
rw or io.contents._dir,
|
io.contents._dir,
|
||||||
io.contents._class,
|
io.contents._class,
|
||||||
io.contents._flags,
|
io.contents._flags,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not cdata:
|
|
||||||
cdata = OcfLib.getInstance().ocf_io_get_data(io)
|
cdata = OcfLib.getInstance().ocf_io_get_data(io)
|
||||||
OcfLib.getInstance().ocf_io_set_data(byref(exp_obj_io), cdata, offset)
|
OcfLib.getInstance().ocf_io_set_data(byref(exp_obj_io), cdata, offset)
|
||||||
|
|
||||||
@ -47,10 +46,10 @@ class OcfInternalVolume(Volume):
|
|||||||
return exp_obj_io
|
return exp_obj_io
|
||||||
|
|
||||||
def get_length(self):
|
def get_length(self):
|
||||||
return Size.from_B(OcfLib.getInstance().ocf_volume_get_length(self.handle))
|
return Size.from_B(lib.ocf_volume_get_length(self.handle))
|
||||||
|
|
||||||
def get_max_io_size(self):
|
def get_max_io_size(self):
|
||||||
return Size.from_B(OcfLib.getInstance().ocf_volume_get_max_io_size(self.handle))
|
return Size.from_B(lib.ocf_volume_get_max_io_size(self.handle))
|
||||||
|
|
||||||
def do_submit_io(self, io):
|
def do_submit_io(self, io):
|
||||||
io = self._alloc_io(io)
|
io = self._alloc_io(io)
|
||||||
@ -65,9 +64,12 @@ class OcfInternalVolume(Volume):
|
|||||||
io.submit_discard()
|
io.submit_discard()
|
||||||
|
|
||||||
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
def do_forward_io(self, token, rw, addr, nbytes, offset):
|
||||||
orig_io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
cdata = OcfLib.getInstance().ocf_forward_get_data(token)
|
io_class = lib.ocf_forward_get_io_class(token)
|
||||||
io = self._alloc_io(orig_io, cdata, rw, addr, nbytes, offset)
|
cdata = lib.ocf_forward_get_data(token)
|
||||||
|
|
||||||
|
io = self.__alloc_io(addr, nbytes, rw, io_class, flags)
|
||||||
|
lib.ocf_io_set_data(byref(io), cdata, offset)
|
||||||
|
|
||||||
def cb(error):
|
def cb(error):
|
||||||
nonlocal io
|
nonlocal io
|
||||||
@ -79,17 +81,37 @@ class OcfInternalVolume(Volume):
|
|||||||
io.submit()
|
io.submit()
|
||||||
|
|
||||||
def do_forward_flush(self, token):
|
def do_forward_flush(self, token):
|
||||||
orig_io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
cdata = OcfLib.getInstance().ocf_forward_get_data(token)
|
io_class = lib.ocf_forward_get_io_class(token)
|
||||||
io = self._alloc_io(orig_io, cdata)
|
|
||||||
|
io = self.__alloc_io(0, 0, 0, io_class, flags)
|
||||||
|
|
||||||
|
def cb(error):
|
||||||
|
nonlocal io
|
||||||
|
Io.forward_end(io.token, error)
|
||||||
|
|
||||||
|
io.token = token
|
||||||
|
io.callback = cb
|
||||||
|
|
||||||
io.submit_flush()
|
io.submit_flush()
|
||||||
|
|
||||||
|
|
||||||
def do_forward_discard(self, token, addr, nbytes):
|
def do_forward_discard(self, token, addr, nbytes):
|
||||||
orig_io = Io.get_by_forward_token(token)
|
flags = lib.ocf_forward_get_flags(token)
|
||||||
cdata = OcfLib.getInstance().ocf_forward_get_data(token)
|
io_class = lib.ocf_forward_get_io_class(token)
|
||||||
io = self._alloc_io(orig_io, cdata, addr=addr, nbytes=nbytes)
|
|
||||||
|
io = self.__alloc_io(addr, nbytes, 0, io_class, flags)
|
||||||
|
|
||||||
|
def cb(error):
|
||||||
|
nonlocal io
|
||||||
|
Io.forward_end(io.token, error)
|
||||||
|
|
||||||
|
io.token = token
|
||||||
|
io.callback = cb
|
||||||
|
|
||||||
io.submit_discard()
|
io.submit_discard()
|
||||||
|
|
||||||
|
|
||||||
def _read(self, offset=0, size=0):
|
def _read(self, offset=0, size=0):
|
||||||
if size == 0:
|
if size == 0:
|
||||||
size = self.get_length().B - offset
|
size = self.get_length().B - offset
|
||||||
@ -166,3 +188,7 @@ lib.ocf_io_get_data.argtypes = [POINTER(Io)]
|
|||||||
lib.ocf_io_get_data.restype = c_void_p
|
lib.ocf_io_get_data.restype = c_void_p
|
||||||
lib.ocf_forward_get_data.argtypes = [c_uint64]
|
lib.ocf_forward_get_data.argtypes = [c_uint64]
|
||||||
lib.ocf_forward_get_data.restype = c_void_p
|
lib.ocf_forward_get_data.restype = c_void_p
|
||||||
|
lib.ocf_forward_get_flags.argtypes = [c_uint64]
|
||||||
|
lib.ocf_forward_get_flags.restype = c_uint64
|
||||||
|
lib.ocf_forward_get_io_class.argtypes = [c_uint64]
|
||||||
|
lib.ocf_forward_get_io_class.restype = c_uint8
|
||||||
|
Loading…
Reference in New Issue
Block a user