Fail cache recovery in case of erroneous mapping

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2021-12-19 15:58:26 +01:00
parent 913966e3f9
commit 294e02bc1b
4 changed files with 75 additions and 7 deletions

View File

@@ -1552,6 +1552,26 @@ void ocf_metadata_clear_dirty_if_invalid(struct ocf_cache *cache,
}
}
bool ocf_metadata_check(struct ocf_cache *cache, ocf_cache_line_t line)
{
switch (cache->metadata.line_size) {
case ocf_cache_line_size_4:
return _ocf_metadata_check_u8(cache, line);
case ocf_cache_line_size_8:
return _ocf_metadata_check_u16(cache, line);
case ocf_cache_line_size_16:
return _ocf_metadata_check_u32(cache, line);
case ocf_cache_line_size_32:
return _ocf_metadata_check_u64(cache, line);
case ocf_cache_line_size_64:
return _ocf_metadata_check_u128(cache, line);
case ocf_cache_line_size_none:
default:
ENV_BUG_ON(1);
return false;
}
}
int ocf_metadata_init(struct ocf_cache *cache,
ocf_cache_line_size_t cache_line_size)
{

View File

@@ -220,4 +220,14 @@ static inline ocf_cache_line_t ocf_metadata_collision_table_entries(
void ocf_metadata_zero_superblock(ocf_cache_t cache,
ocf_metadata_end_t cmpl, void *context);
/**
* @brief Check for incorrect status bits combinations
*
* @param cache Cache instance
* @param line Cache line
* @return true - status bits are correct
* @return false - status bits have illegal value
*/
bool ocf_metadata_check(struct ocf_cache *cache, ocf_cache_line_t line);
#endif /* METADATA_H_ */

View File

@@ -263,6 +263,23 @@ static void _ocf_metadata_clear_dirty_if_invalid_##type(struct ocf_cache *cache,
\
map[line].dirty &= (mask & map[line].valid) | (~mask); \
} \
\
/* true if no incorrect combination of status bits */ \
static bool _ocf_metadata_check_##type(struct ocf_cache *cache, \
ocf_cache_line_t line) \
{ \
struct ocf_metadata_ctrl *ctrl = \
(struct ocf_metadata_ctrl *) cache->metadata.priv; \
\
struct ocf_metadata_raw *raw = \
&ctrl->raw_desc[metadata_segment_collision]; \
\
struct ocf_metadata_map_##type *map = raw->mem_pool; \
\
_raw_bug_on(raw, line); \
\
return (map[line].dirty & (~map[line].valid)) == 0; \
} \
#define ocf_metadata_bit_funcs(type) \
ocf_metadata_bit_struct(type); \