diff --git a/doc/Makefile b/doc/Makefile index d0eed29b0fa7dd57e37d2d2cb3faaec1d2b0ccac..88469bb55f9f99913f067633835ea44eefd21a16 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -102,7 +102,6 @@ MANPAGES_3_MD_PMEM2 = libpmem2/pmem2_errormsg.3.md libpmem2/pmem2_config_new.3.m libpmem2/pmem2_map_get_store_granularity.3.md libpmem2/pmem2_get_flush_fn.3.md \ libpmem2/pmem2_get_drain_fn.3.md libpmem2/pmem2_get_persist_fn.3.md \ libpmem2/pmem2_perror.3.md libpmem2/pmem2_get_memmove_fn.3.md libpmem2/pmem2_config_set_sharing.3.md \ - libpmem2/pmem2_config_set_address.3.md libpmem2/pmem2_config_clear_address.3.md \ libpmem2/pmem2_config_set_vm_reservation.3.md libpmem2/pmem2_vm_reservation_new.3.md \ libpmem2/pmem2_vm_reservation_get_address.3.md libpmem2/pmem2_vm_reservation_get_size.3.md \ libpmem2/pmem2_badblock_context_new.3.md libpmem2/pmem2_badblock_next.3.md \ diff --git a/doc/libpmem2/.gitignore b/doc/libpmem2/.gitignore index 82f48e6f39b8c9cd0b541d90513c6951eee345ce..968b3664dd878d67a7fef503f504d27d2cfa775e 100644 --- a/doc/libpmem2/.gitignore +++ b/doc/libpmem2/.gitignore @@ -3,9 +3,7 @@ libpmem2_unsafe_shutdown.7 pmem2_badblock_context_new.3 pmem2_badblock_next.3 pmem2_badblock_clear.3 -pmem2_config_clear_address.3 pmem2_config_new.3 -pmem2_config_set_address.3 pmem2_config_set_length.3 pmem2_config_set_offset.3 pmem2_config_set_protection.3 diff --git a/doc/libpmem2/pmem2_config_clear_address.3.md b/doc/libpmem2/pmem2_config_clear_address.3.md deleted file mode 100644 index 50d13d97548e37540309b452e1f6fb67c6136f2a..0000000000000000000000000000000000000000 --- a/doc/libpmem2/pmem2_config_clear_address.3.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -layout: manual -Content-Style: 'text/css' -title: _MP(PMEM2_CONFIG_CLEAR_ADDRESS, 3) -collection: libpmem2 -header: PMDK -date: pmem2 API version 1.0 -... - -[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) -[comment]: <> (Copyright 2020, Intel Corporation) - -[comment]: <> (pmem2_config_clear_address.3 -- man page for libpmem2 config API) - -[NAME](#name)<br /> -[SYNOPSIS](#synopsis)<br /> -[DESCRIPTION](#description)<br /> -[RETURN VALUE](#return-value)<br /> -[SEE ALSO](#see-also)<br /> - -# NAME # - -**pmem2_config_clear_address**() - reset addr and request_type to the default values -in the pmem2_config structure - -# SYNOPSIS # - -```c -#include <libpmem2.h> - -struct pmem2_config; -void pmem2_config_clear_address(struct pmem2_config *cfg); -``` - -# DESCRIPTION # - -The **pmem2_config_clear_address**() function resets *\*addr* and \**request_type* to the default values. -The function is used to revert changes set by **pmem2_config_set_address**(3). -If the *\*addr* is default, the starting mapping address will be chosen by the operating system, for -more information please see **pmem2_map_new**(3). - -# RETURN VALUE # - -**pmem2_config_clear_address**() does not return any value. - -# SEE ALSO # - -**libpmem2**(7), **pmem2_config_set_address**(3), **pmem2_map_new**(3), and **<http://pmem.io>** diff --git a/doc/libpmem2/pmem2_config_set_address.3.md b/doc/libpmem2/pmem2_config_set_address.3.md deleted file mode 100644 index 0898687323fa0dfb00c61c5e5659354bdcefbfa3..0000000000000000000000000000000000000000 --- a/doc/libpmem2/pmem2_config_set_address.3.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -layout: manual -Content-Style: 'text/css' -title: _MP(PMEM2_CONFIG_SET_ADDRESS, 3) -collection: libpmem2 -header: PMDK -date: pmem2 API version 1.0 -... - -[comment]: <> (SPDX-License-Identifier: BSD-3-Clause) -[comment]: <> (Copyright 2020, Intel Corporation) - -[comment]: <> (pmem2_config_set_address.3 -- man page for libpmem2 config API) - -[NAME](#name)<br /> -[SYNOPSIS](#synopsis)<br /> -[DESCRIPTION](#description)<br /> -[RETURN VALUE](#return-value)<br /> -[ERRORS](#errors)<br /> -[SEE ALSO](#see-also)<br /> - -# NAME # - -**pmem2_config_set_address**() - set requested address in the pmem2_config structure - -# SYNOPSIS # - -```c -#include <libpmem2.h> - -struct pmem2_config; -enum pmem2_address_request_type { - PMEM2_ADDRESS_FIXED_REPLACE, - PMEM2_ADDRESS_FIXED_NOREPLACE, -}; -int pmem2_config_set_address(struct pmem2_config *cfg, void *addr, - enum pmem2_address_request_type request_type); -``` - -# DESCRIPTION # - -The **pmem2_config_set_address**() function sets the starting address *\*addr* which will be used -for memory mapping. If the *\*addr* is not specified in the config, the starting address -will be chosen by the operating system. The *\request_type* specifies how strictly the address -should be enforced. *\*config* should be already initialized, please see **pmem2_config_new**(3) -for details. The *\*addr* cannot be **NULL** and must be a multiple of the alignment required for the -data source which will be used for mapping alongside the config. To retrieve the alignment required -for specific instance of **pmem2_source** use **pmem2_source_alignment**(3). To reset *\*addr* and -*\request_type* to the default values, please use **pmem2_config_clear_address**(3). - -Possible address request types are: - -* **PMEM2_ADDRESS_FIXED_REPLACE** - not supported yet. - -* **PMEM2_ADDRESS_FIXED_NOREPLACE** - *\*addr* cannot be **NULL**, kernel tries to place the mapping -at exactly the address which was set by user. When any part of <*\*addr*, *\*addr* + length> address -space is occupied, **pmem2_map_new**(3) fails with the **PMEM2_E_MAPPING_EXISTS** return code. - -# RETURN VALUE # - -The **pmem2_config_set_address**() function returns 0 on success -or a negative error code on failure. - -# ERRORS # - -The **pmem2_config_set_address**() can fail with the following errors: - -* **PMEM2_E_INVALID_ADDRESS_REQUEST_TYPE** - set address request type is invalid. - -* **PMEM2_E_ADDRESS_NULL** - cannot use address request type **PMEM2_ADDRESS_FIXED_NOREPLACE** -when address is **NULL**. - -# SEE ALSO # - -**libpmem2**(7), **pmem2_config_clear_address**(3), **pmem2_config_new**(3), **pmem2_map_new**(3), -**pmem2_source_alignment**(3), **sysconf**(3) and **<http://pmem.io>** diff --git a/src/include/libpmem2.h b/src/include/libpmem2.h index 45e78c4b0d73f30d98675c385db5fe7cb02f5fe9..44e29d672ef580f1f46bc58ffd388777ad8bb71f 100644 --- a/src/include/libpmem2.h +++ b/src/include/libpmem2.h @@ -137,19 +137,9 @@ int pmem2_config_set_sharing(struct pmem2_config *cfg, int pmem2_config_set_protection(struct pmem2_config *cfg, unsigned prot); -enum pmem2_address_request_type { - PMEM2_ADDRESS_FIXED_REPLACE = 1, - PMEM2_ADDRESS_FIXED_NOREPLACE = 2, -}; - -int pmem2_config_set_address(struct pmem2_config *cfg, void *addr, - enum pmem2_address_request_type request_type); - int pmem2_config_set_vm_reservation(struct pmem2_config *cfg, struct pmem2_vm_reservation *rsv, size_t offset); -void pmem2_config_clear_address(struct pmem2_config *cfg); - /* mapping */ struct pmem2_map; diff --git a/src/libpmem2/config.c b/src/libpmem2/config.c index 76f6ba4be5971fbf43176d07070bed696947ee2d..9274788aa6446f30799684f65dc836aeed7e310a 100644 --- a/src/libpmem2/config.c +++ b/src/libpmem2/config.c @@ -21,8 +21,6 @@ pmem2_config_init(struct pmem2_config *cfg) { cfg->offset = 0; cfg->length = 0; - cfg->addr = NULL; - cfg->addr_request = PMEM2_ADDRESS_ANY; cfg->requested_max_granularity = PMEM2_GRANULARITY_INVALID; cfg->sharing = PMEM2_SHARED; cfg->protection_flag = PMEM2_PROT_READ | PMEM2_PROT_WRITE; @@ -182,61 +180,6 @@ pmem2_config_set_sharing(struct pmem2_config *cfg, enum pmem2_sharing_type type) return 0; } -/* - * pmem2_config_validate_addr_alignment -- validate that addr in the - * pmem2_config structure is a multiple of the alignment required for - * specific cfg - */ -int -pmem2_config_validate_addr_alignment(const struct pmem2_config *cfg, - const struct pmem2_source *src) -{ - /* cannot NULL % alignment, NULL is valid */ - if (!cfg->addr) - return 0; - - size_t alignment; - int ret = pmem2_source_alignment(src, &alignment); - if (ret) - return ret; - - ASSERTne(alignment, 0); - if ((size_t)cfg->addr % alignment) { - ERR("address %p is not a multiple of %lu", cfg->addr, - alignment); - return PMEM2_E_ADDRESS_UNALIGNED; - } - - return 0; -} - -/* - * pmem2_config_set_address -- set addr and addr_request in the config - * struct - */ -int -pmem2_config_set_address(struct pmem2_config *cfg, void *addr, - enum pmem2_address_request_type request_type) -{ - PMEM2_ERR_CLR(); - - if (request_type != PMEM2_ADDRESS_FIXED_NOREPLACE) { - ERR("invalid address request_type 0x%x", request_type); - return PMEM2_E_INVALID_ADDRESS_REQUEST_TYPE; - } - - if (request_type == PMEM2_ADDRESS_FIXED_NOREPLACE && !addr) { - ERR( - "cannot use address request type PMEM2_ADDRESS_FIXED_NOREPLACE with addr being NULL"); - return PMEM2_E_ADDRESS_NULL; - } - - cfg->addr = addr; - cfg->addr_request = (int)request_type; - - return 0; -} - /* * pmem2_config_set_vm_reservation -- set vm_reservation in the * pmem2_config structure @@ -253,19 +196,6 @@ pmem2_config_set_vm_reservation(struct pmem2_config *cfg, return 0; } -/* - * pmem2_config_clear_address -- reset addr and addr_request in the config - * to the default values - */ -void -pmem2_config_clear_address(struct pmem2_config *cfg) -{ - PMEM2_ERR_CLR(); - - cfg->addr = NULL; - cfg->addr_request = PMEM2_ADDRESS_ANY; -} - /* * pmem2_config_set_protection -- set protection flags * in the config struct diff --git a/src/libpmem2/config.h b/src/libpmem2/config.h index b81215e5e48a5b60fb70d77522c5a4dd79f01b14..beb693c436de393c1e68fbcf55795b399831dd76 100644 --- a/src/libpmem2/config.h +++ b/src/libpmem2/config.h @@ -31,7 +31,4 @@ void pmem2_config_init(struct pmem2_config *cfg); int pmem2_config_validate_length(const struct pmem2_config *cfg, size_t file_len, size_t alignment); -int pmem2_config_validate_addr_alignment(const struct pmem2_config *cfg, - const struct pmem2_source *src); - #endif /* PMEM2_CONFIG_H */ diff --git a/src/libpmem2/libpmem2.def b/src/libpmem2/libpmem2.def index a3806b773e41f1bf5512114aae37c6328238563e..053bac0fae94c5aebdd3b316eeb6ac8c0b2d01d8 100644 --- a/src/libpmem2/libpmem2.def +++ b/src/libpmem2/libpmem2.def @@ -12,10 +12,8 @@ EXPORTS pmem2_badblock_context_delete pmem2_badblock_context_new pmem2_badblock_next - pmem2_config_clear_address pmem2_config_delete pmem2_config_new - pmem2_config_set_address pmem2_config_set_length pmem2_config_set_offset pmem2_config_set_protection diff --git a/src/libpmem2/libpmem2.link.in b/src/libpmem2/libpmem2.link.in index d9a9674c2ccd692613fa39e65e3544eecc2d93c0..2df211e0c47e67f6afef89900a2efb3d869be1d9 100644 --- a/src/libpmem2/libpmem2.link.in +++ b/src/libpmem2/libpmem2.link.in @@ -10,10 +10,8 @@ LIBPMEM2_1.0 { pmem2_badblock_context_delete; pmem2_badblock_context_new; pmem2_badblock_next; - pmem2_config_clear_address; pmem2_config_delete; pmem2_config_new; - pmem2_config_set_address; pmem2_config_set_length; pmem2_config_set_offset; pmem2_config_set_protection; diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 39d26c11286b43322e381e20c17e68d4948311cb..342ab1409086ceda5c2973d11b46354b3e2fea11 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -112,29 +112,7 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, { ASSERTne(reserv, NULL); - /* let's get addr from the cfg */ - void *mmap_addr = cfg->addr; - int mmap_addr_flag = 0; - size_t dlength; /* dummy length */ - - /* if addr is initialized, dlength == len */ - if (mmap_addr) - dlength = len; - else - dlength = len + alignment; /* dummy length */ - - /* "translate" pmem2 addr request type into linux flag */ - if (cfg->addr_request == PMEM2_ADDRESS_FIXED_NOREPLACE) { - /* - * glibc started exposing this flag in version 4.17 but we can still - * imitate it even if it is not supported by libc or kernel - */ -#ifdef MAP_FIXED_NOREPLACE - mmap_addr_flag = MAP_FIXED_NOREPLACE; -#else - mmap_addr_flag = 0; -#endif - } + size_t dlength = len + alignment; /* dummy length */ /* * Create dummy mapping to find an unused region of given size. @@ -143,8 +121,8 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, * zero cost for overcommit accounting. Note: MAP_NORESERVE * flag is ignored if overcommit is disabled (mode 2). */ - char *daddr = mmap(mmap_addr, dlength, PROT_READ, - MAP_PRIVATE | MAP_ANONYMOUS | mmap_addr_flag, -1, 0); + char *daddr = mmap(NULL, dlength, PROT_READ, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (daddr == MAP_FAILED) { if (errno == EEXIST) { ERR("!mmap MAP_FIXED_NOREPLACE"); @@ -154,21 +132,6 @@ map_reserve(size_t len, size_t alignment, void **reserv, size_t *reslen, return PMEM2_E_ERRNO; } - /* - * When kernel does not support MAP_FIXED_NOREPLACE flag we imitate it. - * If kernel does not support flag and given addr is occupied, kernel - * chooses new addr randomly and returns it. We do not want that - * behavior, so we validate it and fail when addresses do not match. - */ - if (mmap_addr && cfg->addr_request == PMEM2_ADDRESS_FIXED_NOREPLACE) { - /* mapping passed and gave different addr, while it shouldn't */ - if (daddr != mmap_addr) { - munmap(daddr, dlength); - ERR("mapping exists in the given address"); - return PMEM2_E_MAPPING_EXISTS; - } - } - LOG(4, "system choice %p", daddr); *reserv = (void *)roundup((uintptr_t)daddr, alignment); /* @@ -407,10 +370,6 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, size_t alignment = get_map_alignment(content_length, src_alignment); - ret = pmem2_config_validate_addr_alignment(cfg, src); - if (ret) - return ret; - /* prepare pmem2_map structure */ map = (struct pmem2_map *)pmem2_malloc(sizeof(*map), &ret); if (!map) diff --git a/src/libpmem2/map_windows.c b/src/libpmem2/map_windows.c index 871250a74f27364552374066b5ff40083323e7d5..0441574be996b613aec642e0d8b4aeccc7fb7c59 100644 --- a/src/libpmem2/map_windows.c +++ b/src/libpmem2/map_windows.c @@ -331,10 +331,6 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, return pmem2_lasterror_to_err(); } - ret = pmem2_config_validate_addr_alignment(cfg, src); - if (ret) - goto err_close_mapping_handle; - /* prepare pmem2_map structure */ struct pmem2_map *map; map = (struct pmem2_map *)pmem2_malloc(sizeof(*map), &ret); @@ -406,29 +402,16 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, goto err_vm_reserv_unregister; } } else { - /* let's get addr from cfg struct */ - LPVOID addr_hint = cfg->addr; - /* obtain a pointer to the mapping view */ - base = MapViewOfFileEx(mh, + base = MapViewOfFile(mh, access, HIDWORD(effective_offset), LODWORD(effective_offset), - length, - addr_hint); /* hint address */ + length); if (base == NULL) { - ERR("!!MapViewOfFileEx"); - if (cfg->addr_request == - PMEM2_ADDRESS_FIXED_NOREPLACE) { - DWORD ret_windows = GetLastError(); - if (ret_windows == ERROR_INVALID_ADDRESS) - ret = PMEM2_E_MAPPING_EXISTS; - else - ret = pmem2_lasterror_to_err(); - } - else - ret = pmem2_lasterror_to_err(); + ERR("!!MapViewOfFile"); + ret = pmem2_lasterror_to_err(); goto err_free_map_struct; } } diff --git a/src/test/pmem2_config/TESTS.py b/src/test/pmem2_config/TESTS.py index 46bf0ee406736d780d650090c4322e5c33bf54c2..b2878a4477215c7896053178f77781944cb783a5 100755 --- a/src/test/pmem2_config/TESTS.py +++ b/src/test/pmem2_config/TESTS.py @@ -80,39 +80,14 @@ class TEST10(Pmem2ConfigNoDir): test_case = "test_set_sharing_invalid" -class TEST11(Pmem2Config): - """setting unaligned addr and validating it""" - test_case = "test_validate_unaligned_addr" - - -class TEST12(Pmem2ConfigNoDir): - """setting wrong addr request type""" - test_case = "test_set_wrong_addr_req_type" - - -class TEST13(Pmem2ConfigNoDir): - """ - setting null addr when request type PMEM2_ADDRESS_FIXED_NOREPLACE - is used - """ - test_case = "test_null_addr_noreplace" - - -class TEST14(Pmem2ConfigNoDir): - """ - using pmem2_config_clear_address func - """ - test_case = "test_clear_address" - - -class TEST15(Pmem2ConfigNoDir): +class TEST11(Pmem2ConfigNoDir): """ setting a valid protection flags """ test_case = "test_set_valid_prot_flag" -class TEST16(Pmem2ConfigNoDir): +class TEST12(Pmem2ConfigNoDir): """ setting a invalid protection flags """ diff --git a/src/test/pmem2_config/pmem2_config.c b/src/test/pmem2_config/pmem2_config.c index 41b15dc3f80ec36cc16a380245d5aa6dda684bec..41bb701147c23c0d7375c1acd4afb97f36484137 100644 --- a/src/test/pmem2_config/pmem2_config.c +++ b/src/test/pmem2_config/pmem2_config.c @@ -217,98 +217,6 @@ test_set_sharing_invalid(const struct test_case *tc, int argc, char *argv[]) return 0; } -/* - * test_validate_unaligned_addr - setting unaligned addr and validating it - */ -static int -test_validate_unaligned_addr(const struct test_case *tc, int argc, - char *argv[]) -{ - if (argc < 1) - UT_FATAL("usage: test_validate_unaligned_addr <file>"); - - /* needed for source alignment */ - char *file = argv[0]; - int fd = OPEN(file, O_RDWR); - - struct pmem2_source *src; - PMEM2_SOURCE_FROM_FD(&src, fd); - struct pmem2_config cfg; - pmem2_config_init(&cfg); - - /* let's set addr which is unaligned */ - cfg.addr = (char *)1; - - int ret = pmem2_config_validate_addr_alignment(&cfg, src); - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_ADDRESS_UNALIGNED); - - PMEM2_SOURCE_DELETE(&src); - CLOSE(fd); - - return 1; -} - -/* - * test_set_wrong_addr_req_type - setting wrong addr request type - */ -static int -test_set_wrong_addr_req_type(const struct test_case *tc, int argc, - char *argv[]) -{ - struct pmem2_config cfg; - pmem2_config_init(&cfg); - - /* "randomly" chosen invalid addr request type */ - enum pmem2_address_request_type request_type = 999; - int ret = pmem2_config_set_address(&cfg, NULL, request_type); - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_INVALID_ADDRESS_REQUEST_TYPE); - - return 0; -} - -/* - * test_null_addr_noreplace - setting null addr when request type - * PMEM2_ADDRESS_FIXED_NOREPLACE is used - */ -static int -test_null_addr_noreplace(const struct test_case *tc, int argc, - char *argv[]) -{ - struct pmem2_config cfg; - pmem2_config_init(&cfg); - - int ret = pmem2_config_set_address( - &cfg, NULL, PMEM2_ADDRESS_FIXED_NOREPLACE); - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_ADDRESS_NULL); - - return 0; -} - -/* - * test_clear_address - using pmem2_config_clear_address func - */ -static int -test_clear_address(const struct test_case *tc, int argc, - char *argv[]) -{ - struct pmem2_config cfg; - pmem2_config_init(&cfg); - - /* "randomly" chosen value of address and addr request type */ - void *addr = (void *)(1024 * 1024); - int ret = pmem2_config_set_address( - &cfg, addr, PMEM2_ADDRESS_FIXED_NOREPLACE); - UT_ASSERTeq(ret, 0); - UT_ASSERTne(cfg.addr, NULL); - UT_ASSERTne(cfg.addr_request, PMEM2_ADDRESS_ANY); - - pmem2_config_clear_address(&cfg); - UT_ASSERTeq(cfg.addr, NULL); - UT_ASSERTeq(cfg.addr_request, PMEM2_ADDRESS_ANY); - - return 0; -} - /* * test_set_valid_prot_flag -- set valid protection flag */ @@ -370,10 +278,6 @@ static struct test_case test_cases[] = { TEST_CASE(test_set_offset_max), TEST_CASE(test_set_sharing_valid), TEST_CASE(test_set_sharing_invalid), - TEST_CASE(test_validate_unaligned_addr), - TEST_CASE(test_set_wrong_addr_req_type), - TEST_CASE(test_null_addr_noreplace), - TEST_CASE(test_clear_address), TEST_CASE(test_set_valid_prot_flag), TEST_CASE(test_set_invalid_prot_flag), }; diff --git a/src/test/pmem2_map/TESTS.py b/src/test/pmem2_map/TESTS.py index 78643f4b45775ac919700eee419d3f9227f8098e..9028cb9f40e8b327ac4788f330f776c250db93e9 100755 --- a/src/test/pmem2_map/TESTS.py +++ b/src/test/pmem2_map/TESTS.py @@ -216,35 +216,3 @@ class TEST28(PMEM2_MAP_DEVDAX): """DevDax file with PMEM2_PRIVATE sharing""" test_case = "test_map_sharing_private_devdax" with_size = False - - -class TEST29(PMEM2_MAP): - """ - map a file to the desired addr with request type - PMEM2_ADDRESS_FIXED_NOREPLACE - """ - test_case = "test_map_fixed_noreplace_valid" - - -class TEST30(PMEM2_MAP): - """ - map a file and overlap whole other existing mapping with the request type - PMEM2_ADDRESS_FIXED_NOREPLACE - """ - test_case = "test_map_fixed_noreplace_full_overlap" - - -class TEST31(PMEM2_MAP): - """ - map a file in a middle of other existing mapping with the request type - PMEM2_ADDRESS_FIXED_NOREPLACE - """ - test_case = "test_map_fixed_noreplace_partial_overlap" - - -class TEST32(PMEM2_MAP): - """ - map a file which starts in a middle and ends above of other - existing mapping with request type PMEM2_ADDRESS_FIXED_NOREPLACE - """ - test_case = "test_map_fixed_noreplace_partial_above_overlap" diff --git a/src/test/pmem2_map/pmem2_map.c b/src/test/pmem2_map/pmem2_map.c index 71b1f4a92ab2dfd5c911bff16118b0d7e0ee068e..19ff25cd16b065f6723f442b82b574e97badf57f 100644 --- a/src/test/pmem2_map/pmem2_map.c +++ b/src/test/pmem2_map/pmem2_map.c @@ -20,21 +20,6 @@ #define KILOBYTE (1 << 10) #define MEGABYTE (1 << 20) -/* - * prepare_config_with_addr -- extended version of ut_pmem2_prepare_config - - * fill pmem2_config also with addr and addr_request - */ -static void -prepare_config_with_addr(struct pmem2_config *cfg, struct pmem2_source **src, - struct FHandle **fh, const char *file, size_t length, size_t offset, - int access, void *addr, enum pmem2_address_request_type addr_request) -{ - ut_pmem2_prepare_config(cfg, src, fh, FH_FD, file, length, offset, - access); - cfg->addr = addr; - cfg->addr_request = (int)addr_request; -} - #ifdef _WIN32 #define HIDWORD(x) ((DWORD)((x) >> 32)) @@ -846,241 +831,6 @@ test_map_sharing_private_devdax(const struct test_case *tc, int argc, return 1; } -/* - * test_map_fixed_noreplace_valid - map a file to the desired addr with - * address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ -static int -test_map_fixed_noreplace_valid(const struct test_case *tc, - int argc, char *argv[]) -{ - if (argc < 2) - UT_FATAL("usage: test_map_fixed_noreplace_valid <file> <size>"); - - char *file = argv[0]; - size_t size = ATOUL(argv[1]); - struct pmem2_config cfg; - struct pmem2_source *src; - struct pmem2_map *map = NULL; - struct FHandle *fh; - void *addr; - - ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, size, 0, - FH_RDWR); - int ret = pmem2_map_new(&map, &cfg, src); - UT_ASSERTeq(ret, 0); - - addr = pmem2_map_get_address(map); - - /* unmap current mapping */ - ret = pmem2_map_delete(&map); - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(map, NULL); - PMEM2_SOURCE_DELETE(&src); - UT_FH_CLOSE(fh); - - /* - * let's do the same mapping, to the same addr but with - * address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ - prepare_config_with_addr(&cfg, &src, &fh, file, size, 0, FH_RDWR, - addr, PMEM2_ADDRESS_FIXED_NOREPLACE); - - ret = pmem2_map_new(&map, &cfg, src); - UT_ASSERTeq(ret, 0); - - /* check if mapping is in the same addr, which is desired */ - UT_ASSERTeq(addr, map->addr); - - /* unmap mapping */ - ret = pmem2_map_delete(&map); - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(map, NULL); - - PMEM2_SOURCE_DELETE(&src); - UT_FH_CLOSE(fh); - - return 2; -} - -/* - * test_map_fixed_noreplace_full_overlap - map a file and overlap whole - * other existing mapping with address type request - * PMEM2_ADDRESS_FIXED_NOREPLACE - */ -static int -test_map_fixed_noreplace_full_overlap(const struct test_case *tc, - int argc, char *argv[]) -{ - if (argc < 2) - UT_FATAL("usage: test_map_fixed_noreplace_full_overlap" - " <file> <size>"); - - char *file = argv[0]; - size_t size = ATOUL(argv[1]); - struct pmem2_source *src; - struct pmem2_config cfg; - struct pmem2_map *map = NULL; - struct pmem2_map *map_overlap = NULL; - struct FHandle *fh; - struct FHandle *fh_overlap; - void *addr; - - ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, size, 0, - FH_RDWR); - int ret = pmem2_map_new(&map, &cfg, src); - UT_ASSERTeq(ret, 0); - - addr = pmem2_map_get_address(map); - - /* - * let's do the same mapping, to the same addr but with - * the address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ - prepare_config_with_addr(&cfg, &src, &fh_overlap, file, size, 0, - FH_RDWR, addr, PMEM2_ADDRESS_FIXED_NOREPLACE); - ret = pmem2_map_new(&map_overlap, &cfg, src); - - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_MAPPING_EXISTS); - - /* unmap first mapping and close fds */ - ret = pmem2_map_delete(&map); - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(map, NULL); - PMEM2_SOURCE_DELETE(&src); - UT_FH_CLOSE(fh); - UT_FH_CLOSE(fh_overlap); - - return 2; -} - -/* - * test_map_fixed_noreplace_partial_overlap - map a file in a middle of - * other existing mapping with address type request - * PMEM2_ADDRESS_FIXED_NOREPLACE - */ -static int -test_map_fixed_noreplace_partial_overlap(const struct test_case *tc, - int argc, char *argv[]) -{ - if (argc < 2) - UT_FATAL("usage: test_map_fixed_noreplace_partial_overlap" - " <file> <size>"); - - char *file = argv[0]; - size_t size = ATOUL(argv[1]); - struct pmem2_source *src; - struct pmem2_config cfg; - struct pmem2_map *map = NULL; - struct pmem2_map *map_overlap = NULL; - struct FHandle *fh; - struct FHandle *fh_overlap; - void *addr; - - ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, size, 0, - FH_RDWR); - int ret = pmem2_map_new(&map, &cfg, src); - UT_ASSERTeq(ret, 0); - - /* - * Let's get address of the current mapping and move it to the - * middle of the mapping. "Randomly" define size of the new - * mapping as MEGABYTE. - */ - addr = (char *)pmem2_map_get_address(map) + MEGABYTE; - size_t overlap_size = MEGABYTE; - - /* check if new mapping is in the middle of the existing one */ - UT_ASSERT(size > MEGABYTE + overlap_size); - - /* - * let's do the mapping in the middle of existing one, but - * with the address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ - prepare_config_with_addr(&cfg, &src, &fh_overlap, file, - overlap_size, 0, FH_RDWR, addr, - PMEM2_ADDRESS_FIXED_NOREPLACE); - ret = pmem2_map_new(&map_overlap, &cfg, src); - - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_MAPPING_EXISTS); - - /* unmap first mapping and close fds */ - ret = pmem2_map_delete(&map); - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(map, NULL); - PMEM2_SOURCE_DELETE(&src); - UT_FH_CLOSE(fh); - UT_FH_CLOSE(fh_overlap); - - return 2; -} - -/* - * test_map_fixed_noreplace_partial_above_overlap - map a file which - * starts in a middle and ends above of other existing mapping with - * address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ -static int -test_map_fixed_noreplace_partial_above_overlap(const struct test_case *tc, - int argc, char *argv[]) -{ - if (argc < 2) - UT_FATAL("usage: test_map_fixed_noreplace_partial_overlap" - " <file> <size>"); - - char *file = argv[0]; - size_t size = ATOUL(argv[1]); - struct pmem2_source *src; - struct pmem2_config cfg; - struct pmem2_map *map = NULL; - struct pmem2_map *map_overlap = NULL; - struct FHandle *fh; - struct FHandle *fh_overlap; - void *addr; - - /* let's do the mapping which size is half of the file size */ - size /= 2; - ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, size, 0, - FH_RDWR); - int ret = pmem2_map_new(&map, &cfg, src); - UT_ASSERTeq(ret, 0); - - /* - * Let's get address of the current mapping and move it to the - * middle of the mapping. "Randomly" define size of the new - * mapping as a size. - */ - addr = (char *)pmem2_map_get_address(map) + MEGABYTE; - size_t overlap_size = size; - - /* - * check if new mapping starts in the middle and ends above of - * the existing one - */ - UT_ASSERT(size < MEGABYTE + overlap_size); - - /* - * let's do the mapping in the middle of existing one, but - * with the address type request PMEM2_ADDRESS_FIXED_NOREPLACE - */ - prepare_config_with_addr(&cfg, &src, &fh_overlap, file, - overlap_size, 0, FH_RDWR, addr, - PMEM2_ADDRESS_FIXED_NOREPLACE); - ret = pmem2_map_new(&map_overlap, &cfg, src); - - UT_PMEM2_EXPECT_RETURN(ret, PMEM2_E_MAPPING_EXISTS); - - /* unmap first mapping and close fds */ - ret = pmem2_map_delete(&map); - UT_ASSERTeq(ret, 0); - UT_ASSERTeq(map, NULL); - PMEM2_SOURCE_DELETE(&src); - UT_FH_CLOSE(fh); - UT_FH_CLOSE(fh_overlap); - - return 2; -} - /* * test_cases -- available test cases */ @@ -1106,10 +856,6 @@ static struct test_case test_cases[] = { TEST_CASE(test_map_sharing_private_with_reopened_fd), TEST_CASE(test_map_sharing_private_rdonly_file), TEST_CASE(test_map_sharing_private_devdax), - TEST_CASE(test_map_fixed_noreplace_valid), - TEST_CASE(test_map_fixed_noreplace_full_overlap), - TEST_CASE(test_map_fixed_noreplace_partial_overlap), - TEST_CASE(test_map_fixed_noreplace_partial_above_overlap), }; #define NTESTS (sizeof(test_cases) / sizeof(test_cases[0])) diff --git a/src/test/pmem2_vm_reservation/TESTS.py b/src/test/pmem2_vm_reservation/TESTS.py index d3d23bae3f503b862afdf79f6ea6dce95baa52f8..154256681254108493007a0b2918a07461dfde25 100755 --- a/src/test/pmem2_vm_reservation/TESTS.py +++ b/src/test/pmem2_vm_reservation/TESTS.py @@ -66,18 +66,42 @@ class PMEM2_VM_RESERVATION_ASYNC_DEVDAX(t.Test): class TEST0(PMEM2_VM_RESERVATION): - """create a vm reservation in the region belonging to existing mapping""" - test_case = "test_vm_reserv_new_region_occupied_map" + """create a vm reservation with unaligned address provided""" + test_case = "test_vm_reserv_new_unaligned_addr" class TEST1(PMEM2_VM_RESERVATION_DEVDAX): + """DevDax create a vm reservation with unaligned address provided""" + test_case = "test_vm_reserv_new_unaligned_addr" + + +class TEST2(PMEM2_VM_RESERVATION): + """create a vm reservation with unaligned size provided""" + test_case = "test_vm_reserv_new_unaligned_size" + + +class TEST3(PMEM2_VM_RESERVATION_DEVDAX): + """DevDax create a vm reservation with unaligned size provided""" + test_case = "test_vm_reserv_new_unaligned_size" + + +class TEST4(PMEM2_VM_RESERVATION): """ - DevDax create a vm reservation in the region belonging to existing mapping + map a file to the desired addr with the help of virtual + memory reservation """ - test_case = "test_vm_reserv_new_region_occupied_map" + test_case = "test_vm_reserv_new_valid_addr" -class TEST2(PMEM2_VM_RESERVATION): +class TEST5(PMEM2_VM_RESERVATION_DEVDAX): + """ + DevDax map a file to the desired addr with the help of virtual + memory reservation + """ + test_case = "test_vm_reserv_new_valid_addr" + + +class TEST6(PMEM2_VM_RESERVATION): """ create a vm reservation in the region belonging to other existing vm reservation @@ -85,7 +109,7 @@ class TEST2(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_new_region_occupied_reserv" -class TEST3(PMEM2_VM_RESERVATION_DEVDAX): +class TEST7(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax create a vm reservation in the region belonging to other existing vm reservation @@ -93,54 +117,81 @@ class TEST3(PMEM2_VM_RESERVATION_DEVDAX): test_case = "test_vm_reserv_new_region_occupied_reserv" -class TEST4(PMEM2_VM_RESERVATION): - """create a vm reservation with unaligned address provided""" - test_case = "test_vm_reserv_new_unaligned_addr" +class TEST8(PMEM2_VM_RESERVATION): + """ + create a vm reservation in the region overlapping whole existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map" -class TEST5(PMEM2_VM_RESERVATION_DEVDAX): - """DevDax create a vm reservation with unaligned address provided""" - test_case = "test_vm_reserv_new_unaligned_addr" +class TEST9(PMEM2_VM_RESERVATION_DEVDAX): + """ + DevDax create a vm reservation in the region overlapping + whole existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map" -class TEST6(PMEM2_VM_RESERVATION): - """create a vm reservation with unaligned size provided""" - test_case = "test_vm_reserv_new_unaligned_size" +class TEST10(PMEM2_VM_RESERVATION): + """ + create a reservation in the region overlapping lower half of + the existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map_below" -class TEST7(PMEM2_VM_RESERVATION_DEVDAX): - """DevDax create a vm reservation with unaligned size provided""" - test_case = "test_vm_reserv_new_unaligned_size" +class TEST11(PMEM2_VM_RESERVATION_DEVDAX): + """ + DevDax create a reservation in the region overlapping lower half of + the existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map_below" -class TEST8(PMEM2_VM_RESERVATION): +class TEST12(PMEM2_VM_RESERVATION): + """ + create a reservation in the region overlapping upper half of + the existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map_above" + + +class TEST13(PMEM2_VM_RESERVATION_DEVDAX): + """ + DevDax create a reservation in the region overlapping upper half of + the existing mapping + """ + test_case = "test_vm_reserv_new_region_occupied_map_above" + + +class TEST14(PMEM2_VM_RESERVATION): """create a vm reservation with with error injection""" test_case = "test_vm_reserv_new_alloc_enomem" -class TEST9(PMEM2_VM_RESERVATION_DEVDAX): +class TEST15(PMEM2_VM_RESERVATION_DEVDAX): """DevDax create a vm reservation with with error injection""" test_case = "test_vm_reserv_new_alloc_enomem" -class TEST10(PMEM2_VM_RESERVATION): +class TEST16(PMEM2_VM_RESERVATION): """map a file to a vm reservation""" test_case = "test_vm_reserv_map_file" -class TEST11(PMEM2_VM_RESERVATION_DEVDAX): +class TEST17(PMEM2_VM_RESERVATION_DEVDAX): """DevDax map a file to a vm reservation""" test_case = "test_vm_reserv_map_file" -class TEST12(PMEM2_VM_RESERVATION): +class TEST18(PMEM2_VM_RESERVATION): """ map a part of the file to a vm reservation smaller than the whole file """ test_case = "test_vm_reserv_map_part_file" -class TEST13(PMEM2_VM_RESERVATION_DEVDAX): +class TEST19(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax map a part of the file to a vm reservation smaller than the whole file @@ -148,33 +199,33 @@ class TEST13(PMEM2_VM_RESERVATION_DEVDAX): test_case = "test_vm_reserv_map_part_file" -class TEST14(PMEM2_VM_RESERVATION): +class TEST20(PMEM2_VM_RESERVATION): """delete a vm reservation that contains a mapping""" test_case = "test_vm_reserv_delete_contains_mapping" -class TEST15(PMEM2_VM_RESERVATION): +class TEST21(PMEM2_VM_RESERVATION): """delete a vm reservation with spoiled address""" test_case = "test_vm_reserv_delete_spoil_addr" -class TEST16(PMEM2_VM_RESERVATION_DEVDAX): +class TEST22(PMEM2_VM_RESERVATION_DEVDAX): """DevDax delete a vm reservation with spoiled address""" test_case = "test_vm_reserv_delete_spoil_addr" @t.windows_exclude -class TEST17(PMEM2_VM_RESERVATION): +class TEST23(PMEM2_VM_RESERVATION): """delete a vm reservation with spoiled size""" test_case = "test_vm_reserv_delete_spoil_size" -class TEST18(PMEM2_VM_RESERVATION_DEVDAX): +class TEST24(PMEM2_VM_RESERVATION_DEVDAX): """DevDax delete a vm reservation with spoiled size""" test_case = "test_vm_reserv_delete_spoil_size" -class TEST19(PMEM2_VM_RESERVATION): +class TEST25(PMEM2_VM_RESERVATION): """ map multiple files to a vm reservation, then unmap every 2nd mapping and map the mappings again @@ -182,7 +233,7 @@ class TEST19(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_map_unmap_multiple_files" -class TEST20(PMEM2_VM_RESERVATION_DEVDAX): +class TEST26(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax map multiple files to a vm reservation, then unmap every 2nd mapping and map the mappings again @@ -190,12 +241,12 @@ class TEST20(PMEM2_VM_RESERVATION_DEVDAX): test_case = "test_vm_reserv_map_unmap_multiple_files" -class TEST21(PMEM2_VM_RESERVATION): +class TEST27(PMEM2_VM_RESERVATION): """map a file to a vm reservation with insufficient space""" test_case = "test_vm_reserv_map_insufficient_space" -class TEST22(PMEM2_VM_RESERVATION): +class TEST28(PMEM2_VM_RESERVATION): """ map a file to a vm reservation and overlap whole other existing mapping belonging to the same reservation @@ -203,7 +254,7 @@ class TEST22(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_map_full_overlap" -class TEST23(PMEM2_VM_RESERVATION_DEVDAX): +class TEST29(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax map a file to a vm reservation and overlap whole other existing mapping belonging to the same reservation @@ -211,7 +262,7 @@ class TEST23(PMEM2_VM_RESERVATION_DEVDAX): test_case = "test_vm_reserv_map_full_overlap" -class TEST24(PMEM2_VM_RESERVATION): +class TEST30(PMEM2_VM_RESERVATION): """ map a file to a vm reservation overlapping with the ealier half of the other existing mapping @@ -219,7 +270,7 @@ class TEST24(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_map_partial_overlap_below" -class TEST25(PMEM2_VM_RESERVATION_DEVDAX): +class TEST31(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax map a file to a vm reservation overlapping with the ealier half of the other existing mapping @@ -227,7 +278,7 @@ class TEST25(PMEM2_VM_RESERVATION_DEVDAX): test_case = "test_vm_reserv_map_partial_overlap_below" -class TEST26(PMEM2_VM_RESERVATION): +class TEST32(PMEM2_VM_RESERVATION): """ map a file to a vm reservation overlapping with the latter half of the other existing mapping @@ -235,7 +286,7 @@ class TEST26(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_map_partial_overlap_above" -class TEST27(PMEM2_VM_RESERVATION_DEVDAX): +class TEST33(PMEM2_VM_RESERVATION_DEVDAX): """ DevDax map a file to a vm reservation overlapping with the latter half of the other existing mapping @@ -244,7 +295,7 @@ class TEST27(PMEM2_VM_RESERVATION_DEVDAX): @g.require_granularity(g.PAGE, g.CACHELINE) -class TEST28(PMEM2_VM_RESERVATION): +class TEST34(PMEM2_VM_RESERVATION): """ map a file with invalid granularity to a vm reservation in the middle of the vm reservation bigger than the file, then map a file that covers whole @@ -253,7 +304,7 @@ class TEST28(PMEM2_VM_RESERVATION): test_case = "test_vm_reserv_map_invalid_granularity" -class TEST29(PMEM2_VM_RESERVATION_ASYNC): +class TEST35(PMEM2_VM_RESERVATION_ASYNC): """ map and unmap asynchronously multiple times to the whole vm reservation region @@ -263,7 +314,7 @@ class TEST29(PMEM2_VM_RESERVATION_ASYNC): ops_per_thread = 10000 -class TEST30(PMEM2_VM_RESERVATION_ASYNC_DEVDAX): +class TEST36(PMEM2_VM_RESERVATION_ASYNC_DEVDAX): """ DevDax map and unmap asynchronously multiple times to the whole whole vm reservation region diff --git a/src/test/pmem2_vm_reservation/pmem2_vm_reservation.c b/src/test/pmem2_vm_reservation/pmem2_vm_reservation.c index 09d6eab61ee08efb0b50c386d8246ee451973537..33f43e2772cadd6254da4950e86f991a656c5838 100644 --- a/src/test/pmem2_vm_reservation/pmem2_vm_reservation.c +++ b/src/test/pmem2_vm_reservation/pmem2_vm_reservation.c @@ -56,9 +56,71 @@ offset_align_to_devdax(void *rsv_addr, size_t alignment) return 0; } +/* + * test_vm_reserv_new_valid_addr - map a file to the desired addr with the + * help of virtual memory reservation + */ +static int +test_vm_reserv_new_valid_addr(const struct test_case *tc, + int argc, char *argv[]) +{ + if (argc < 2) + UT_FATAL("usage: test_vm_reserv_new_valid_addr " + "<file> <size>"); + + char *file = argv[0]; + size_t size = ATOUL(argv[1]); + void *rsv_addr; + size_t rsv_size; + struct FHandle *fh; + struct pmem2_config cfg; + struct pmem2_map *map; + struct pmem2_vm_reservation *rsv; + struct pmem2_source *src; + + ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, 0, 0, FH_RDWR); + + int ret = pmem2_map_new(&map, &cfg, src); + UT_PMEM2_EXPECT_RETURN(ret, 0); + + rsv_addr = pmem2_map_get_address(map); + + /* unmap the mapping after getting the address */ + ret = pmem2_map_delete(&map); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(map, NULL); + + /* + * there's no need for padding in case of DevDax since the address + * we get from the first mapping is already aligned + */ + rsv_size = size; + + ret = pmem2_vm_reservation_new(&rsv, rsv_addr, rsv_size); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(pmem2_vm_reservation_get_address(rsv), rsv_addr); + UT_ASSERTeq(pmem2_vm_reservation_get_size(rsv), rsv_size); + + pmem2_config_set_vm_reservation(&cfg, rsv, 0); + + ret = pmem2_map_new(&map, &cfg, src); + UT_PMEM2_EXPECT_RETURN(ret, 0); + UT_ASSERTeq(pmem2_map_get_address(map), rsv_addr); + + ret = pmem2_map_delete(&map); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(map, NULL); + ret = pmem2_vm_reservation_delete(&rsv); + UT_ASSERTeq(ret, 0); + PMEM2_SOURCE_DELETE(&src); + UT_FH_CLOSE(fh); + + return 2; +} + /* * test_vm_reserv_new_region_occupied_map - create a reservation - * in the region belonging to existing mapping + * in the region overlapping whole existing mapping */ static int test_vm_reserv_new_region_occupied_map(const struct test_case *tc, @@ -99,6 +161,118 @@ test_vm_reserv_new_region_occupied_map(const struct test_case *tc, return 2; } +/* + * test_vm_reserv_new_region_occupied_map_below - create a reservation + * in the region overlapping lower half of the existing mapping + */ +static int +test_vm_reserv_new_region_occupied_map_below(const struct test_case *tc, + int argc, char *argv[]) +{ + if (argc < 2) + UT_FATAL("usage: test_vm_reserv_new_region_occupied_map_below " + "<file> <size>"); + + char *file = argv[0]; + size_t size = ATOUL(argv[1]); + size_t alignment = get_align_by_filename(file); + void *rsv_addr; + size_t rsv_size; + struct FHandle *fh; + struct pmem2_config cfg; + struct pmem2_map *map; + struct pmem2_vm_reservation *rsv; + struct pmem2_source *src; + + ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, 0, 0, FH_RDWR); + + int ret = pmem2_map_new(&map, &cfg, src); + UT_PMEM2_EXPECT_RETURN(ret, 0); + + /* + * address of the mapping is already aligned, we need to align + * the half of the size in case of DevDax + */ + rsv_addr = (char *)pmem2_map_get_address(map) - + ALIGN_UP(size / 2, alignment); + + /* + * there's no need for padding in case of DevDax since the address + * we get from the first mapping is already aligned + */ + rsv_size = size; + + ret = pmem2_vm_reservation_new(&rsv, rsv_addr, rsv_size); + UT_ASSERTeq(ret, PMEM2_E_MAPPING_EXISTS); + UT_ASSERTeq(rsv, NULL); + + /* unmap the mapping after getting the address */ + ret = pmem2_map_delete(&map); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(map, NULL); + + PMEM2_SOURCE_DELETE(&src); + UT_FH_CLOSE(fh); + + return 2; +} + +/* + * test_vm_reserv_new_region_occupied_map_above - create a reservation + * in the region overlapping upper half of the existing mapping + */ +static int +test_vm_reserv_new_region_occupied_map_above(const struct test_case *tc, + int argc, char *argv[]) +{ + if (argc < 2) + UT_FATAL("usage: test_vm_reserv_new_region_occupied_map_above " + "<file> <size>"); + + char *file = argv[0]; + size_t size = ATOUL(argv[1]); + size_t alignment = get_align_by_filename(file); + void *rsv_addr; + size_t rsv_size; + struct FHandle *fh; + struct pmem2_config cfg; + struct pmem2_map *map; + struct pmem2_vm_reservation *rsv; + struct pmem2_source *src; + + ut_pmem2_prepare_config(&cfg, &src, &fh, FH_FD, file, 0, 0, FH_RDWR); + + int ret = pmem2_map_new(&map, &cfg, src); + UT_PMEM2_EXPECT_RETURN(ret, 0); + + /* + * address of the mapping is already aligned, we need to align + * the half of the size in case of DevDax + */ + rsv_addr = (char *)pmem2_map_get_address(map) + + ALIGN_DOWN(size / 2, alignment); + + /* + * there's no need for padding in case of DevDax since the address + * we get from the first mapping is already aligned + */ + rsv_size = size; + + ret = pmem2_vm_reservation_new(&rsv, rsv_addr, rsv_size); + UT_ASSERTeq(ret, PMEM2_E_MAPPING_EXISTS); + UT_ASSERTeq(rsv, NULL); + + /* unmap the mapping after getting the address */ + ret = pmem2_map_delete(&map); + UT_ASSERTeq(ret, 0); + UT_ASSERTeq(map, NULL); + + PMEM2_SOURCE_DELETE(&src); + UT_FH_CLOSE(fh); + + return 2; +} + /* * test_vm_reserv_new_region_occupied_reserv - create a vm reservation * in the region belonging to other existing vm reservation @@ -968,10 +1142,13 @@ test_vm_reserv_async_map_unmap_multiple_files(const struct test_case *tc, * test_cases -- available test cases */ static struct test_case test_cases[] = { - TEST_CASE(test_vm_reserv_new_region_occupied_map), - TEST_CASE(test_vm_reserv_new_region_occupied_reserv), TEST_CASE(test_vm_reserv_new_unaligned_addr), TEST_CASE(test_vm_reserv_new_unaligned_size), + TEST_CASE(test_vm_reserv_new_valid_addr), + TEST_CASE(test_vm_reserv_new_region_occupied_map), + TEST_CASE(test_vm_reserv_new_region_occupied_map_below), + TEST_CASE(test_vm_reserv_new_region_occupied_map_above), + TEST_CASE(test_vm_reserv_new_region_occupied_reserv), TEST_CASE(test_vm_reserv_new_alloc_enomem), TEST_CASE(test_vm_reserv_map_file), TEST_CASE(test_vm_reserv_map_part_file), diff --git a/src/test/scope/out13.log.match b/src/test/scope/out13.log.match index c95fcca7cf796e49146e7e55a69e3f94050fc00e..322fe63bfb818604a739a44c704c4102574465b7 100644 --- a/src/test/scope/out13.log.match +++ b/src/test/scope/out13.log.match @@ -2,10 +2,8 @@ pmem2_badblock_clear$(nW) pmem2_badblock_context_delete$(nW) pmem2_badblock_context_new$(nW) pmem2_badblock_next$(nW) -pmem2_config_clear_address$(nW) pmem2_config_delete$(nW) pmem2_config_new$(nW) -pmem2_config_set_address$(nW) pmem2_config_set_length$(nW) pmem2_config_set_offset$(nW) pmem2_config_set_protection$(nW) diff --git a/src/test/scope/out14.log.match b/src/test/scope/out14.log.match index cbd0e079389c7463f901ef8f676b755d5d08f29f..a8907ea7a9fea815fcd05aff7851b1729e933e50 100644 --- a/src/test/scope/out14.log.match +++ b/src/test/scope/out14.log.match @@ -3,10 +3,8 @@ pmem2_badblock_clear pmem2_badblock_context_delete pmem2_badblock_context_new pmem2_badblock_next -pmem2_config_clear_address pmem2_config_delete pmem2_config_new -pmem2_config_set_address pmem2_config_set_length pmem2_config_set_offset pmem2_config_set_protection