@@ -107,6 +107,8 @@ fill_storage_path(char *storage_location, pdcid_t obj_id, uint64_t region_index)
107107 // Data file name s$pdc_server_rank_g$region_index$.bin
108108 snprintf (storage_location , ADDR_MAX , "%s/pdc_data/%" PRIu64 "/server%d/s%04d_%lu.bin" , data_path , obj_id ,
109109 pdc_server_rank_g , pdc_server_rank_g , region_index );
110+
111+ printf ("HERE\n" );
110112 PDC_mkdir (storage_location );
111113#ifdef ENABLE_LUSTRE
112114 if (pdc_nost_per_file_g != 1 )
@@ -380,8 +382,11 @@ PDC_Server_register_obj_region_by_pointer(data_server_region_t **new_obj_reg_ptr
380382
381383 FUNC_ENTER (NULL );
382384
385+ LOG_JUST_PRINT ("1\n" );
386+
383387 if (new_obj_reg == NULL ) {
384- new_obj_reg = (data_server_region_t * )malloc (sizeof (struct data_server_region_t ));
388+ LOG_JUST_PRINT ("2\n" );
389+ new_obj_reg = (data_server_region_t * )calloc (1 , sizeof (struct data_server_region_t ));
385390 if (new_obj_reg == NULL ) {
386391 ret_value = FAIL ;
387392 }
@@ -391,34 +396,33 @@ PDC_Server_register_obj_region_by_pointer(data_server_region_t **new_obj_reg_ptr
391396 new_obj_reg -> region_lock_request_head = NULL ;
392397 new_obj_reg -> region_storage_head = NULL ;
393398 new_obj_reg -> close_flag = close_flag ;
394- // FIXME: (Noah)
395- new_obj_reg -> storage_location [region_index ] = (char * )malloc (sizeof (char ) * ADDR_MAX );
399+ new_obj_reg -> storage_location [region_index ] = (char * )calloc (ADDR_MAX , sizeof (char ));
396400 new_obj_reg -> region_size_elements = UNITIALIZED_DATA_SERVER_REGION_SIZE_ELEMENTS ;
397401 new_obj_reg -> fd =
398402 server_open_storage (new_obj_reg -> storage_location [region_index ], obj_id , region_index );
399403
400404 if (new_obj_reg -> fd < 0 ) {
405+ LOG_ERROR ("Failed to open file %s\n" , new_obj_reg -> storage_location [region_index ]);
401406 goto done ;
402407 }
403408 DL_APPEND (dataserver_region_g , new_obj_reg );
404409 }
405410 else {
406- if (new_obj_reg -> fd == -1 ) {
407- // FIXME: (Noah)
408- new_obj_reg -> storage_location [region_index ] = (char * )malloc (sizeof (char ) * ADDR_MAX );
411+ LOG_JUST_PRINT ("3\n" );
412+ if (new_obj_reg -> storage_location [region_index ] == NULL ) {
413+ new_obj_reg -> storage_location [region_index ] = (char * )calloc (ADDR_MAX , sizeof (char ));
414+ }
415+ if (new_obj_reg -> storage_location [region_index ][0 ] == 0 ) {
409416 fill_storage_path (new_obj_reg -> storage_location [region_index ], obj_id , region_index );
410417 }
418+
411419 if (new_obj_reg -> fd < 0 ) {
412- if (new_obj_reg -> storage_location [region_index ] == NULL ) {
413- new_obj_reg -> storage_location [region_index ] = (char * )malloc (sizeof (char ) * ADDR_MAX );
414- fill_storage_path (new_obj_reg -> storage_location [region_index ], obj_id , region_index );
415- }
420+ LOG_JUST_PRINT ("4\n" );
416421 new_obj_reg -> close_flag = close_flag ;
417- // FIXME: (Noah)
418- new_obj_reg -> fd = open ( new_obj_reg -> storage_location [ region_index ], O_RDWR | O_CREAT , 0666 );
422+ new_obj_reg -> fd = server_open_storage ( new_obj_reg -> storage_location [ region_index ], obj_id , region_index );
423+
419424 if (new_obj_reg -> fd < 0 ) {
420425 LOG_ERROR ("Failed to open file %s\n" , new_obj_reg -> storage_location [region_index ]);
421- perror ("open" );
422426 goto done ;
423427 }
424428 }
@@ -435,11 +439,12 @@ PDC_Server_unregister_obj_region_by_pointer(data_server_region_t *new_obj_reg, i
435439 perr_t ret_value = SUCCEED ;
436440
437441 FUNC_ENTER (NULL );
438- if (new_obj_reg -> close_flag == close_flag && new_obj_reg != NULL ) {
442+ if (new_obj_reg != NULL && new_obj_reg -> close_flag == close_flag ) {
439443 close (new_obj_reg -> fd );
440444 new_obj_reg -> fd = -2 ;
441445 }
442446
447+ done :
443448 FUNC_LEAVE (ret_value );
444449} // End PDC_Server_unregister_obj_region
445450
@@ -4509,6 +4514,10 @@ typedef enum {
45094514 REGION_PER_FILE_IO_TYPE_WRITE ,
45104515} REGION_PER_FILE_IO_TYPE ;
45114516
4517+ static int is_fd_valid (int fd ) {
4518+ return fcntl (fd , F_GETFD ) != -1 || errno != EBADF ;
4519+ }
4520+
45124521static perr_t
45134522PDC_Server_data_io_from_region_per_file (uint64_t obj_id , struct pdc_region_info * region_info , void * buf ,
45144523 size_t unit , REGION_PER_FILE_IO_TYPE io_type )
@@ -4582,6 +4591,10 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45824591 // Register the initial region
45834592 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
45844593
4594+ if (region == NULL ) {
4595+ PGOTO_ERROR (FAIL , "Failed to register obj_region by pointer" );
4596+ }
4597+
45854598 if (region -> region_size_elements == UNITIALIZED_DATA_SERVER_REGION_SIZE_ELEMENTS ) {
45864599 region -> region_size_elements = num_elements ;
45874600 }
@@ -4593,7 +4606,7 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
45934606 }
45944607
45954608 for (uint64_t count = 0 ; count < num_elements ; count ++ ) {
4596- printf ("cur count: %d\n" , count );
4609+ // printf("\tcur count: %d\n", count);
45974610 // Compute flat index
45984611 uint64_t flat_index = 0 ;
45994612 uint64_t temp_stride = 1 ;
@@ -4608,10 +4621,18 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46084621 uint64_t old_region_size = region -> region_size_elements ;
46094622 if (region ) {
46104623 PDC_Server_unregister_obj_region_by_pointer (region , 0 );
4611- region = NULL ;
4624+ region -> fd = -1 ;
46124625 }
4626+ LOG_JUST_PRINT ("\told region index: %d\n" , region_index );
4627+ LOG_JUST_PRINT ("\tnew region index: %d\n" , new_region_index );
4628+ LOG_JUST_PRINT ("\tflat index: %d\n" , flat_index );
46134629 region_index = new_region_index ;
46144630 PDC_Server_register_obj_region_by_pointer (& region , obj_id , 0 , region_index );
4631+
4632+ if (region == NULL ) {
4633+ PGOTO_ERROR (FAIL , "Failed to register obj_region by pointer" );
4634+ }
4635+
46154636 region -> region_size_elements = old_region_size ;
46164637 }
46174638
@@ -4633,14 +4654,19 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46334654 }
46344655
46354656 if (res != (ssize_t )unit ) {
4657+ if (is_fd_valid (region -> fd )) {
4658+ LOG_JUST_PRINT ("region->fd was valid\n" );
4659+ } else {
4660+ LOG_JUST_PRINT ("region->fd %d was invalid\n" , region -> fd );
4661+ }
46364662 LOG_JUST_PRINT ("expected io size %d: actual io size %d\n" , unit , res );
46374663 LOG_JUST_PRINT ("region size %d, region index: %d\n" , region -> region_size_elements , region_index );
46384664 LOG_JUST_PRINT ("io error storage location: %s\n" , region -> storage_location [region_index ]);
46394665 perror (io_type == REGION_PER_FILE_IO_TYPE_READ ? "pread" : "pwrite" );
46404666 PGOTO_ERROR (FAIL , "I/O operation failed\n" );
46414667 }
46424668 else {
4643- LOG_JUST_PRINT ("io storage location: %s\n" , region -> storage_location [region_index ]);
4669+ // LOG_JUST_PRINT("\tio storage location: %s\n", region->storage_location[region_index]);
46444670 }
46454671
46464672 // Advance indices
@@ -4658,7 +4684,7 @@ PDC_Server_data_io_from_region_per_file(uint64_t obj_id, struct pdc_region_info
46584684done :
46594685 if (region ) {
46604686 PDC_Server_unregister_obj_region_by_pointer (region , 0 );
4661- region = NULL ;
4687+ region -> fd = -1 ;
46624688 }
46634689
46644690 if (indices )
0 commit comments