memory: limit the translation length to the original, requested value
spdk_mem_map_translate() will no longer update its translation size parameter to a value that's bigger than requested. This will be handy once we introduce a similar translation length parameter to spdk_vtophys(). Change-Id: Ia662cd3f1340c57a3341182fa0e8137163084779 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/438447 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
b45683c7a3
commit
641c5b0018
@ -614,7 +614,7 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
|
||||
if (size == NULL || map->ops.are_contiguous == NULL ||
|
||||
map_2mb->translation_2mb == map->default_translation) {
|
||||
if (size != NULL) {
|
||||
*size = cur_size;
|
||||
*size = spdk_min(*size, cur_size);
|
||||
}
|
||||
return map_2mb->translation_2mb;
|
||||
}
|
||||
@ -640,7 +640,7 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
|
||||
prev_translation = map_2mb->translation_2mb;
|
||||
}
|
||||
|
||||
*size = cur_size;
|
||||
*size = spdk_min(*size, cur_size);
|
||||
return orig_translation;
|
||||
}
|
||||
|
||||
|
24
test/env/memory/memory_ut.c
vendored
24
test/env/memory/memory_ut.c
vendored
@ -296,6 +296,24 @@ test_mem_map_translation(void)
|
||||
*/
|
||||
CU_ASSERT(addr == 0);
|
||||
|
||||
/* Translate only a subset of a 2MB page */
|
||||
mapping_length = 543;
|
||||
addr = spdk_mem_map_translate(map, 0, &mapping_length);
|
||||
CU_ASSERT(addr == 0);
|
||||
CU_ASSERT(mapping_length == 543);
|
||||
|
||||
/* Translate another subset of a 2MB page */
|
||||
mapping_length = 543;
|
||||
addr = spdk_mem_map_translate(map, VALUE_4KB, &mapping_length);
|
||||
CU_ASSERT(addr == 0);
|
||||
CU_ASSERT(mapping_length == 543);
|
||||
|
||||
/* Try to translate an unaligned region that is only partially registered */
|
||||
mapping_length = 543;
|
||||
addr = spdk_mem_map_translate(map, 3 * VALUE_2MB - 196, &mapping_length);
|
||||
CU_ASSERT(addr == 0);
|
||||
CU_ASSERT(mapping_length == 196);
|
||||
|
||||
/* Clear translation for the first page */
|
||||
rc = spdk_mem_map_clear_translation(map, 0, VALUE_2MB);
|
||||
CU_ASSERT(rc == 0);
|
||||
@ -345,6 +363,12 @@ test_mem_map_translation(void)
|
||||
CU_ASSERT(addr == 0);
|
||||
CU_ASSERT(mapping_length == VALUE_2MB)
|
||||
|
||||
/* Translate only a subset of a 2MB page */
|
||||
mapping_length = 543;
|
||||
addr = spdk_mem_map_translate(map, 0, &mapping_length);
|
||||
CU_ASSERT(addr == 0);
|
||||
CU_ASSERT(mapping_length == 543);
|
||||
|
||||
/* Clear the translation */
|
||||
rc = spdk_mem_map_clear_translation(map, 0, VALUE_2MB * 3);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user