Merge pull request #804 from mmichal10/pytest-fixes
(Mostly) pyocf fixes
This commit is contained in:
commit
421d3f03ea
@ -54,10 +54,10 @@ static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
|
||||
int result;
|
||||
|
||||
if (!uuid->data)
|
||||
return -EINVAL;
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
if (uuid->size > sizeof(muuid->data))
|
||||
return -ENOBUFS;
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
result = env_memcpy(muuid->data, sizeof(muuid->data),
|
||||
uuid->data, uuid->size);
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* Copyright(c) 2024 Huawei Technologies
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@ -25,19 +26,19 @@ int ocf_ctx_register_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id,
|
||||
int result = 0;
|
||||
|
||||
if (!ctx || !properties)
|
||||
return -EINVAL;
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
env_rmutex_lock(&ctx->lock);
|
||||
|
||||
if (type_id >= OCF_VOLUME_TYPE_MAX || ctx->volume_type[type_id]) {
|
||||
env_rmutex_unlock(&ctx->lock);
|
||||
result = -EINVAL;
|
||||
result = -OCF_ERR_INVAL;
|
||||
goto err;
|
||||
}
|
||||
|
||||
ocf_volume_type_init(&ctx->volume_type[type_id], properties, extended);
|
||||
if (!ctx->volume_type[type_id])
|
||||
result = -EINVAL;
|
||||
result = -OCF_ERR_INVAL;
|
||||
|
||||
env_rmutex_unlock(&ctx->lock);
|
||||
|
||||
@ -58,7 +59,7 @@ int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id,
|
||||
const struct ocf_volume_properties *properties)
|
||||
{
|
||||
if (type_id >= OCF_VOLUME_TYPE_MAX_USER)
|
||||
return -EINVAL;
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
return ocf_ctx_register_volume_type_internal(ctx, type_id,
|
||||
properties, NULL);
|
||||
@ -150,7 +151,7 @@ int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume,
|
||||
|
||||
volume_type = ocf_ctx_get_volume_type(ctx, type_id);
|
||||
if (!volume_type)
|
||||
return -EINVAL;
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
return ocf_volume_create(volume, volume_type, uuid);
|
||||
}
|
||||
@ -188,7 +189,7 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
|
||||
|
||||
ocf_ctx = env_zalloc(sizeof(*ocf_ctx), ENV_MEM_NORMAL);
|
||||
if (!ocf_ctx)
|
||||
return -ENOMEM;
|
||||
return -OCF_ERR_NO_MEM;
|
||||
|
||||
INIT_LIST_HEAD(&ocf_ctx->caches);
|
||||
env_atomic_set(&ocf_ctx->ref_count, 1);
|
||||
|
@ -1,16 +1,17 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
from ctypes import c_int, c_void_p, CFUNCTYPE
|
||||
from enum import Enum, auto
|
||||
from random import Random
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import timedelta, datetime
|
||||
from itertools import cycle
|
||||
from threading import Thread, Condition, Event
|
||||
from copy import deepcopy
|
||||
import copy
|
||||
|
||||
from pyocf.utils import Size
|
||||
from pyocf.types.volume import Volume
|
||||
@ -61,12 +62,12 @@ class JobSpec:
|
||||
randseed: int = 1
|
||||
rwmixwrite: int = 50
|
||||
randommap: bool = True
|
||||
bs: Size = Size.from_B(512)
|
||||
offset: Size = Size(0)
|
||||
bs: Size = field(default_factory=lambda: Size.from_B(512))
|
||||
offset: Size = field(default_factory=lambda: Size(0))
|
||||
njobs: int = 1
|
||||
qd: int = 1
|
||||
size: Size = Size(0)
|
||||
io_size: Size = Size(0)
|
||||
size: Size = field(default_factory=lambda: Size(0))
|
||||
io_size: Size = field(default_factory=lambda: Size(0))
|
||||
target: Volume = None
|
||||
time_based: bool = False
|
||||
time: timedelta = None
|
||||
@ -124,7 +125,7 @@ class Rio:
|
||||
|
||||
def run(self):
|
||||
iogen = IoGen(
|
||||
(self.jobspec.offset, self.jobspec.size - self.jobspec.offset),
|
||||
(self.jobspec.offset, self.jobspec.size),
|
||||
self.jobspec.bs,
|
||||
self.jobspec.randseed + hash(self.name),
|
||||
self.jobspec.readwrite.is_random(),
|
||||
@ -135,11 +136,9 @@ class Rio:
|
||||
self.finish_time = datetime.now() + self.jobspec.time
|
||||
else:
|
||||
if int(self.jobspec.io_size) != 0:
|
||||
self.io_target = min(
|
||||
self.jobspec.io_size, self.jobspec.size - self.jobspec.offset
|
||||
)
|
||||
self.io_target = min(self.jobspec.io_size, self.jobspec.size)
|
||||
else:
|
||||
self.io_target = self.jobspec.size - self.jobspec.offset
|
||||
self.io_target = self.jobspec.size
|
||||
|
||||
# TODO randrw
|
||||
iodir = (
|
||||
@ -174,6 +173,11 @@ class Rio:
|
||||
self.errors = {}
|
||||
self.error_count = 0
|
||||
|
||||
def copy(self):
|
||||
r = copy.copy(self)
|
||||
r.global_jobspec = copy.copy(self.global_jobspec)
|
||||
return r
|
||||
|
||||
def readwrite(self, rw: ReadWrite):
|
||||
self.global_jobspec.readwrite = rw
|
||||
return self
|
||||
@ -270,7 +274,7 @@ class Rio:
|
||||
def run_async(self, queues):
|
||||
self.clear()
|
||||
|
||||
jobs = deepcopy(self.jobs)
|
||||
jobs = copy.deepcopy(self.jobs)
|
||||
|
||||
if not jobs:
|
||||
jobs = [self.global_jobspec for _ in range(self.global_jobspec.njobs)]
|
||||
|
@ -296,7 +296,7 @@ class Cache:
|
||||
|
||||
def standby_detach(self):
|
||||
self.write_lock()
|
||||
c = OcfCompletion([("cache", c_void_p), ("priv", c_void_p), ("error", c_int)])
|
||||
c = OcfCompletion([("priv", c_void_p), ("error", c_int)])
|
||||
self.owner.lib.ocf_mngt_cache_standby_detach(self, c, None)
|
||||
c.wait()
|
||||
self.write_unlock()
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -18,6 +19,7 @@ from enum import IntEnum
|
||||
|
||||
from ..ocf import OcfLib
|
||||
from .data import Data
|
||||
from .shared import OcfCompletion
|
||||
|
||||
|
||||
class IoDir(IntEnum):
|
||||
@ -113,6 +115,29 @@ class Io(Structure):
|
||||
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.GET_DATA = CFUNCTYPE(c_void_p, POINTER(Io))
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import pytest
|
||||
from ctypes import c_int
|
||||
|
||||
from pyocf.types.cache import Cache
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.volume import RamVolume, ErrorDevice
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
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.types.shared import OcfError, OcfCompletion
|
||||
from pyocf.types.shared import OcfError
|
||||
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)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
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.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
assert read_data.md5() == write_data.md5()
|
||||
|
123
tests/functional/tests/engine/test_discard.py
Normal file
123
tests/functional/tests/engine/test_discard.py
Normal file
@ -0,0 +1,123 @@
|
||||
#
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import pytest
|
||||
|
||||
from pyocf.types.cache import Cache, CacheMode, CacheLineSize
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.io import IoDir, Sync
|
||||
from pyocf.types.volume import RamVolume, IoFlags, TraceDevice
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
from math import ceil
|
||||
|
||||
|
||||
def test_discard_propagation(pyocf_ctx):
|
||||
discards = {}
|
||||
|
||||
pyocf_ctx.register_volume_type(TraceDevice)
|
||||
|
||||
def trace_discard(vol, io, io_type):
|
||||
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))
|
||||
|
||||
return True
|
||||
|
||||
cache_device = TraceDevice(RamVolume(Size.from_MiB(50)), trace_fcn=trace_discard)
|
||||
core_device = TraceDevice(RamVolume(Size.from_MiB(100)), trace_fcn=trace_discard)
|
||||
|
||||
cache = Cache.start_on_device(cache_device)
|
||||
core = Core.using_device(core_device)
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
cache.add_core(core)
|
||||
volume = CoreVolume(core)
|
||||
volume.open()
|
||||
|
||||
discards = {}
|
||||
|
||||
addr = Size.from_MiB(2).B
|
||||
size = Size.from_MiB(1).B
|
||||
|
||||
io = volume.new_io(queue, addr, size, IoDir.WRITE, 0, 0)
|
||||
data = Data(byte_count=0)
|
||||
io.set_data(data, 0)
|
||||
|
||||
completion = Sync(io).submit_discard()
|
||||
volume.close()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
||||
assert core_device.uuid in discards
|
||||
|
||||
core_discards = discards[core_device.uuid]
|
||||
|
||||
assert len(core_discards) == 1
|
||||
assert core_discards[0] == (addr, size)
|
||||
|
||||
cache.stop()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||
@pytest.mark.parametrize("discard_addr", [63, 64, 65])
|
||||
@pytest.mark.parametrize("discard_size", [1, 127, 128, 129])
|
||||
def test_discard_invalidation(pyocf_ctx, cls, discard_addr, discard_size):
|
||||
discard_addr = Size.from_KiB(discard_addr)
|
||||
discard_size = Size.from_KiB(discard_size)
|
||||
|
||||
cache_device = RamVolume(Size.from_MiB(50))
|
||||
core_device = RamVolume(Size.from_MiB(100))
|
||||
|
||||
cache = Cache.start_on_device(cache_device, cache_line_size=cls)
|
||||
core = Core.using_device(core_device)
|
||||
queue = cache.get_default_queue()
|
||||
|
||||
cache.add_core(core)
|
||||
volume = CoreVolume(core)
|
||||
volume.open()
|
||||
|
||||
data_size = Size.from_KiB(256)
|
||||
pattern = b"\xff"
|
||||
|
||||
data = Data(data_size)
|
||||
data.write(pattern * int(data_size), data_size)
|
||||
io = volume.new_io(queue, 0, data_size, IoDir.WRITE, 0, 0)
|
||||
io.set_data(data, 0)
|
||||
Sync(io).submit()
|
||||
|
||||
data = Data(byte_count=0)
|
||||
io = volume.new_io(queue, discard_addr, discard_size, IoDir.WRITE, 0, 0)
|
||||
io.set_data(data, 0)
|
||||
Sync(io).submit_discard()
|
||||
|
||||
if discard_size < cls:
|
||||
expect_occupancy = data_size
|
||||
else:
|
||||
begin = Size(ceil(int(discard_addr) / cls) * cls)
|
||||
end = min(Size((int(discard_addr + discard_size) // cls) * cls), data_size)
|
||||
expect_occupancy = data_size - (end - begin)
|
||||
|
||||
assert cache.get_stats()["conf"]["occupancy"] == expect_occupancy
|
||||
|
||||
data = Data(data_size)
|
||||
io = volume.new_io(queue, 0, data_size, IoDir.READ, 0, 0)
|
||||
io.set_data(data, 0)
|
||||
Sync(io).submit()
|
||||
|
||||
size = int(discard_addr)
|
||||
assert bytes(data.buffer[:size]) == pattern * size
|
||||
|
||||
offset = int(discard_addr + discard_size)
|
||||
size = int(data_size) - offset
|
||||
assert bytes(data.buffer[offset:]) == pattern * size
|
||||
|
||||
volume.close()
|
||||
|
||||
cache.stop()
|
@ -1,17 +1,16 @@
|
||||
#
|
||||
# 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.data import Data
|
||||
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_core import CoreVolume
|
||||
from pyocf.utils import Size
|
||||
from pyocf.types.shared import OcfCompletion
|
||||
|
||||
|
||||
def test_flush_propagation(pyocf_ctx):
|
||||
@ -46,13 +45,10 @@ def test_flush_propagation(pyocf_ctx):
|
||||
|
||||
vol.open()
|
||||
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()
|
||||
completion = Sync(io).submit_flush()
|
||||
vol.close()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2020-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# 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_core import CoreVolume
|
||||
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.types.shared import OcfCompletion
|
||||
|
||||
|
||||
def __io(io, queue, address, size, data, direction):
|
||||
def __io(io, data):
|
||||
io.set_data(data, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
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))
|
||||
else:
|
||||
_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:
|
||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||
vol.close()
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -8,11 +9,10 @@ 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.io import IoDir, Sync
|
||||
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):
|
||||
@ -28,12 +28,9 @@ def test_large_flush(pyocf_ctx):
|
||||
vol.open()
|
||||
|
||||
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()
|
||||
completion = Sync(io).submit_flush()
|
||||
vol.close()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
@ -54,12 +51,9 @@ def test_large_discard(pyocf_ctx):
|
||||
vol.open()
|
||||
|
||||
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()
|
||||
completion = Sync(io).submit_discard()
|
||||
vol.close()
|
||||
|
||||
assert int(completion.results["err"]) == 0
|
||||
@ -80,12 +74,9 @@ def test_large_io(pyocf_ctx):
|
||||
vol.open()
|
||||
|
||||
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()
|
||||
completion = Sync(io).submit()
|
||||
|
||||
vol.close()
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -174,7 +175,7 @@ def test_promoted_after_hits_various_thresholds(pyocf_ctx, insertion_threshold,
|
||||
.bs(Size(4096))
|
||||
.offset(last_core_line)
|
||||
.target(vol)
|
||||
.size(Size(4096) + last_core_line)
|
||||
.size(Size(4096))
|
||||
)
|
||||
|
||||
for i in range(insertion_threshold - 1):
|
||||
|
@ -18,9 +18,9 @@ from pyocf.types.core import Core
|
||||
from pyocf.types.volume import RamVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
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.types.shared import OcfCompletion, CacheLineSize
|
||||
from pyocf.types.shared import CacheLineSize
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def __io(io, queue, address, size, data, direction):
|
||||
def __io(io, data):
|
||||
io.set_data(data, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
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))
|
||||
else:
|
||||
_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:
|
||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||
return ret
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -12,7 +13,7 @@ import pytest
|
||||
from pyocf.types.cache import Cache, CacheMode
|
||||
from pyocf.types.core import Core
|
||||
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.volume import RamVolume
|
||||
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)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
assert completion.results["err"] == 0, "IO to exported object completion"
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -81,7 +82,7 @@ def test_test_standby_io_metadata(pyocf_ctx, cacheline_size):
|
||||
.target(cache_vol)
|
||||
.njobs(num_jobs)
|
||||
.readwrite(ReadWrite.RANDWRITE)
|
||||
.size(io_offset + io_size)
|
||||
.size(io_size)
|
||||
.bs(Size.from_KiB(16))
|
||||
.offset(io_offset)
|
||||
.qd(qd)
|
||||
|
@ -1,31 +1,23 @@
|
||||
#
|
||||
# Copyright(c) 2020-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
from ctypes import c_int, memmove, cast, c_void_p
|
||||
from enum import IntEnum
|
||||
from itertools import product
|
||||
import random
|
||||
|
||||
import pytest
|
||||
from ctypes import memmove, cast, c_void_p
|
||||
|
||||
from pyocf.types.cache import Cache, CacheMode
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.volume import RamVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
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.types.shared import OcfCompletion
|
||||
|
||||
|
||||
def __io(io, queue, address, size, data, direction):
|
||||
def __io(io, data):
|
||||
io.set_data(data, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
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))
|
||||
else:
|
||||
_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:
|
||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||
vol.close()
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# 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_core import CoreVolume
|
||||
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.utils import Size as S
|
||||
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)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
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.set_data(data)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
|
||||
vol.close()
|
||||
assert completion.results["err"] == 0, "IO to exported object completion"
|
||||
|
@ -11,19 +11,14 @@ from itertools import count
|
||||
|
||||
import pytest
|
||||
|
||||
from pyocf.ocf import OcfLib
|
||||
from pyocf.types.cache import (
|
||||
Cache,
|
||||
CacheMode,
|
||||
MetadataLayout,
|
||||
CleaningPolicy,
|
||||
)
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.data import Data
|
||||
from pyocf.types.io import IoDir
|
||||
from pyocf.types.io import IoDir, Sync
|
||||
from pyocf.types.shared import (
|
||||
OcfError,
|
||||
OcfCompletion,
|
||||
CacheLines,
|
||||
CacheLineSize,
|
||||
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))
|
||||
else:
|
||||
_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:
|
||||
memmove(cast(data, c_void_p).value + offset, _data.handle, size)
|
||||
vol.close()
|
||||
return ret
|
||||
|
||||
|
||||
def __io(io, queue, address, size, data, direction):
|
||||
def __io(io, data):
|
||||
io.set_data(data, 0)
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
return int(completion.results["err"])
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -471,7 +472,7 @@ def test_io_propagation_multiple_subvolumes(pyocf_ctx, rand_seed):
|
||||
|
||||
# I/O addres range start/end offsets within a subvolume
|
||||
start_offset = S.from_B(random.randint(0, vol_size.B // 512 - 1) * 512)
|
||||
end_offset = S.from_B(random.randint(0, vol_size.B // 512 - 1) * 512)
|
||||
end_offset = S.from_B(random.randint(1, vol_size.B // 512 - 1) * 512)
|
||||
|
||||
size = (vol_size - start_offset) + (subvol_count - 2) * vol_size + end_offset
|
||||
addr = first_idx * vol_size + start_offset
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -7,10 +8,9 @@ import pytest
|
||||
from pyocf.types.volume import RamVolume
|
||||
from pyocf.types.cache import Cache, CacheMetadataSegment, CleaningPolicy
|
||||
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.helpers import get_metadata_segment_size
|
||||
from ctypes import c_int
|
||||
|
||||
def test_attach_cleaner_disabled(pyocf_ctx):
|
||||
"""
|
||||
|
@ -1,21 +1,18 @@
|
||||
#
|
||||
# Copyright(c) 2022-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import pytest
|
||||
import copy
|
||||
from ctypes import c_int
|
||||
|
||||
from pyocf.types.cache import (
|
||||
Cache,
|
||||
CacheMode,
|
||||
MetadataLayout,
|
||||
CleaningPolicy,
|
||||
)
|
||||
from pyocf.types.core import Core
|
||||
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_cache import CacheVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
@ -23,10 +20,7 @@ from pyocf.types.volume_replicated import ReplicatedVolume
|
||||
from pyocf.types.shared import (
|
||||
OcfError,
|
||||
OcfErrorCode,
|
||||
OcfCompletion,
|
||||
CacheLines,
|
||||
CacheLineSize,
|
||||
SeqCutOffPolicy,
|
||||
)
|
||||
from pyocf.utils import Size
|
||||
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):
|
||||
subdata_size = min(data_size - offset, subdata_size_max)
|
||||
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.set_data(subdata)
|
||||
io.callback = comp.callback
|
||||
io.submit()
|
||||
comp.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
@ -25,15 +26,13 @@ from pyocf.types.cache import (
|
||||
MetadataLayout,
|
||||
CleaningPolicy,
|
||||
CacheConfig,
|
||||
PromotionPolicy,
|
||||
Backfill,
|
||||
CacheDeviceConfig,
|
||||
CacheAttachConfig,
|
||||
)
|
||||
from pyocf.types.core import Core
|
||||
from pyocf.types.ctx import OcfCtx
|
||||
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.shared import (
|
||||
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.set_data(data)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
|
||||
vol.close()
|
||||
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.set_data(read_buffer)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
assert completion.results["err"] == 0, "IO from exported object completion"
|
||||
|
@ -1,18 +1,17 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
from ctypes import c_int
|
||||
from random import randrange
|
||||
|
||||
import pytest
|
||||
|
||||
from pyocf.types.cache import Cache, Core
|
||||
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.shared import OcfCompletion
|
||||
from pyocf.types.volume import Volume, RamVolume
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
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.set_data(data)
|
||||
|
||||
completion = OcfCompletion([("err", c_int)])
|
||||
io.callback = completion.callback
|
||||
io.submit()
|
||||
completion.wait()
|
||||
completion = Sync(io).submit()
|
||||
vol.close()
|
||||
return completion
|
||||
|
@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright(c) 2019-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# 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.ocf import OcfLib
|
||||
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
|
||||
|
||||
|
||||
@ -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.set_data(write_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
|
||||
cmpls = []
|
||||
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.set_data(write_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
|
||||
vol.close()
|
||||
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.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
|
||||
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.set_data(read_data)
|
||||
|
||||
cmpl = OcfCompletion([("err", c_int)])
|
||||
io.callback = cmpl.callback
|
||||
io.submit()
|
||||
cmpl.wait()
|
||||
Sync(io).submit()
|
||||
|
||||
vol.close()
|
||||
stats = cache.get_stats()
|
||||
|
@ -1,9 +1,11 @@
|
||||
#
|
||||
# Copyright(c) 2021-2022 Intel Corporation
|
||||
# Copyright(c) 2024 Huawei Technologies
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import pytest
|
||||
from ctypes import c_int, c_void_p, byref, cast, POINTER
|
||||
from ctypes import byref
|
||||
|
||||
from pyocf.types.cache import (
|
||||
Cache,
|
||||
@ -22,15 +24,12 @@ from pyocf.types.core import Core
|
||||
from pyocf.types.volume import ErrorDevice, RamVolume, VOLUME_POISON
|
||||
from pyocf.types.volume_core import CoreVolume
|
||||
from pyocf.types.volume_cache import CacheVolume
|
||||
from pyocf.types.io import IoDir
|
||||
from pyocf.types.ioclass import IoClassesInfo, IoClassInfo
|
||||
from pyocf.types.io import IoDir, Sync
|
||||
from pyocf.types.ioclass import IoClassesInfo
|
||||
from pyocf.utils import Size as S
|
||||
from pyocf.types.shared import (
|
||||
OcfCompletion,
|
||||
CacheLineSize,
|
||||
OcfError,
|
||||
OcfErrorCode,
|
||||
Uuid,
|
||||
)
|
||||
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):
|
||||
vol.open()
|
||||
data = Data.from_bytes(bytes([val] * 512))
|
||||
comp = OcfCompletion([("error", c_int)])
|
||||
io = vol.new_io(queue, offset, 512, IoDir.WRITE, 0, 0)
|
||||
io.set_data(data)
|
||||
io.callback = comp.callback
|
||||
io.submit()
|
||||
comp.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
|
||||
|
||||
def ocf_read(vol, queue, offset):
|
||||
vol.open()
|
||||
data = Data(byte_count=512)
|
||||
comp = OcfCompletion([("error", c_int)])
|
||||
io = vol.new_io(queue, offset, 512, IoDir.READ, 0, 0)
|
||||
io.set_data(data)
|
||||
io.callback = comp.callback
|
||||
io.submit()
|
||||
comp.wait()
|
||||
Sync(io).submit()
|
||||
vol.close()
|
||||
return data.get_bytes()[0]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user