pyocf: refactor sync io operations
Replace the pattern: completion = OcfCompletion([("err", c_int)]) io.callback = completion.callback io.submit() completion.wait() with: completion = Sync(io).submit() Also, remove some redundant imports. Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
8d4661bdc9
commit
9f0147ab1e
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ from enum import IntEnum
|
|||||||
|
|
||||||
from ..ocf import OcfLib
|
from ..ocf import OcfLib
|
||||||
from .data import Data
|
from .data import Data
|
||||||
|
from .shared import OcfCompletion
|
||||||
|
|
||||||
|
|
||||||
class IoDir(IntEnum):
|
class IoDir(IntEnum):
|
||||||
@ -113,6 +115,29 @@ class Io(Structure):
|
|||||||
OcfLib.getInstance().ocf_io_set_data(byref(self), data, offset)
|
OcfLib.getInstance().ocf_io_set_data(byref(self), data, offset)
|
||||||
|
|
||||||
|
|
||||||
|
class Sync:
|
||||||
|
def __init__(self, io: Io) -> None:
|
||||||
|
self.io = io
|
||||||
|
|
||||||
|
def sync_submit(self, submit_method):
|
||||||
|
if getattr(self.io, 'callback', None):
|
||||||
|
raise Exception("completion callback is already set")
|
||||||
|
cmpl = OcfCompletion([("err", c_int)])
|
||||||
|
self.io.callback = cmpl.callback
|
||||||
|
submit_method()
|
||||||
|
cmpl.wait()
|
||||||
|
return cmpl
|
||||||
|
|
||||||
|
def submit(self):
|
||||||
|
return self.sync_submit(self.io.submit)
|
||||||
|
|
||||||
|
def submit_flush(self):
|
||||||
|
return self.sync_submit(self.io.submit_flush)
|
||||||
|
|
||||||
|
def submit_discard(self):
|
||||||
|
return self.sync_submit(self.io.submit_discard)
|
||||||
|
|
||||||
|
|
||||||
IoOps.SET_DATA = CFUNCTYPE(c_int, POINTER(Io), c_void_p, c_uint32)
|
IoOps.SET_DATA = CFUNCTYPE(c_int, POINTER(Io), c_void_p, c_uint32)
|
||||||
IoOps.GET_DATA = CFUNCTYPE(c_void_p, POINTER(Io))
|
IoOps.GET_DATA = CFUNCTYPE(c_void_p, POINTER(Io))
|
||||||
|
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from ctypes import c_int
|
|
||||||
|
|
||||||
from pyocf.types.cache import Cache
|
from pyocf.types.cache import Cache
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.volume import RamVolume, ErrorDevice
|
from pyocf.types.volume import RamVolume, ErrorDevice
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.utils import Size as S
|
from pyocf.utils import Size as S
|
||||||
from pyocf.types.shared import OcfError, OcfCompletion
|
from pyocf.types.shared import OcfError
|
||||||
from pyocf.rio import Rio, ReadWrite
|
from pyocf.rio import Rio, ReadWrite
|
||||||
|
|
||||||
|
|
||||||
@ -100,10 +100,7 @@ def test_load_cache_with_cores(pyocf_ctx, open_cores):
|
|||||||
)
|
)
|
||||||
io.set_data(write_data)
|
io.set_data(write_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
cache.stop()
|
cache.stop()
|
||||||
@ -121,10 +118,7 @@ def test_load_cache_with_cores(pyocf_ctx, open_cores):
|
|||||||
io = vol.new_io(cache.get_default_queue(), S.from_sector(3).B, read_data.size, IoDir.READ, 0, 0)
|
io = vol.new_io(cache.get_default_queue(), S.from_sector(3).B, read_data.size, IoDir.READ, 0, 0)
|
||||||
io.set_data(read_data)
|
io.set_data(read_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert read_data.md5() == write_data.md5()
|
assert read_data.md5() == write_data.md5()
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022-2022 Intel Corporation
|
# Copyright(c) 2022-2022 Intel Corporation
|
||||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
from ctypes import c_int
|
|
||||||
|
|
||||||
from pyocf.types.cache import Cache
|
from pyocf.types.cache import Cache
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.volume import RamVolume, IoFlags, TraceDevice
|
from pyocf.types.volume import RamVolume, IoFlags, TraceDevice
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.types.shared import OcfCompletion
|
|
||||||
|
|
||||||
|
|
||||||
def test_flush_propagation(pyocf_ctx):
|
def test_flush_propagation(pyocf_ctx):
|
||||||
@ -46,13 +45,10 @@ def test_flush_propagation(pyocf_ctx):
|
|||||||
|
|
||||||
vol.open()
|
vol.open()
|
||||||
io = vol.new_io(queue, addr, size, IoDir.WRITE, 0, IoFlags.FLUSH)
|
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)
|
data = Data(byte_count=0)
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
|
|
||||||
io.submit_flush()
|
completion = Sync(io).submit_flush()
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert int(completion.results["err"]) == 0
|
assert int(completion.results["err"]) == 0
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2020-2022 Intel Corporation
|
# Copyright(c) 2020-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -15,17 +16,13 @@ from pyocf.types.core import Core
|
|||||||
from pyocf.types.volume import RamVolume
|
from pyocf.types.volume import RamVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.types.shared import OcfCompletion
|
|
||||||
|
|
||||||
|
|
||||||
def __io(io, queue, address, size, data, direction):
|
def __io(io, data):
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
return int(completion.results["err"])
|
return int(completion.results["err"])
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +34,7 @@ def io_to_exp_obj(vol, address, size, data, offset, direction, flags):
|
|||||||
_data = Data.from_bytes(bytes(size))
|
_data = Data.from_bytes(bytes(size))
|
||||||
else:
|
else:
|
||||||
_data = Data.from_bytes(data, offset, size)
|
_data = Data.from_bytes(data, offset, size)
|
||||||
ret = __io(io, queue, address, size, _data, direction)
|
ret = __io(io, _data)
|
||||||
if not ret and direction == IoDir.READ:
|
if not ret and direction == IoDir.READ:
|
||||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||||
vol.close()
|
vol.close()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022 Intel Corporation
|
# Copyright(c) 2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -8,11 +9,10 @@ from ctypes import c_int
|
|||||||
from pyocf.types.cache import Cache
|
from pyocf.types.cache import Cache
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.volume import RamVolume, IoFlags
|
from pyocf.types.volume import RamVolume, IoFlags
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.types.shared import OcfCompletion
|
|
||||||
|
|
||||||
|
|
||||||
def test_large_flush(pyocf_ctx):
|
def test_large_flush(pyocf_ctx):
|
||||||
@ -28,12 +28,9 @@ def test_large_flush(pyocf_ctx):
|
|||||||
vol.open()
|
vol.open()
|
||||||
|
|
||||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, IoFlags.FLUSH)
|
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)
|
data = Data(byte_count=0)
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
io.submit_flush()
|
completion = Sync(io).submit_flush()
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert int(completion.results["err"]) == 0
|
assert int(completion.results["err"]) == 0
|
||||||
@ -54,12 +51,9 @@ def test_large_discard(pyocf_ctx):
|
|||||||
vol.open()
|
vol.open()
|
||||||
|
|
||||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, 0)
|
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)
|
data = Data(byte_count=0)
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
io.submit_discard()
|
completion = Sync(io).submit_discard()
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert int(completion.results["err"]) == 0
|
assert int(completion.results["err"]) == 0
|
||||||
@ -80,12 +74,9 @@ def test_large_io(pyocf_ctx):
|
|||||||
vol.open()
|
vol.open()
|
||||||
|
|
||||||
io = vol.new_io(queue, 0, core_device.size.bytes, IoDir.WRITE, 0, 0)
|
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)
|
data = Data(byte_count=core_device.size.bytes)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
io.submit()
|
completion = Sync(io).submit()
|
||||||
completion.wait()
|
|
||||||
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ from pyocf.types.core import Core
|
|||||||
from pyocf.types.volume import RamVolume
|
from pyocf.types.volume import RamVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.types.shared import OcfCompletion, CacheLineSize
|
from pyocf.types.shared import CacheLineSize
|
||||||
|
|
||||||
|
|
||||||
def get_byte(number, byte):
|
def get_byte(number, byte):
|
||||||
@ -31,12 +31,9 @@ def bytes_to_uint32(byte0, byte1, byte2, byte3):
|
|||||||
return (int(byte3) << 24) + (int(byte2) << 16) + (int(byte1) << 8) + int(byte0)
|
return (int(byte3) << 24) + (int(byte2) << 16) + (int(byte1) << 8) + int(byte0)
|
||||||
|
|
||||||
|
|
||||||
def __io(io, queue, address, size, data, direction):
|
def __io(io, data):
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
return int(completion.results["err"])
|
return int(completion.results["err"])
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +43,7 @@ def io_to_exp_obj(vol, queue, address, size, data, offset, direction):
|
|||||||
_data = Data.from_bytes(bytes(size))
|
_data = Data.from_bytes(bytes(size))
|
||||||
else:
|
else:
|
||||||
_data = Data.from_bytes(data, offset, size)
|
_data = Data.from_bytes(data, offset, size)
|
||||||
ret = __io(io, queue, address, size, _data, direction)
|
ret = __io(io, _data)
|
||||||
if not ret and direction == IoDir.READ:
|
if not ret and direction == IoDir.READ:
|
||||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||||
return ret
|
return ret
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ import pytest
|
|||||||
from pyocf.types.cache import Cache, CacheMode
|
from pyocf.types.cache import Cache, CacheMode
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.shared import OcfCompletion, CacheLineSize, SeqCutOffPolicy, CacheLines
|
from pyocf.types.shared import OcfCompletion, CacheLineSize, SeqCutOffPolicy, CacheLines
|
||||||
from pyocf.types.volume import RamVolume
|
from pyocf.types.volume import RamVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
@ -180,10 +181,7 @@ def send_io(vol: CoreVolume, data: Data, addr: int = 0, target_ioclass: int = 0)
|
|||||||
|
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
|
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert completion.results["err"] == 0, "IO to exported object completion"
|
assert completion.results["err"] == 0, "IO to exported object completion"
|
||||||
|
@ -1,31 +1,23 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2020-2022 Intel Corporation
|
# Copyright(c) 2020-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
from ctypes import c_int, memmove, cast, c_void_p
|
from ctypes import memmove, cast, c_void_p
|
||||||
from enum import IntEnum
|
|
||||||
from itertools import product
|
|
||||||
import random
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from pyocf.types.cache import Cache, CacheMode
|
from pyocf.types.cache import Cache, CacheMode
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.volume import RamVolume
|
from pyocf.types.volume import RamVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.types.shared import OcfCompletion
|
|
||||||
|
|
||||||
|
|
||||||
def __io(io, queue, address, size, data, direction):
|
def __io(io, data):
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
return int(completion.results["err"])
|
return int(completion.results["err"])
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +28,7 @@ def io_to_exp_obj(vol, queue, address, size, data, offset, direction, flags):
|
|||||||
_data = Data.from_bytes(bytes(size))
|
_data = Data.from_bytes(bytes(size))
|
||||||
else:
|
else:
|
||||||
_data = Data.from_bytes(data, offset, size)
|
_data = Data.from_bytes(data, offset, size)
|
||||||
ret = __io(io, queue, address, size, _data, direction)
|
ret = __io(io, _data)
|
||||||
if not ret and direction == IoDir.READ:
|
if not ret and direction == IoDir.READ:
|
||||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||||
vol.close()
|
vol.close()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ from pyocf.types.core import Core
|
|||||||
from pyocf.types.volume import RamVolume, Volume
|
from pyocf.types.volume import RamVolume, Volume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.queue import Queue
|
from pyocf.types.queue import Queue
|
||||||
from pyocf.utils import Size as S
|
from pyocf.utils import Size as S
|
||||||
from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize
|
from pyocf.types.shared import OcfError, OcfCompletion, CacheLineSize
|
||||||
@ -132,10 +133,7 @@ def test_10add_remove_with_io(pyocf_ctx):
|
|||||||
)
|
)
|
||||||
io.set_data(write_data)
|
io.set_data(write_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
cache.remove_core(core)
|
cache.remove_core(core)
|
||||||
@ -305,10 +303,7 @@ def _io_to_core(vol: Volume, queue: Queue, data: Data):
|
|||||||
io = vol.new_io(queue, 0, data.size, IoDir.WRITE, 0, 0)
|
io = vol.new_io(queue, 0, data.size, IoDir.WRITE, 0, 0)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
|
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
|
|
||||||
vol.close()
|
vol.close()
|
||||||
assert completion.results["err"] == 0, "IO to exported object completion"
|
assert completion.results["err"] == 0, "IO to exported object completion"
|
||||||
|
@ -11,19 +11,14 @@ from itertools import count
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyocf.ocf import OcfLib
|
|
||||||
from pyocf.types.cache import (
|
from pyocf.types.cache import (
|
||||||
Cache,
|
Cache,
|
||||||
CacheMode,
|
CacheMode,
|
||||||
MetadataLayout,
|
|
||||||
CleaningPolicy,
|
|
||||||
)
|
)
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.shared import (
|
from pyocf.types.shared import (
|
||||||
OcfError,
|
|
||||||
OcfCompletion,
|
|
||||||
CacheLines,
|
CacheLines,
|
||||||
CacheLineSize,
|
CacheLineSize,
|
||||||
SeqCutOffPolicy,
|
SeqCutOffPolicy,
|
||||||
@ -129,17 +124,14 @@ def io_to_exp_obj(vol, queue, address, size, data, offset, direction, target_ioc
|
|||||||
_data = Data.from_bytes(bytes(size))
|
_data = Data.from_bytes(bytes(size))
|
||||||
else:
|
else:
|
||||||
_data = Data.from_bytes(data, offset, size)
|
_data = Data.from_bytes(data, offset, size)
|
||||||
ret = __io(io, queue, address, size, _data, direction)
|
ret = __io(io, _data)
|
||||||
if not ret and direction == IoDir.READ:
|
if not ret and direction == IoDir.READ:
|
||||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||||
vol.close()
|
vol.close()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def __io(io, queue, address, size, data, direction):
|
def __io(io, data):
|
||||||
io.set_data(data, 0)
|
io.set_data(data, 0)
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
return int(completion.results["err"])
|
return int(completion.results["err"])
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022 Intel Corporation
|
# Copyright(c) 2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -7,10 +8,9 @@ import pytest
|
|||||||
from pyocf.types.volume import RamVolume
|
from pyocf.types.volume import RamVolume
|
||||||
from pyocf.types.cache import Cache, CacheMetadataSegment, CleaningPolicy
|
from pyocf.types.cache import Cache, CacheMetadataSegment, CleaningPolicy
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.shared import OcfError, OcfCompletion
|
from pyocf.types.shared import OcfError
|
||||||
from pyocf.utils import Size as S
|
from pyocf.utils import Size as S
|
||||||
from pyocf.helpers import get_metadata_segment_size
|
from pyocf.helpers import get_metadata_segment_size
|
||||||
from ctypes import c_int
|
|
||||||
|
|
||||||
def test_attach_cleaner_disabled(pyocf_ctx):
|
def test_attach_cleaner_disabled(pyocf_ctx):
|
||||||
"""
|
"""
|
||||||
|
@ -1,21 +1,18 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2022-2022 Intel Corporation
|
# Copyright(c) 2022-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import copy
|
|
||||||
from ctypes import c_int
|
|
||||||
|
|
||||||
from pyocf.types.cache import (
|
from pyocf.types.cache import (
|
||||||
Cache,
|
Cache,
|
||||||
CacheMode,
|
CacheMode,
|
||||||
MetadataLayout,
|
|
||||||
CleaningPolicy,
|
|
||||||
)
|
)
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import Io, IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.volume import RamVolume, Volume
|
from pyocf.types.volume import RamVolume, Volume
|
||||||
from pyocf.types.volume_cache import CacheVolume
|
from pyocf.types.volume_cache import CacheVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
@ -23,10 +20,7 @@ from pyocf.types.volume_replicated import ReplicatedVolume
|
|||||||
from pyocf.types.shared import (
|
from pyocf.types.shared import (
|
||||||
OcfError,
|
OcfError,
|
||||||
OcfErrorCode,
|
OcfErrorCode,
|
||||||
OcfCompletion,
|
|
||||||
CacheLines,
|
|
||||||
CacheLineSize,
|
CacheLineSize,
|
||||||
SeqCutOffPolicy,
|
|
||||||
)
|
)
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
from pyocf.rio import Rio, ReadWrite
|
from pyocf.rio import Rio, ReadWrite
|
||||||
@ -377,12 +371,9 @@ def write_vol(vol, queue, data):
|
|||||||
for offset in range(0, data_size, subdata_size_max):
|
for offset in range(0, data_size, subdata_size_max):
|
||||||
subdata_size = min(data_size - offset, subdata_size_max)
|
subdata_size = min(data_size - offset, subdata_size_max)
|
||||||
subdata = Data.from_bytes(data, offset, subdata_size)
|
subdata = Data.from_bytes(data, offset, subdata_size)
|
||||||
comp = OcfCompletion([("error", c_int)])
|
|
||||||
io = vol.new_io(queue, offset, subdata_size, IoDir.WRITE, 0, 0,)
|
io = vol.new_io(queue, offset, subdata_size, IoDir.WRITE, 0, 0,)
|
||||||
io.set_data(subdata)
|
io.set_data(subdata)
|
||||||
io.callback = comp.callback
|
Sync(io).submit()
|
||||||
io.submit()
|
|
||||||
comp.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -25,15 +26,13 @@ from pyocf.types.cache import (
|
|||||||
MetadataLayout,
|
MetadataLayout,
|
||||||
CleaningPolicy,
|
CleaningPolicy,
|
||||||
CacheConfig,
|
CacheConfig,
|
||||||
PromotionPolicy,
|
|
||||||
Backfill,
|
|
||||||
CacheDeviceConfig,
|
CacheDeviceConfig,
|
||||||
CacheAttachConfig,
|
CacheAttachConfig,
|
||||||
)
|
)
|
||||||
from pyocf.types.core import Core
|
from pyocf.types.core import Core
|
||||||
from pyocf.types.ctx import OcfCtx
|
from pyocf.types.ctx import OcfCtx
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.queue import Queue
|
from pyocf.types.queue import Queue
|
||||||
from pyocf.types.shared import (
|
from pyocf.types.shared import (
|
||||||
Uuid,
|
Uuid,
|
||||||
@ -520,10 +519,7 @@ def io_to_core(vol: Volume, queue: Queue, data: Data, offset: int):
|
|||||||
io = vol.new_io(queue, offset, data.size, IoDir.WRITE, 0, 0)
|
io = vol.new_io(queue, offset, data.size, IoDir.WRITE, 0, 0)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
|
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
|
|
||||||
vol.close()
|
vol.close()
|
||||||
assert completion.results["err"] == 0, "IO to exported object completion"
|
assert completion.results["err"] == 0, "IO to exported object completion"
|
||||||
@ -535,10 +531,7 @@ def io_from_exported_object(vol: Volume, queue: Queue, buffer_size: int, offset:
|
|||||||
io = vol.new_io(queue, offset, read_buffer.size, IoDir.READ, 0, 0)
|
io = vol.new_io(queue, offset, read_buffer.size, IoDir.READ, 0, 0)
|
||||||
io.set_data(read_buffer)
|
io.set_data(read_buffer)
|
||||||
|
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
assert completion.results["err"] == 0, "IO from exported object completion"
|
assert completion.results["err"] == 0, "IO from exported object completion"
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
from ctypes import c_int
|
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pyocf.types.cache import Cache, Core
|
from pyocf.types.cache import Cache, Core
|
||||||
from pyocf.types.data import Data
|
from pyocf.types.data import Data
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.queue import Queue
|
from pyocf.types.queue import Queue
|
||||||
from pyocf.types.shared import OcfCompletion
|
|
||||||
from pyocf.types.volume import Volume, RamVolume
|
from pyocf.types.volume import Volume, RamVolume
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.utils import Size
|
from pyocf.utils import Size
|
||||||
@ -204,9 +203,6 @@ def io_operation(
|
|||||||
io = vol.new_io(queue, offset, data.size, io_direction, io_class, 0)
|
io = vol.new_io(queue, offset, data.size, io_direction, io_class, 0)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
|
|
||||||
completion = OcfCompletion([("err", c_int)])
|
completion = Sync(io).submit()
|
||||||
io.callback = completion.callback
|
|
||||||
io.submit()
|
|
||||||
completion.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
return completion
|
return completion
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright(c) 2019-2022 Intel Corporation
|
# Copyright(c) 2019-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ from pyocf.types.ctx import OcfCtx
|
|||||||
from pyocf.types.logger import DefaultLogger, LogLevel
|
from pyocf.types.logger import DefaultLogger, LogLevel
|
||||||
from pyocf.ocf import OcfLib
|
from pyocf.ocf import OcfLib
|
||||||
from pyocf.types.cleaner import Cleaner
|
from pyocf.types.cleaner import Cleaner
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.shared import OcfCompletion
|
from pyocf.types.shared import OcfCompletion
|
||||||
|
|
||||||
|
|
||||||
@ -90,10 +91,7 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
|||||||
io = vol.new_io(queue, S.from_sector(1).B, write_data.size, IoDir.WRITE, 0, 0,)
|
io = vol.new_io(queue, S.from_sector(1).B, write_data.size, IoDir.WRITE, 0, 0,)
|
||||||
io.set_data(write_data)
|
io.set_data(write_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
|
|
||||||
cmpls = []
|
cmpls = []
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
@ -113,10 +111,7 @@ def test_secure_erase_simple_io_read_misses(cache_mode):
|
|||||||
io = vol.new_io(queue, S.from_sector(1), write_data.size, IoDir.WRITE, 0, 0)
|
io = vol.new_io(queue, S.from_sector(1), write_data.size, IoDir.WRITE, 0, 0)
|
||||||
io.set_data(write_data)
|
io.set_data(write_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
|
|
||||||
vol.close()
|
vol.close()
|
||||||
stats = cache.get_stats()
|
stats = cache.get_stats()
|
||||||
@ -167,19 +162,13 @@ def test_secure_erase_simple_io_cleaning():
|
|||||||
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.WRITE, 0, 0)
|
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.WRITE, 0, 0)
|
||||||
io.set_data(read_data)
|
io.set_data(read_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
|
|
||||||
read_data = Data(S.from_sector(8).B)
|
read_data = Data(S.from_sector(8).B)
|
||||||
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.READ, 0, 0)
|
io = vol.new_io(queue, S.from_sector(1).B, read_data.size, IoDir.READ, 0, 0)
|
||||||
io.set_data(read_data)
|
io.set_data(read_data)
|
||||||
|
|
||||||
cmpl = OcfCompletion([("err", c_int)])
|
Sync(io).submit()
|
||||||
io.callback = cmpl.callback
|
|
||||||
io.submit()
|
|
||||||
cmpl.wait()
|
|
||||||
|
|
||||||
vol.close()
|
vol.close()
|
||||||
stats = cache.get_stats()
|
stats = cache.get_stats()
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
#
|
||||||
# Copyright(c) 2021-2022 Intel Corporation
|
# Copyright(c) 2021-2022 Intel Corporation
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
#
|
#
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from ctypes import c_int, c_void_p, byref, cast, POINTER
|
from ctypes import byref
|
||||||
|
|
||||||
from pyocf.types.cache import (
|
from pyocf.types.cache import (
|
||||||
Cache,
|
Cache,
|
||||||
@ -22,15 +24,12 @@ from pyocf.types.core import Core
|
|||||||
from pyocf.types.volume import ErrorDevice, RamVolume, VOLUME_POISON
|
from pyocf.types.volume import ErrorDevice, RamVolume, VOLUME_POISON
|
||||||
from pyocf.types.volume_core import CoreVolume
|
from pyocf.types.volume_core import CoreVolume
|
||||||
from pyocf.types.volume_cache import CacheVolume
|
from pyocf.types.volume_cache import CacheVolume
|
||||||
from pyocf.types.io import IoDir
|
from pyocf.types.io import IoDir, Sync
|
||||||
from pyocf.types.ioclass import IoClassesInfo, IoClassInfo
|
from pyocf.types.ioclass import IoClassesInfo
|
||||||
from pyocf.utils import Size as S
|
from pyocf.utils import Size as S
|
||||||
from pyocf.types.shared import (
|
from pyocf.types.shared import (
|
||||||
OcfCompletion,
|
|
||||||
CacheLineSize,
|
|
||||||
OcfError,
|
OcfError,
|
||||||
OcfErrorCode,
|
OcfErrorCode,
|
||||||
Uuid,
|
|
||||||
)
|
)
|
||||||
from pyocf.ocf import OcfLib
|
from pyocf.ocf import OcfLib
|
||||||
|
|
||||||
@ -41,24 +40,18 @@ mngmt_op_surprise_shutdown_test_io_offset = S.from_MiB(4).B
|
|||||||
def ocf_write(vol, queue, val, offset):
|
def ocf_write(vol, queue, val, offset):
|
||||||
vol.open()
|
vol.open()
|
||||||
data = Data.from_bytes(bytes([val] * 512))
|
data = Data.from_bytes(bytes([val] * 512))
|
||||||
comp = OcfCompletion([("error", c_int)])
|
|
||||||
io = vol.new_io(queue, offset, 512, IoDir.WRITE, 0, 0)
|
io = vol.new_io(queue, offset, 512, IoDir.WRITE, 0, 0)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
io.callback = comp.callback
|
Sync(io).submit()
|
||||||
io.submit()
|
|
||||||
comp.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
|
|
||||||
|
|
||||||
def ocf_read(vol, queue, offset):
|
def ocf_read(vol, queue, offset):
|
||||||
vol.open()
|
vol.open()
|
||||||
data = Data(byte_count=512)
|
data = Data(byte_count=512)
|
||||||
comp = OcfCompletion([("error", c_int)])
|
|
||||||
io = vol.new_io(queue, offset, 512, IoDir.READ, 0, 0)
|
io = vol.new_io(queue, offset, 512, IoDir.READ, 0, 0)
|
||||||
io.set_data(data)
|
io.set_data(data)
|
||||||
io.callback = comp.callback
|
Sync(io).submit()
|
||||||
io.submit()
|
|
||||||
comp.wait()
|
|
||||||
vol.close()
|
vol.close()
|
||||||
return data.get_bytes()[0]
|
return data.get_bytes()[0]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user