Split count_pages and update on metadata deinit
This resets count_pages_variable on cache-detach, so during the following cache-attach metadata size is calculated properly. Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| /* | /* | ||||||
|  * Copyright(c) 2012-2022 Intel Corporation |  * Copyright(c) 2012-2022 Intel Corporation | ||||||
|  * Copyright(c) 2024 Huawei Technologies |  * Copyright(c) 2024-2025 Huawei Technologies | ||||||
|  * SPDX-License-Identifier: BSD-3-Clause |  * SPDX-License-Identifier: BSD-3-Clause | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| @@ -271,7 +271,7 @@ static int ocf_metadata_calculate_metadata_size( | |||||||
| 	lowest_diff = cache_lines; | 	lowest_diff = cache_lines; | ||||||
|  |  | ||||||
| 	do { | 	do { | ||||||
| 		count_pages = ctrl->count_pages; | 		count_pages = 0; | ||||||
| 		for (i = metadata_segment_variable_size_start; | 		for (i = metadata_segment_variable_size_start; | ||||||
| 				i < metadata_segment_max; i++) { | 				i < metadata_segment_max; i++) { | ||||||
| 			struct ocf_metadata_raw *raw = &ctrl->raw_desc[i]; | 			struct ocf_metadata_raw *raw = &ctrl->raw_desc[i]; | ||||||
| @@ -286,7 +286,7 @@ static int ocf_metadata_calculate_metadata_size( | |||||||
| 			/* | 			/* | ||||||
| 			 * Setup SSD location and size | 			 * Setup SSD location and size | ||||||
| 			 */ | 			 */ | ||||||
| 			raw->ssd_pages_offset = count_pages; | 			raw->ssd_pages_offset = ctrl->count_pages_fixed + count_pages; | ||||||
| 			raw->ssd_pages = OCF_DIV_ROUND_UP(raw->entries, | 			raw->ssd_pages = OCF_DIV_ROUND_UP(raw->entries, | ||||||
| 					raw->entries_in_page); | 					raw->entries_in_page); | ||||||
|  |  | ||||||
| @@ -321,7 +321,7 @@ static int ocf_metadata_calculate_metadata_size( | |||||||
| 		/* Cache size in bytes */ | 		/* Cache size in bytes */ | ||||||
| 		diff_lines = ctrl->device_lines * line_size; | 		diff_lines = ctrl->device_lines * line_size; | ||||||
| 		/* Sub metadata size which is in 4 kiB unit */ | 		/* Sub metadata size which is in 4 kiB unit */ | ||||||
| 		diff_lines -= (int64_t)count_pages * PAGE_SIZE; | 		diff_lines -= (int64_t)(ctrl->count_pages_fixed + count_pages) * PAGE_SIZE; | ||||||
| 		/* Convert back to cache lines */ | 		/* Convert back to cache lines */ | ||||||
| 		diff_lines /= line_size; | 		diff_lines /= line_size; | ||||||
| 		/* Calculate difference */ | 		/* Calculate difference */ | ||||||
| @@ -344,7 +344,7 @@ static int ocf_metadata_calculate_metadata_size( | |||||||
|  |  | ||||||
| 	} while (diff_lines); | 	} while (diff_lines); | ||||||
|  |  | ||||||
| 	ctrl->count_pages = count_pages; | 	ctrl->count_pages_variable = count_pages; | ||||||
| 	ctrl->cachelines = cache_lines; | 	ctrl->cachelines = cache_lines; | ||||||
| 	OCF_DEBUG_PARAM(cache, "Cache lines = %u", ctrl->cachelines); | 	OCF_DEBUG_PARAM(cache, "Cache lines = %u", ctrl->cachelines); | ||||||
|  |  | ||||||
| @@ -447,6 +447,7 @@ void ocf_metadata_deinit_variable_size(struct ocf_cache *cache) | |||||||
| 			i < metadata_segment_max; i++) { | 			i < metadata_segment_max; i++) { | ||||||
| 		ocf_metadata_segment_destroy(cache, ctrl->segment[i]); | 		ocf_metadata_segment_destroy(cache, ctrl->segment[i]); | ||||||
| 	} | 	} | ||||||
|  | 	ctrl->count_pages_variable = 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| static inline void ocf_metadata_config_init(ocf_cache_t cache, size_t size) | static inline void ocf_metadata_config_init(ocf_cache_t cache, size_t size) | ||||||
| @@ -530,7 +531,7 @@ static struct ocf_metadata_ctrl *ocf_metadata_ctrl_init( | |||||||
| 		page += ocf_metadata_raw_size_on_ssd(raw); | 		page += ocf_metadata_raw_size_on_ssd(raw); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	ctrl->count_pages = page; | 	ctrl->count_pages_fixed = page; | ||||||
|  |  | ||||||
| 	return ctrl; | 	return ctrl; | ||||||
| } | } | ||||||
| @@ -711,9 +712,10 @@ int ocf_metadata_init_variable_size(struct ocf_cache *cache, | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	OCF_DEBUG_PARAM(cache, "Metadata begin pages = %u", ctrl->start_page); | 	OCF_DEBUG_PARAM(cache, "Metadata begin pages = %u", ctrl->start_page); | ||||||
| 	OCF_DEBUG_PARAM(cache, "Metadata count pages = %u", ctrl->count_pages); | 	OCF_DEBUG_PARAM(cache, "Metadata count pages fixed = %u", ctrl->count_pages_fixed); | ||||||
|  | 	OCF_DEBUG_PARAM(cache, "Metadata count pages variable = %u", ctrl->count_pages_variable); | ||||||
| 	OCF_DEBUG_PARAM(cache, "Metadata end pages = %u", ctrl->start_page | 	OCF_DEBUG_PARAM(cache, "Metadata end pages = %u", ctrl->start_page | ||||||
| 			+ ctrl->count_pages); | 			+ ctrl->count_pages_fixed + ctrl->count_pages_variable); | ||||||
|  |  | ||||||
| 	superblock = ctrl->segment[metadata_segment_sb_config]; | 	superblock = ctrl->segment[metadata_segment_sb_config]; | ||||||
|  |  | ||||||
| @@ -787,7 +789,8 @@ finalize: | |||||||
| 	cache->device->hash_table_entries = | 	cache->device->hash_table_entries = | ||||||
| 			ctrl->raw_desc[metadata_segment_hash].entries; | 			ctrl->raw_desc[metadata_segment_hash].entries; | ||||||
|  |  | ||||||
| 	cache->device->metadata_offset = ctrl->count_pages * PAGE_SIZE; | 	cache->device->metadata_offset = | ||||||
|  | 			(ctrl->count_pages_fixed + ctrl->count_pages_variable) * PAGE_SIZE; | ||||||
|  |  | ||||||
| 	cache->conf_meta->cachelines = ctrl->cachelines; | 	cache->conf_meta->cachelines = ctrl->cachelines; | ||||||
| 	cache->conf_meta->line_size = line_size; | 	cache->conf_meta->line_size = line_size; | ||||||
| @@ -954,7 +957,7 @@ ocf_cache_line_t ocf_metadata_get_pages_count(struct ocf_cache *cache) | |||||||
|  |  | ||||||
| 	ctrl = (struct ocf_metadata_ctrl *) cache->metadata.priv; | 	ctrl = (struct ocf_metadata_ctrl *) cache->metadata.priv; | ||||||
|  |  | ||||||
| 	return ctrl->count_pages; | 	return ctrl->count_pages_fixed + ctrl->count_pages_variable; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| /* | /* | ||||||
|  * Copyright(c) 2020-2021 Intel Corporation |  * Copyright(c) 2020-2021 Intel Corporation | ||||||
|  |  * Copyright(c) 2025 Huawei Technologies | ||||||
|  * SPDX-License-Identifier: BSD-3-Clause |  * SPDX-License-Identifier: BSD-3-Clause | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| @@ -20,7 +21,8 @@ | |||||||
| struct ocf_metadata_ctrl { | struct ocf_metadata_ctrl { | ||||||
| 	ocf_cache_line_t cachelines; | 	ocf_cache_line_t cachelines; | ||||||
| 	ocf_cache_line_t start_page; | 	ocf_cache_line_t start_page; | ||||||
| 	ocf_cache_line_t count_pages; | 	ocf_cache_line_t count_pages_fixed; | ||||||
|  | 	ocf_cache_line_t count_pages_variable; | ||||||
| 	uint32_t device_lines; | 	uint32_t device_lines; | ||||||
| 	size_t mapping_size; | 	size_t mapping_size; | ||||||
| 	struct ocf_metadata_raw raw_desc[metadata_segment_max]; | 	struct ocf_metadata_raw raw_desc[metadata_segment_max]; | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| /* | /* | ||||||
|  * Copyright(c) 2012-2022 Intel Corporation |  * Copyright(c) 2012-2022 Intel Corporation | ||||||
|  * Copyright(c) 2024 Huawei Technologies |  * Copyright(c) 2024-2025 Huawei Technologies | ||||||
|  * SPDX-License-Identifier: BSD-3-Clause |  * SPDX-License-Identifier: BSD-3-Clause | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| @@ -87,7 +87,7 @@ int ocf_metadata_passive_update(struct ocf_request *master) | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (io_start_page >= ctrl->count_pages) { | 	if (io_start_page >= ctrl->count_pages_fixed + ctrl->count_pages_variable) { | ||||||
| 		master->complete(master, 0); | 		master->complete(master, 0); | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Madej
					Daniel Madej