Skip to content

Commit 327307a

Browse files
committed
Enable IPC API for FSDAX
FSDAX requires 2 MB page size. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 955ac33 commit 327307a

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/provider/provider_file_memory.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -687,30 +687,40 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
687687
umf_result_t ret = UMF_RESULT_SUCCESS;
688688
int fd;
689689

690+
size_t offset_aligned = file_ipc_data->offset_fd;
691+
size_t size_aligned = file_ipc_data->size;
692+
693+
if (file_provider->is_fsdax) {
694+
// It is just a workaround for case when
695+
// file_alloc() was called with the size argument
696+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
697+
utils_align_ptr_down_size_up((void **)&offset_aligned, &size_aligned,
698+
FSDAX_PAGE_SIZE_2MB);
699+
}
700+
690701
fd = utils_file_open(file_ipc_data->path);
691702
if (fd == -1) {
692703
LOG_PERR("opening the file to be mapped (%s) failed",
693704
file_ipc_data->path);
694705
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
695706
}
696707

697-
char *addr = utils_mmap_file(
698-
NULL, file_ipc_data->size, file_ipc_data->protection,
699-
file_ipc_data->visibility, fd, file_ipc_data->offset_fd);
708+
char *addr = utils_mmap_file(NULL, size_aligned, file_ipc_data->protection,
709+
file_ipc_data->visibility, fd, offset_aligned);
700710
(void)utils_close_fd(fd);
701711
if (addr == NULL) {
702712
file_store_last_native_error(UMF_FILE_RESULT_ERROR_ALLOC_FAILED, errno);
703713
LOG_PERR("file mapping failed (path: %s, size: %zu, protection: %i, "
704714
"fd: %i, offset: %zu)",
705-
file_ipc_data->path, file_ipc_data->size,
706-
file_ipc_data->protection, fd, file_ipc_data->offset_fd);
715+
file_ipc_data->path, size_aligned, file_ipc_data->protection,
716+
fd, offset_aligned);
707717
return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
708718
}
709719

710720
LOG_DEBUG("file mapped (path: %s, size: %zu, protection: %i, fd: %i, "
711721
"offset: %zu) at address %p",
712-
file_ipc_data->path, file_ipc_data->size,
713-
file_ipc_data->protection, fd, file_ipc_data->offset_fd, addr);
722+
file_ipc_data->path, size_aligned, file_ipc_data->protection, fd,
723+
offset_aligned, addr);
714724

715725
*ptr = addr;
716726

@@ -730,6 +740,13 @@ static umf_result_t file_close_ipc_handle(void *provider, void *ptr,
730740
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
731741
}
732742

743+
if (file_provider->is_fsdax) {
744+
// It is just a workaround for case when
745+
// file_alloc() was called with the size argument
746+
// that is not a multiplier of FSDAX_PAGE_SIZE_2MB.
747+
utils_align_ptr_down_size_up(&ptr, &size, FSDAX_PAGE_SIZE_2MB);
748+
}
749+
733750
errno = 0;
734751
int ret = utils_munmap(ptr, size);
735752
// ignore error when size == 0

0 commit comments

Comments
 (0)