diff --git a/src/engine/engine_common.c b/src/engine/engine_common.c index 9a729f9..2bd6544 100644 --- a/src/engine/engine_common.c +++ b/src/engine/engine_common.c @@ -95,15 +95,8 @@ void ocf_engine_update_req_info(struct ocf_cache *cache, uint8_t end_sector = ocf_line_end_sector(cache); struct ocf_map_info *_entry = &(req->map[entry]); - if (entry == 0) { - start_sector = BYTES_TO_SECTORS(req->byte_position) - % ocf_line_sectors(cache); - } - - if (entry == req->core_line_count - 1) { - end_sector = BYTES_TO_SECTORS(req->byte_position + - req->byte_length - 1)% ocf_line_sectors(cache); - } + start_sector = ocf_map_line_start_sector(req, entry); + end_sector = ocf_map_line_end_sector(req, entry); /* Handle return value */ switch (_entry->status) { diff --git a/src/utils/utils_cache_line.h b/src/utils/utils_cache_line.h index 53f9708..e014df6 100644 --- a/src/utils/utils_cache_line.h +++ b/src/utils/utils_cache_line.h @@ -229,6 +229,29 @@ static inline void ocf_purge_map_info(struct ocf_request *req) } } +static inline +uint8_t ocf_map_line_start_sector(struct ocf_request *req, uint32_t line) +{ + if (line == 0) { + return BYTES_TO_SECTORS(req->byte_position) + % ocf_line_sectors(req->cache); + } + + return 0; +} + +static inline +uint8_t ocf_map_line_end_sector(struct ocf_request *req, uint32_t line) +{ + if (line == req->core_line_count - 1) { + return BYTES_TO_SECTORS(req->byte_position + + req->byte_length - 1) % + ocf_line_sectors(req->cache); + } + + return ocf_line_end_sector(req->cache); +} + static inline void ocf_set_valid_map_info(struct ocf_request *req) { uint32_t map_idx = 0; @@ -244,27 +267,11 @@ static inline void ocf_set_valid_map_info(struct ocf_request *req) * | -----+++ | ++++++++ | +++ | ++++++++ | +++++--- | * | first | Middle | last | */ - for (map_idx = 0; map_idx < count; map_idx++) { ENV_BUG_ON(map[map_idx].status == LOOKUP_MISS); - start_bit = 0; - end_bit = ocf_line_end_sector(cache); - - if (map_idx == 0) { - /* First */ - - start_bit = BYTES_TO_SECTORS(req->byte_position) - % ocf_line_sectors(cache); - } - - if (map_idx == (count - 1)) { - /* Last */ - - end_bit = BYTES_TO_SECTORS(req->byte_position + - req->byte_length - 1) - % ocf_line_sectors(cache); - } + start_bit = ocf_map_line_start_sector(req, map_idx); + end_bit = ocf_map_line_end_sector(req, map_idx); set_cache_line_valid(cache, start_bit, end_bit, req, map_idx); } @@ -286,24 +293,8 @@ static inline void ocf_set_dirty_map_info(struct ocf_request *req) */ for (map_idx = 0; map_idx < count; map_idx++) { - start_bit = 0; - end_bit = ocf_line_end_sector(cache); - - if (map_idx == 0) { - /* First */ - - start_bit = BYTES_TO_SECTORS(req->byte_position) - % ocf_line_sectors(cache); - } - - if (map_idx == (count - 1)) { - /* Last */ - - end_bit = BYTES_TO_SECTORS(req->byte_position + - req->byte_length - 1) % - ocf_line_sectors(cache); - } - + start_bit = ocf_map_line_start_sector(req, map_idx); + end_bit = ocf_map_line_end_sector(req, map_idx); set_cache_line_dirty(cache, start_bit, end_bit, req, map_idx); } } @@ -324,25 +315,8 @@ static inline void ocf_set_clean_map_info(struct ocf_request *req) */ for (map_idx = 0; map_idx < count; map_idx++) { - start_bit = 0; - end_bit = ocf_line_end_sector(cache); - - if (map_idx == 0) { - /* First */ - - start_bit = BYTES_TO_SECTORS(req->byte_position) - % ocf_line_sectors(cache); - } - - if (map_idx == (count - 1)) { - /* Last */ - - end_bit = BYTES_TO_SECTORS(req->byte_position + - req->byte_length - 1) % - ocf_line_sectors(cache); - - } - + start_bit = ocf_map_line_start_sector(req, map_idx); + end_bit = ocf_map_line_end_sector(req, map_idx); set_cache_line_clean(cache, start_bit, end_bit, req, map_idx); } }