@@ -139,21 +139,31 @@ static umf_result_t devdax_initialize(void *params, void **provider) {
139139 goto err_free_devdax_provider ;
140140 }
141141
142- unsigned map_sync_flag = 0 ;
143- utils_translate_mem_visibility_flag (UMF_MEM_MAP_SYNC , & map_sync_flag );
142+ bool is_dax = false;
144143
145- // mmap /dev/dax with the MAP_SYNC xor MAP_SHARED flag (if MAP_SYNC fails)
144+ // mmap /dev/dax with the MAP_SYNC
146145 devdax_provider -> base = utils_mmap_file (
147- NULL , devdax_provider -> size , devdax_provider -> protection , map_sync_flag ,
148- fd , 0 /* offset */ , NULL );
146+ NULL , devdax_provider -> size , devdax_provider -> protection , 0 /* flags */ ,
147+ fd , 0 /* offset */ , & is_dax );
149148 utils_close_fd (fd );
150149 if (devdax_provider -> base == NULL ) {
151- LOG_PDEBUG ("devdax memory mapping failed (path=%s, size=%zu)" ,
150+ LOG_PDEBUG ("mapping the devdax failed (path=%s, size=%zu)" ,
152151 in_params -> path , devdax_provider -> size );
153152 ret = UMF_RESULT_ERROR_UNKNOWN ;
154153 goto err_free_devdax_provider ;
155154 }
156155
156+ if (!is_dax ) {
157+ LOG_ERR ("mapping the devdax with MAP_SYNC failed: %s" , in_params -> path );
158+ ret = UMF_RESULT_ERROR_UNKNOWN ;
159+
160+ if (devdax_provider -> base ) {
161+ utils_munmap (devdax_provider -> base , devdax_provider -> size );
162+ }
163+
164+ goto err_free_devdax_provider ;
165+ }
166+
157167 LOG_DEBUG ("devdax memory mapped (path=%s, size=%zu, addr=%p)" ,
158168 in_params -> path , devdax_provider -> size , devdax_provider -> base );
159169
@@ -433,6 +443,8 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
433443 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
434444 }
435445
446+ * ptr = NULL ;
447+
436448 devdax_ipc_data_t * devdax_ipc_data = (devdax_ipc_data_t * )providerIpcData ;
437449
438450 int fd = utils_devdax_open (devdax_ipc_data -> path );
@@ -441,9 +453,6 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
441453 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
442454 }
443455
444- unsigned map_sync_flag = 0 ;
445- utils_translate_mem_visibility_flag (UMF_MEM_MAP_SYNC , & map_sync_flag );
446-
447456 // It is just a workaround for case when
448457 // devdax_alloc() was called with the size argument
449458 // that is not a multiplier of DEVDAX_PAGE_SIZE_2MB.
@@ -452,34 +461,42 @@ static umf_result_t devdax_open_ipc_handle(void *provider,
452461 utils_align_ptr_down_size_up ((void * * )& offset_aligned , & length_aligned ,
453462 DEVDAX_PAGE_SIZE_2MB );
454463
455- // mmap /dev/dax with the MAP_SYNC xor MAP_SHARED flag (if MAP_SYNC fails)
464+ bool is_dax = false;
465+
466+ // mmap /dev/dax with the MAP_SYNC
456467 char * addr =
457468 utils_mmap_file (NULL , length_aligned , devdax_ipc_data -> protection ,
458- map_sync_flag , fd , offset_aligned , NULL );
469+ 0 /* flags */ , fd , offset_aligned , & is_dax );
470+ (void )utils_close_fd (fd );
459471 if (addr == NULL ) {
460- devdax_store_last_native_error (UMF_DEVDAX_RESULT_ERROR_ALLOC_FAILED ,
461- errno );
462-
463472 LOG_PERR ("devdax mapping failed (path: %s, size: %zu, protection: %i, "
464473 "fd: %i, offset: %zu)" ,
465474 devdax_ipc_data -> path , length_aligned ,
466475 devdax_ipc_data -> protection , fd , offset_aligned );
467476
468- * ptr = NULL ;
469- (void )utils_close_fd (fd );
470-
477+ devdax_store_last_native_error (UMF_DEVDAX_RESULT_ERROR_ALLOC_FAILED ,
478+ errno );
471479 return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
472480 }
473481
482+ if (!is_dax ) {
483+ LOG_ERR ("mapping the devdax with MAP_SYNC failed: %s" ,
484+ devdax_ipc_data -> path );
485+
486+ if (addr ) {
487+ utils_munmap (addr , length_aligned );
488+ }
489+
490+ return UMF_RESULT_ERROR_UNKNOWN ;
491+ }
492+
474493 LOG_DEBUG ("devdax mapped (path: %s, size: %zu, protection: %i, fd: %i, "
475494 "offset: %zu) to address %p" ,
476495 devdax_ipc_data -> path , length_aligned ,
477496 devdax_ipc_data -> protection , fd , offset_aligned , addr );
478497
479498 * ptr = addr ;
480499
481- (void )utils_close_fd (fd );
482-
483500 return UMF_RESULT_SUCCESS ;
484501}
485502
0 commit comments