3737#include <math.h>
3838#include <sys/shm.h>
3939#include <sys/mman.h>
40+ #include <errno.h>
4041
4142#include "pdc_config.h"
4243
@@ -126,7 +127,16 @@ static int
126127server_open_storage (char * storage_location , pdcid_t obj_id , uint64_t region_index )
127128{
128129 fill_storage_path (storage_location , obj_id , region_index );
129- return open (storage_location , O_RDWR | O_CREAT , 0666 );
130+
131+ errno = 0 ;
132+ int fd = open (storage_location , O_RDWR | O_CREAT , 0666 );
133+
134+ if (fd <= 0 ) {
135+ LOG_ERROR ("Failed to open file: %s\n" , storage_location );
136+ perror ("open" );
137+ }
138+
139+ return fd ;
130140}
131141
132142perr_t
@@ -395,6 +405,7 @@ PDC_Server_register_obj_region_by_pointer(data_server_region_t **new_obj_reg_ptr
395405 else {
396406 if (new_obj_reg -> fd == -1 ) {
397407 // FIXME: (Noah)
408+ new_obj_reg -> storage_location [region_index ] = (char * )malloc (sizeof (char ) * ADDR_MAX );
398409 fill_storage_path (new_obj_reg -> storage_location [region_index ], obj_id , region_index );
399410 }
400411 if (new_obj_reg -> fd < 0 ) {
@@ -406,6 +417,8 @@ PDC_Server_register_obj_region_by_pointer(data_server_region_t **new_obj_reg_ptr
406417 // FIXME: (Noah)
407418 new_obj_reg -> fd = open (new_obj_reg -> storage_location [region_index ], O_RDWR | O_CREAT , 0666 );
408419 if (new_obj_reg -> fd < 0 ) {
420+ LOG_ERROR ("Failed to open file %s\n" , new_obj_reg -> storage_location [region_index ]);
421+ perror ("open" );
409422 goto done ;
410423 }
411424 }
@@ -4536,9 +4549,9 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45364549 uint64_t * offset = region_info -> offset ;
45374550 int ndim = region_info -> ndim ;
45384551
4539- printf ("\tobj meta ndim: %d\n" , ndim );
4552+ LOG_JUST_PRINT ("\tobj meta ndim: %d\n" , ndim );
45404553 for (int i = 0 ; i < ndim ; i ++ ) {
4541- printf ("\tobj meta dims[%d] = %" PRIu64 "\n" , i , global_size [i ]);
4554+ LOG_JUST_PRINT ("\tobj meta dims[%d] = %" PRIu64 "\n" , i , global_size [i ]);
45424555 }
45434556
45444557 // Compute flat offset from global start
@@ -4547,25 +4560,38 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45474560 flat_offset += offset [i ] * stride ;
45484561 stride *= global_size [i ];
45494562 }
4563+
4564+ LOG_JUST_PRINT ("\tnum_elements: %d\n" , num_elements );
4565+ LOG_JUST_PRINT ("\tflat_offset: %d\n" , flat_offset );
45504566
45514567 // Determine initial region index
45524568 uint64_t region_index = 0 ;
45534569 if (region == NULL ) {
4554- region_index = 0 ;
4570+ region_index = flat_offset / num_elements ;
45554571 } else {
4572+ if (region -> region_size_elements == UNITIALIZED_DATA_SERVER_REGION_SIZE_ELEMENTS ) {
4573+ region -> region_size_elements = num_elements ;
4574+ }
45564575 region_index = flat_offset / region -> region_size_elements ;
45574576 }
45584577
4578+ LOG_JUST_PRINT ("\tregion_index: %d\n" , region_index );
4579+
45594580 // Register the initial region
45604581 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
45614582
4583+ if (region -> region_size_elements == UNITIALIZED_DATA_SERVER_REGION_SIZE_ELEMENTS ) {
4584+ region -> region_size_elements = num_elements ;
4585+ }
4586+
45624587 // Allocate indices for iteration
45634588 uint64_t * indices = (uint64_t * )calloc (ndim , sizeof (uint64_t ));
45644589 if (indices == NULL ) {
45654590 PGOTO_ERROR (FAIL , "calloc failed for indices" );
45664591 }
45674592
45684593 for (uint64_t count = 0 ; count < num_elements ; count ++ ) {
4594+ printf ("cur count: %d\n" , count );
45694595 // Compute flat index
45704596 uint64_t flat_index = 0 ;
45714597 uint64_t temp_stride = 1 ;
@@ -4577,33 +4603,40 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45774603 // Determine region
45784604 uint64_t new_region_index = flat_index / region -> region_size_elements ;
45794605 if (new_region_index != region_index ) {
4606+ uint64_t old_region_size = region -> region_size_elements ;
45804607 if (region ) {
45814608 PDC_Server_unregister_obj_region_by_pointer (region , 0 );
45824609 region = NULL ;
45834610 }
45844611 region_index = new_region_index ;
45854612 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
4613+ region -> region_size_elements = old_region_size ;
45864614 }
45874615
45884616 if (region == NULL || region -> region_size_elements == 0 ) {
45894617 PGOTO_ERROR (FAIL , "Region not properly initialized" );
45904618 }
45914619
4592- // Compute offset within region
45934620 uint64_t offset_region = flat_index % region -> region_size_elements ;
45944621 void * target_buf = (char * )buf + (count * unit );
45954622 off_t file_offset = offset_region * unit ;
45964623
45974624 ssize_t res ;
4625+ errno = 0 ;
45984626 if (io_type == REGION_PER_FILE_IO_TYPE_READ ) {
45994627 res = pread (region -> fd , target_buf , unit , file_offset );
46004628 } else {
46014629 res = pwrite (region -> fd , target_buf , unit , file_offset );
46024630 }
46034631
46044632 if (res != (ssize_t )unit ) {
4633+ LOG_JUST_PRINT ("expected io size %d: actual io size %d\n" , unit , res );
4634+ LOG_JUST_PRINT ("region size %d, region index: %d\n" , region -> region_size_elements , region_index );
4635+ LOG_JUST_PRINT ("io error storage location: %s\n" , region -> storage_location [region_index ]);
46054636 perror (io_type == REGION_PER_FILE_IO_TYPE_READ ? "pread" : "pwrite" );
4606- PGOTO_ERROR (FAIL , "I/O operation failed" );
4637+ PGOTO_ERROR (FAIL , "I/O operation failed\n" );
4638+ } else {
4639+ LOG_JUST_PRINT ("io storage location: %s\n" , region -> storage_location [region_index ]);
46074640 }
46084641
46094642 // Advance indices
0 commit comments