diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index c344adf..15043cb 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -1540,6 +1540,32 @@ bool ocf_metadata_##what(struct ocf_cache *cache, \ _ocf_metadata_funcs(dirty) _ocf_metadata_funcs(valid) +bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop) +{ + switch (cache->metadata.line_size) { + case ocf_cache_line_size_4: + return _ocf_metadata_clear_valid_if_clean_u8(cache, + line, start, stop); + case ocf_cache_line_size_8: + return _ocf_metadata_clear_valid_if_clean_u16(cache, + line, start, stop); + case ocf_cache_line_size_16: + return _ocf_metadata_clear_valid_if_clean_u32(cache, + line, start, stop); + case ocf_cache_line_size_32: + return _ocf_metadata_clear_valid_if_clean_u64(cache, + line, start, stop); + case ocf_cache_line_size_64: + return _ocf_metadata_clear_valid_if_clean_u128(cache, + line, start, stop); + 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) { diff --git a/src/metadata/metadata_bit.h b/src/metadata/metadata_bit.h index 5e1ccb6..2a2a586 100644 --- a/src/metadata/metadata_bit.h +++ b/src/metadata/metadata_bit.h @@ -221,20 +221,39 @@ static bool _ocf_metadata_test_and_clear_##what##_##type( \ return test; \ } \ -ocf_metadata_bit_struct(u8); -ocf_metadata_bit_struct(u16); -ocf_metadata_bit_struct(u32); -ocf_metadata_bit_struct(u64); -ocf_metadata_bit_struct(u128); +#define ocf_metadata_bit_func_basic(type) \ +static bool _ocf_metadata_clear_valid_if_clean_##type(struct ocf_cache *cache, \ + ocf_cache_line_t line, uint8_t start, uint8_t stop) \ +{ \ + type mask = _get_mask_##type(start, stop); \ +\ + 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); \ +\ + map[line].valid &= ~mask & map[line].dirty; \ +\ + if (map[line].valid) { \ + return true; \ + } else { \ + return false; \ + } \ +} \ -ocf_metadata_bit_func(dirty, u8); -ocf_metadata_bit_func(dirty, u16); -ocf_metadata_bit_func(dirty, u32); -ocf_metadata_bit_func(dirty, u64); -ocf_metadata_bit_func(dirty, u128); +#define ocf_metadata_bit_funcs(type) \ +ocf_metadata_bit_struct(type); \ +ocf_metadata_bit_func(dirty, type); \ +ocf_metadata_bit_func(valid, type); \ +ocf_metadata_bit_func_basic(type); \ -ocf_metadata_bit_func(valid, u8); -ocf_metadata_bit_func(valid, u16); -ocf_metadata_bit_func(valid, u32); -ocf_metadata_bit_func(valid, u64); -ocf_metadata_bit_func(valid, u128); +ocf_metadata_bit_funcs(u8); +ocf_metadata_bit_funcs(u16); +ocf_metadata_bit_funcs(u32); +ocf_metadata_bit_funcs(u64); +ocf_metadata_bit_funcs(u128); diff --git a/src/metadata/metadata_status.h b/src/metadata/metadata_status.h index bacf980..661591c 100644 --- a/src/metadata/metadata_status.h +++ b/src/metadata/metadata_status.h @@ -13,19 +13,33 @@ * Dirty ******************************************************************************/ -bool ocf_metadata_test_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_out_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_out_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_clear_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_set_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_test_and_set_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_and_clear_dirty(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_out_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop); -bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); -bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_out_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_clear_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_set_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); +bool ocf_metadata_test_and_set_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_test_and_clear_valid(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop, bool all); +bool ocf_metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line, uint8_t start, uint8_t stop); static inline void metadata_init_status_bits(struct ocf_cache *cache, ocf_cache_line_t line) @@ -214,6 +228,13 @@ static inline void metadata_clear_valid(struct ocf_cache *cache, ocf_metadata_clear_valid(cache, line, 0, ocf_line_end_sector(cache)); } +static inline void metadata_clear_valid_if_clean(struct ocf_cache *cache, + ocf_cache_line_t line) +{ + ocf_metadata_clear_valid_if_clean(cache, line, 0, + ocf_line_end_sector(cache)); +} + static inline bool metadata_test_and_clear_valid( struct ocf_cache *cache, ocf_cache_line_t line) { diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index fab9132..a22feef 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -509,19 +509,6 @@ static void _recovery_rebuild_cline_metadata(ocf_cache_t cache, } } -static void _recovery_invalidate_clean_sec(struct ocf_cache *cache, - ocf_cache_line_t cline) -{ - uint8_t i; - - for (i = 0; i <= ocf_line_sectors(cache); i++) { - if (!metadata_test_dirty_one(cache, cline, i)) { - /* Invalidate clear sectors */ - metadata_clear_valid_sec_one(cache, cline, i); - } - } -} - static void _recovery_reset_cline_metadata(struct ocf_cache *cache, ocf_cache_line_t cline) { @@ -553,7 +540,7 @@ static void _ocf_mngt_recovery_rebuild_metadata(ocf_cache_t cache) _recovery_rebuild_cline_metadata(cache, core_id, core_line, cline); if (dirty_only) - _recovery_invalidate_clean_sec(cache, cline); + metadata_clear_valid_if_clean(cache, cline); } else { /* Reset metadata for not mapped or clean cache line */ _recovery_reset_cline_metadata(cache, cline);