Merge pull request #816 from mmichal10/zero-offset
Support set_data() with offset > 0
This commit is contained in:
commit
b3f5ca1c2f
@ -51,7 +51,7 @@ static int _ocf_discard_core(struct ocf_request *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete);
|
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete);
|
||||||
err = ocf_io_set_data(io, req->data, 0);
|
err = ocf_io_set_data(io, req->data, req->offset);
|
||||||
if (err) {
|
if (err) {
|
||||||
_ocf_discard_core_complete(io, err);
|
_ocf_discard_core_complete(io, err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -438,11 +438,12 @@ static int ocf_core_io_set_data(struct ocf_io *io,
|
|||||||
|
|
||||||
OCF_CHECK_NULL(io);
|
OCF_CHECK_NULL(io);
|
||||||
|
|
||||||
if (!data || offset)
|
if (!data)
|
||||||
return -OCF_ERR_INVAL;
|
return -OCF_ERR_INVAL;
|
||||||
|
|
||||||
req = ocf_io_to_req(io);
|
req = ocf_io_to_req(io);
|
||||||
req->data = data;
|
req->data = data;
|
||||||
|
req->offset = offset;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,9 @@ struct ocf_request {
|
|||||||
uint32_t alloc_core_line_count;
|
uint32_t alloc_core_line_count;
|
||||||
/*! Number of core lines at time of request allocation */
|
/*! Number of core lines at time of request allocation */
|
||||||
|
|
||||||
|
uint32_t offset;
|
||||||
|
/*!< Offset into request data*/
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
/*!< This filed indicates an error for OCF request */
|
/*!< This filed indicates an error for OCF request */
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright(c) 2012-2022 Intel Corporation
|
* Copyright(c) 2012-2022 Intel Corporation
|
||||||
|
* Copyright(c) 2024 Huawei Technologies
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -273,7 +274,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
|||||||
|
|
||||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||||
|
|
||||||
err = ocf_io_set_data(io, req->data, offset);
|
err = ocf_io_set_data(io, req->data, req->offset + offset);
|
||||||
if (err) {
|
if (err) {
|
||||||
ocf_io_put(io);
|
ocf_io_put(io);
|
||||||
callback(req, err);
|
callback(req, err);
|
||||||
@ -322,7 +323,8 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
|||||||
|
|
||||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||||
|
|
||||||
err = ocf_io_set_data(io, req->data, offset + total_bytes);
|
err = ocf_io_set_data(io, req->data,
|
||||||
|
req->offset + offset + total_bytes);
|
||||||
if (err) {
|
if (err) {
|
||||||
ocf_io_put(io);
|
ocf_io_put(io);
|
||||||
/* Finish all IOs which left with ERROR */
|
/* Finish all IOs which left with ERROR */
|
||||||
@ -359,7 +361,7 @@ void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||||
err = ocf_io_set_data(io, req->data, 0);
|
err = ocf_io_set_data(io, req->data, req->offset);
|
||||||
if (err) {
|
if (err) {
|
||||||
ocf_io_put(io);
|
ocf_io_put(io);
|
||||||
callback(req, err);
|
callback(req, err);
|
||||||
|
74
tests/functional/tests/basic/test_offset.py
Normal file
74
tests/functional/tests/basic/test_offset.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#
|
||||||
|
# Copyright(c) 2024 Huawei Technologies
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
#
|
||||||
|
|
||||||
|
from pyocf.types.cache import Cache
|
||||||
|
from pyocf.types.core import Core
|
||||||
|
from pyocf.types.data import Data, DataSeek
|
||||||
|
from pyocf.types.io import IoDir, Sync
|
||||||
|
from pyocf.types.volume import RamVolume
|
||||||
|
from pyocf.types.volume_core import CoreVolume
|
||||||
|
from pyocf.utils import Size
|
||||||
|
|
||||||
|
|
||||||
|
def test_data_with_offset(pyocf_ctx):
|
||||||
|
cache_device = RamVolume(Size.from_MiB(50))
|
||||||
|
core_device = RamVolume(Size.from_MiB(50))
|
||||||
|
|
||||||
|
cache = Cache.start_on_device(cache_device)
|
||||||
|
core = Core.using_device(core_device)
|
||||||
|
queue = cache.get_default_queue()
|
||||||
|
|
||||||
|
cache.add_core(core)
|
||||||
|
core_volume = CoreVolume(core)
|
||||||
|
core_volume.open()
|
||||||
|
|
||||||
|
# Populate core backend volume
|
||||||
|
CL = cache.cache_line_size
|
||||||
|
data_1 = Data(CL)
|
||||||
|
for addr in range(0, CL, Size._SECTOR_SIZE):
|
||||||
|
data_1.seek(DataSeek.BEGIN, addr)
|
||||||
|
data_1.write(b"I\x00\x00\x00\x00", 5)
|
||||||
|
core_device.sync_io(queue, CL * 0, data_1, IoDir.WRITE)
|
||||||
|
core_device.sync_io(queue, CL * 1, data_1, IoDir.WRITE)
|
||||||
|
core_device.sync_io(queue, CL * 2, data_1, IoDir.WRITE)
|
||||||
|
core_device.sync_io(queue, CL * 3, data_1, IoDir.WRITE)
|
||||||
|
|
||||||
|
# write using data with offset
|
||||||
|
B1 = b"12345"
|
||||||
|
B2 = b"67890"
|
||||||
|
data = Data(8192)
|
||||||
|
data.seek(DataSeek.BEGIN, 0)
|
||||||
|
data.write(B1, len(B1))
|
||||||
|
data.seek(DataSeek.BEGIN, 4096)
|
||||||
|
data.write(B2, len(B2))
|
||||||
|
|
||||||
|
address = CL
|
||||||
|
length = CL
|
||||||
|
offset = CL
|
||||||
|
io = core_volume.new_io(queue, address, length, IoDir.WRITE, 0, 0)
|
||||||
|
io.set_data(data, offset)
|
||||||
|
Sync(io).submit()
|
||||||
|
|
||||||
|
s = core_device.read_sync(queue, 0, 2 * CL)
|
||||||
|
for addr in range(0, CL, Size._SECTOR_SIZE):
|
||||||
|
assert chr(s[addr]) == "I", f"addr {addr}"
|
||||||
|
assert s[CL:CL + len(B2)] == B2
|
||||||
|
|
||||||
|
s = core_volume.read_sync(queue, 0, 2 * CL)
|
||||||
|
for addr in range(0, CL, Size._SECTOR_SIZE):
|
||||||
|
assert chr(s[addr]) == "I", f"addr {addr}"
|
||||||
|
assert s[CL:CL + len(B2)] == B2
|
||||||
|
|
||||||
|
# read using data with offset
|
||||||
|
data1 = Data(10000)
|
||||||
|
offset1 = 10
|
||||||
|
io1 = core_volume.new_io(queue, address, length, IoDir.READ, 0, 0)
|
||||||
|
io1.set_data(data1, offset1)
|
||||||
|
Sync(io1).submit()
|
||||||
|
|
||||||
|
s0 = data1.buffer[:offset1]
|
||||||
|
assert s0 == bytes([Data.DATA_POISON] * offset1)
|
||||||
|
s1 = data1.buffer[offset1:(offset1 + len(B2))]
|
||||||
|
assert s1 == B2
|
Loading…
Reference in New Issue
Block a user