@@ -499,8 +499,6 @@ PDC_Data_Server_region_lock(region_lock_in_t *in, region_lock_out_t *out, hg_han
499499 region_buf_map_t * eltt ;
500500 int error = 0 ;
501501 int found_lock = 0 ;
502- // time_t t;
503- // struct tm tm;
504502
505503 FUNC_ENTER (NULL );
506504
@@ -3334,10 +3332,8 @@ PDC_Server_add_region_storage_meta_to_bulk_buf(region_list_t *region, bulk_xfer_
33343332
33353333 // Sanity check
33363334 if (NULL == region || region -> storage_location [0 ] == 0 || NULL == region -> meta ) {
3337- LOG_ERROR ("==PDC_SERVER[%d]: invalid region data!\n" , pdc_server_rank_g );
33383335 PDC_print_region_list (region );
3339- ret_value = FAIL ;
3340- goto done ;
3336+ PGOTO_ERROR (FAIL , "==PDC_SERVER[%d]: invalid region data!\n" , pdc_server_rank_g );
33413337 }
33423338
33433339 // Alloc space and init if it's empty
@@ -4532,6 +4528,8 @@ is_fd_valid(int fd)
45324528 return fcntl (fd , F_GETFD ) != -1 || errno != EBADF ;
45334529}
45344530
4531+ #undef NOAH_DEBUG
4532+
45354533static perr_t
45364534PDC_Server_data_io_from_region_per_file (uint64_t obj_id , struct pdc_region_info * region_info , void * buf ,
45374535 size_t unit , REGION_PER_FILE_IO_TYPE io_type )
@@ -4540,6 +4538,7 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45404538
45414539 FUNC_ENTER (NULL );
45424540
4541+ #ifdef NOAH_DEBUG
45434542 LOG_JUST_PRINT ("===============================================\n" );
45444543 LOG_JUST_PRINT ("IO (%s) called with parameters:\n" ,
45454544 io_type == REGION_PER_FILE_IO_TYPE_READ ? "READ" : "WRITE" );
@@ -4552,6 +4551,7 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45524551 printf ("\tregion_info->offset[%d] = %" PRIu64 "\n" , i , region_info -> offset [i ]);
45534552 printf ("\tregion_info->size[%d] = %" PRIu64 "\n" , i , region_info -> size [i ]);
45544553 }
4554+ #endif
45554555
45564556 // Compute total number of elements
45574557 uint64_t num_elements = 1 ;
@@ -4573,10 +4573,12 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45734573 uint64_t * offset = region_info -> offset ;
45744574 int ndim = region_info -> ndim ;
45754575
4576+ #ifdef NOAH_DEBUG
45764577 LOG_JUST_PRINT ("\tobj meta ndim: %d\n" , ndim );
45774578 for (int i = 0 ; i < ndim ; i ++ ) {
45784579 LOG_JUST_PRINT ("\tobj meta dims[%d] = %" PRIu64 "\n" , i , global_size [i ]);
45794580 }
4581+ #endif
45804582
45814583 // Compute flat offset from global start
45824584 uint64_t flat_offset = 0 , stride = 1 ;
@@ -4585,11 +4587,14 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45854587 stride *= global_size [i ];
45864588 }
45874589
4590+ #ifdef NOAH_DEBUG
45884591 LOG_JUST_PRINT ("\tnum_elements: %d\n" , num_elements );
45894592 LOG_JUST_PRINT ("\tflat_offset: %d\n" , flat_offset );
4593+ #endif
45904594
45914595 // Determine initial region index
45924596 uint64_t region_index = 0 ;
4597+ uint64_t region_num_elements ;
45934598 if (region == NULL ) {
45944599 region_index = flat_offset / num_elements ;
45954600 }
@@ -4600,8 +4605,9 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46004605 region_index = flat_offset / region -> region_size_elements ;
46014606 }
46024607
4608+ #ifdef NOAH_DEBUG
46034609 LOG_JUST_PRINT ("\tregion_index: %d\n" , region_index );
4604-
4610+ #endif
46054611 // Register the initial region
46064612 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
46074613
@@ -4613,6 +4619,19 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46134619 region -> region_size_elements = num_elements ;
46144620 }
46154621
4622+ // Used to buffer I/O operations
4623+ uint8_t * buf_io_ops = (uint8_t * )malloc (region -> region_size_elements * unit );
4624+ errno = 0 ;
4625+ if (ftruncate (region -> fd , region -> region_size_elements * unit ) != 0 ) {
4626+ LOG_ERROR ("Error: %s\n" , strerror (errno ));
4627+ PGOTO_ERROR (FAIL , "Failed to tfruncate" );
4628+ }
4629+ errno = 0 ;
4630+ if (pread (region -> fd , buf_io_ops , region -> region_size_elements * unit , 0 ) != region -> region_size_elements * unit ) {
4631+ LOG_ERROR ("Error: %s\n" , strerror (errno ));
4632+ PGOTO_ERROR (FAIL , "Failed to pread" );
4633+ }
4634+
46164635 // Allocate indices for iteration
46174636 uint64_t * indices = (uint64_t * )calloc (ndim , sizeof (uint64_t ));
46184637 if (indices == NULL ) {
@@ -4633,15 +4652,29 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46334652 if (new_region_index != region_index ) {
46344653 uint64_t old_region_size = region -> region_size_elements ;
46354654 if (region ) {
4655+ pwrite (region -> fd , buf_io_ops , region -> region_size_elements * unit , 0 );
46364656 PDC_Server_unregister_obj_region_by_pointer (region , 0 );
46374657 region -> fd = -1 ;
46384658 }
4659+ #ifdef NOAH_DEBUG
46394660 LOG_JUST_PRINT ("\told region index: %d\n" , region_index );
46404661 LOG_JUST_PRINT ("\tnew region index: %d\n" , new_region_index );
46414662 LOG_JUST_PRINT ("\tflat index: %d\n" , flat_index );
4663+ #endif
46424664 region_index = new_region_index ;
46434665 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
46444666
4667+ errno = 0 ;
4668+ if (ftruncate (region -> fd , region -> region_size_elements * unit ) != 0 ) {
4669+ LOG_ERROR ("Error: %s\n" , strerror (errno ));
4670+ PGOTO_ERROR (FAIL , "Failed to tfruncate" );
4671+ }
4672+ errno = 0 ;
4673+ if (pread (region -> fd , buf_io_ops , region -> region_size_elements * unit , 0 ) != region -> region_size_elements * unit ) {
4674+ LOG_ERROR ("Error: %s\n" , strerror (errno ));
4675+ PGOTO_ERROR (FAIL , "Failed to pread" );
4676+ }
4677+
46454678 if (region == NULL ) {
46464679 PGOTO_ERROR (FAIL , "Failed to register obj_region by pointer" );
46474680 }
@@ -4657,27 +4690,11 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46574690 void * target_buf = (char * )buf + (count * unit );
46584691 off_t file_offset = offset_region * unit ;
46594692
4660- ssize_t res ;
4661- errno = 0 ;
46624693 if (io_type == REGION_PER_FILE_IO_TYPE_READ ) {
4663- res = pread ( region -> fd , target_buf , unit , file_offset );
4694+ memcpy ( target_buf , & ( buf_io_ops [ file_offset ]), unit );
46644695 }
46654696 else {
4666- res = pwrite (region -> fd , target_buf , unit , file_offset );
4667- }
4668-
4669- if (res != (ssize_t )unit ) {
4670- if (is_fd_valid (region -> fd )) {
4671- LOG_JUST_PRINT ("region->fd was valid\n" );
4672- }
4673- else {
4674- LOG_JUST_PRINT ("region->fd %d was invalid\n" , region -> fd );
4675- }
4676- LOG_JUST_PRINT ("expected io size %d: actual io size %d\n" , unit , res );
4677- LOG_JUST_PRINT ("region size %d, region index: %d\n" , region -> region_size_elements , region_index );
4678- LOG_JUST_PRINT ("io error storage location: %s\n" , region -> storage_location [region_index ]);
4679- perror (io_type == REGION_PER_FILE_IO_TYPE_READ ? "pread" : "pwrite" );
4680- PGOTO_ERROR (FAIL , "I/O operation failed\n" );
4697+ memcpy (& (buf_io_ops [file_offset ]), target_buf , unit );
46814698 }
46824699
46834700 // Advance indices
@@ -4694,14 +4711,18 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46944711
46954712done :
46964713 if (region ) {
4714+ pwrite (region -> fd , buf_io_ops , region -> region_size_elements * unit , 0 );
46974715 PDC_Server_unregister_obj_region_by_pointer (region , 0 );
46984716 region -> fd = -1 ;
46994717 }
4700-
47014718 if (indices )
47024719 free (indices );
4720+ if (buf_io_ops )
4721+ free (buf_io_ops );
47034722
4723+ #ifdef NOAH_DEBUG
47044724 LOG_JUST_PRINT ("===============================================\n" );
4725+ #endif
47054726
47064727 FUNC_LEAVE (ret_value );
47074728}
0 commit comments