Merge pull request #339 from imjfckm/check-max-cache-size
Detect cache devices that would overflow ocf_cacheline_t
This commit is contained in:
commit
89f0e96607
2
env/posix/ocf_env.h
vendored
2
env/posix/ocf_env.h
vendored
@ -180,7 +180,7 @@ static inline void env_secure_free(const void *ptr, size_t size)
|
|||||||
|
|
||||||
static inline uint64_t env_get_free_memory(void)
|
static inline uint64_t env_get_free_memory(void)
|
||||||
{
|
{
|
||||||
return sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
|
return (uint64_t)(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ALLOCATOR */
|
/* ALLOCATOR */
|
||||||
|
@ -912,6 +912,7 @@ static int ocf_metadata_hash_init_variable_size(struct ocf_cache *cache,
|
|||||||
struct ocf_cache_line_settings *settings =
|
struct ocf_cache_line_settings *settings =
|
||||||
(struct ocf_cache_line_settings *)&cache->metadata.settings;
|
(struct ocf_cache_line_settings *)&cache->metadata.settings;
|
||||||
ocf_flush_page_synch_t lock_page, unlock_page;
|
ocf_flush_page_synch_t lock_page, unlock_page;
|
||||||
|
uint64_t device_lines;
|
||||||
|
|
||||||
OCF_DEBUG_TRACE(cache);
|
OCF_DEBUG_TRACE(cache);
|
||||||
|
|
||||||
@ -919,7 +920,16 @@ static int ocf_metadata_hash_init_variable_size(struct ocf_cache *cache,
|
|||||||
|
|
||||||
ctrl = cache->metadata.iface_priv;
|
ctrl = cache->metadata.iface_priv;
|
||||||
|
|
||||||
ctrl->device_lines = device_size / cache_line_size;
|
device_lines = device_size / cache_line_size;
|
||||||
|
if (device_lines >= (ocf_cache_line_t)(-1)){
|
||||||
|
/* TODO: This is just a rough check. Most optimal one would be
|
||||||
|
* located in calculate_metadata_size. */
|
||||||
|
ocf_cache_log(cache, log_err, "Device exceeds maximum suported size "
|
||||||
|
"with this cache line size. Try bigger cache line size.");
|
||||||
|
return -OCF_ERR_INVAL_CACHE_DEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl->device_lines = device_lines;
|
||||||
|
|
||||||
if (settings->size != cache_line_size)
|
if (settings->size != cache_line_size)
|
||||||
/* Re-initialize settings with different cache line size */
|
/* Re-initialize settings with different cache line size */
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from ctypes import c_int, c_void_p, byref
|
from ctypes import c_int, c_void_p, byref, c_uint32
|
||||||
from random import randrange
|
from random import randrange
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
|
||||||
@ -330,6 +330,31 @@ def test_start_cache_same_id(pyocf_ctx, mode, cls):
|
|||||||
cache.get_stats()
|
cache.get_stats()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||||
|
def test_start_cache_huge_device(pyocf_ctx_log_buffer, cls):
|
||||||
|
"""
|
||||||
|
Test whether we can start cache which would overflow ocf_cache_line_t type.
|
||||||
|
pass_criteria:
|
||||||
|
- Starting cache on device too big to handle should fail
|
||||||
|
"""
|
||||||
|
class HugeDevice(Volume):
|
||||||
|
def get_length(self):
|
||||||
|
return Size.from_B((cls * c_uint32(-1).value))
|
||||||
|
|
||||||
|
def submit_io(self, io):
|
||||||
|
io.contents._end(io, 0)
|
||||||
|
|
||||||
|
cache_device = HugeDevice(Size.from_MiB(20))
|
||||||
|
|
||||||
|
with pytest.raises(OcfError, match="OCF_ERR_START_CACHE_FAIL"):
|
||||||
|
cache = Cache.start_on_device(cache_device, cache_line_size=cls, metadata_volatile=True)
|
||||||
|
|
||||||
|
assert any(
|
||||||
|
[line.find("exceeds maximum") > 0 for line in pyocf_ctx_log_buffer.get_lines()]
|
||||||
|
), "Expected to find log notifying that max size was exceeded"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", CacheMode)
|
@pytest.mark.parametrize("mode", CacheMode)
|
||||||
@pytest.mark.parametrize("cls", CacheLineSize)
|
@pytest.mark.parametrize("cls", CacheLineSize)
|
||||||
def test_start_cache_same_device(pyocf_ctx, mode, cls):
|
def test_start_cache_same_device(pyocf_ctx, mode, cls):
|
||||||
|
Loading…
Reference in New Issue
Block a user