Skip to content

Commit 4215c61

Browse files
committed
Fix open and close
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent ac1c7e0 commit 4215c61

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/provider/provider_devdax_memory.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,6 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
443443

444444
devdax_ipc_data_t *devdax_ipc_data = (devdax_ipc_data_t *)providerIpcData;
445445

446-
// length and offset passed to mmap() have to be page-aligned
447-
if (IS_NOT_ALIGNED(devdax_ipc_data->offset, DEVDAX_PAGE_SIZE_2MB)) {
448-
LOG_ERR("incorrect offset (%zu) in IPC handle - it is not page-aligned",
449-
devdax_ipc_data->offset);
450-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
451-
}
452-
453-
// length and offset passed to mmap() have to be page-aligned
454-
size_t length_aligned =
455-
ALIGN_UP(devdax_ipc_data->length, DEVDAX_PAGE_SIZE_2MB);
456-
457446
int fd = utils_devdax_open(devdax_ipc_data->path);
458447
if (fd == -1) {
459448
LOG_PERR("opening the devdax (%s) failed", devdax_ipc_data->path);
@@ -464,15 +453,26 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
464453
utils_translate_mem_visibility_flag(UMF_MEM_MAP_SYNC, &map_sync_flag);
465454

466455
// mmap /dev/dax with the MAP_SYNC xor MAP_SHARED flag (if MAP_SYNC fails)
467-
char *addr =
468-
utils_mmap_file(NULL, length_aligned, devdax_ipc_data->protection,
469-
map_sync_flag, fd, devdax_ipc_data->offset);
456+
char *addr = utils_mmap_file(NULL, devdax_ipc_data->length,
457+
devdax_ipc_data->protection, map_sync_flag, fd,
458+
devdax_ipc_data->offset);
470459
if (addr == NULL) {
471460
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_ALLOC_FAILED,
472461
errno);
462+
463+
if (IS_NOT_ALIGNED(devdax_ipc_data->offset, DEVDAX_PAGE_SIZE_2MB)) {
464+
LOG_WARN("offset (%zu) is not aligned to the page size (%zu)",
465+
devdax_ipc_data->offset, DEVDAX_PAGE_SIZE_2MB);
466+
}
467+
468+
if (IS_NOT_ALIGNED(devdax_ipc_data->length, DEVDAX_PAGE_SIZE_2MB)) {
469+
LOG_WARN("length (%zu) is not aligned to the page size (%zu)",
470+
devdax_ipc_data->length, DEVDAX_PAGE_SIZE_2MB);
471+
}
472+
473473
LOG_PERR("devdax mapping failed (path: %s, size: %zu, protection: %i, "
474474
"fd: %i, offset: %zu)",
475-
devdax_ipc_data->path, length_aligned,
475+
devdax_ipc_data->path, devdax_ipc_data->length,
476476
devdax_ipc_data->protection, fd, devdax_ipc_data->offset);
477477

478478
*ptr = NULL;
@@ -483,7 +483,7 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
483483

484484
LOG_DEBUG("devdax mapped (path: %s, size: %zu, protection: %i, fd: %i, "
485485
"offset: %zu) to address %p",
486-
devdax_ipc_data->path, length_aligned,
486+
devdax_ipc_data->path, devdax_ipc_data->length,
487487
devdax_ipc_data->protection, fd, devdax_ipc_data->offset, addr);
488488

489489
*ptr = addr;
@@ -499,15 +499,17 @@ static umf_result_t devdax_close_ipc_handle(void *provider, void *ptr,
499499
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
500500
}
501501

502-
// size passed to munmap() has to have the same value as in devdax_open_ipc_handle()
503-
size = ALIGN_UP(size, DEVDAX_PAGE_SIZE_2MB);
504-
505502
errno = 0;
506503
int ret = utils_munmap(ptr, size);
507504
// ignore error when size == 0
508505
if (ret && (size > 0)) {
509506
devdax_store_last_native_error(UMF_DEVDAX_RESULT_ERROR_FREE_FAILED,
510507
errno);
508+
if (IS_NOT_ALIGNED(size, DEVDAX_PAGE_SIZE_2MB)) {
509+
LOG_WARN("size (%zu) is not aligned to the page size (%zu)", size,
510+
DEVDAX_PAGE_SIZE_2MB);
511+
}
512+
511513
LOG_PERR("memory unmapping failed (ptr: %p, size: %zu)", ptr, size);
512514

513515
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;

0 commit comments

Comments
 (0)