@@ -116,7 +116,7 @@ static int darshan_should_instrument_rank(
116116 struct darshan_core_runtime * core );
117117static void darshan_fs_info_from_path (
118118 const char * path , struct darshan_fs_info * fs_info );
119- static int darshan_add_name_record_ref (
119+ static int darshan_update_name_record_ref (
120120 struct darshan_core_runtime * core , darshan_record_id rec_id ,
121121 const char * name , darshan_module_id mod_id );
122122static void darshan_get_user_name (
@@ -1301,51 +1301,87 @@ static void darshan_fs_info_from_path(const char *path, struct darshan_fs_info *
13011301 return ;
13021302}
13031303
1304- static int darshan_add_name_record_ref (struct darshan_core_runtime * core ,
1304+ static int darshan_update_name_record_ref (struct darshan_core_runtime * core ,
13051305 darshan_record_id rec_id , const char * name , darshan_module_id mod_id )
13061306{
1307- struct darshan_core_name_record_ref * ref ;
1308- struct darshan_core_name_record_ref * check_ref ;
1309- int record_size = sizeof (darshan_record_id ) + strlen (name ) + 1 ;
1307+ int is_new_rec = 0 ;
1308+ struct darshan_core_name_record_ref * ref , * check_ref ;
13101309
1311- if (( record_size + core -> name_mem_used ) > core -> config . name_mem )
1312- return ( 0 ) ;
1310+ /* if no name given, use the empty string */
1311+ if (! name ) name = "" ;
13131312
1314- /* drop core lock while we allocate reference. Note that
1315- * this means we must check for existence again in hash table once we
1316- * re-acquire the lock, but this code path will only happen once per
1317- * file.
1318- */
1319- __DARSHAN_CORE_UNLOCK ();
1320- ref = malloc (sizeof (* ref ));
1321- __DARSHAN_CORE_LOCK ();
1313+ /* check to see if we've already stored the id->name mapping for this record */
1314+ HASH_FIND (hlink , core -> name_hash , & rec_id , sizeof (rec_id ), ref );
13221315 if (!ref )
13231316 {
1324- return (0 );
1325- }
1326- memset (ref , 0 , sizeof (* ref ));
1317+ /* drop core lock while we allocate reference. Note that
1318+ * this means we must check for existence again in hash table once we
1319+ * re-acquire the lock, but this code path will only happen once per
1320+ * file.
1321+ */
1322+ __DARSHAN_CORE_UNLOCK ();
1323+ ref = malloc (sizeof (* ref ));
1324+ __DARSHAN_CORE_LOCK ();
1325+ if (!ref )
1326+ {
1327+ return (0 );
1328+ }
1329+ memset (ref , 0 , sizeof (* ref ));
13271330
1328- /* make sure no one else added it while we dropped the lock */
1329- HASH_FIND (hlink , core -> name_hash , & rec_id ,
1330- sizeof (darshan_record_id ), check_ref );
1331- if (check_ref )
1332- return (1 );
1331+ HASH_FIND (hlink , core -> name_hash , & rec_id , sizeof (rec_id ), check_ref );
1332+ if (check_ref )
1333+ {
1334+ /* someone else added the ref while we dropped the lock */
1335+ free (ref );
1336+ ref = check_ref ;
1337+ }
1338+ else
1339+ {
1340+ /* we need to allocate and add a new record ref */
1341+ is_new_rec = 1 ;
1342+ }
1343+ }
13331344
1334- /* initialize the name record */
1335- ref -> name_record = (struct darshan_name_record * )
1336- ((char * )core -> log_name_p + core -> name_mem_used );
1337- memset (ref -> name_record , 0 , record_size );
1338- ref -> name_record -> id = rec_id ;
1339- strcpy (ref -> name_record -> name , name );
1340- DARSHAN_MOD_FLAG_SET (ref -> mod_flags , mod_id );
1345+ /* set a new name record reference in 2 scenarios:
1346+ * 1.) creation of a new record ref
1347+ * 2.) detecting zero-length name on an existing record ref
1348+ * (i.e., initial creator of the ref didn't specify a name)
1349+ */
1350+ if (is_new_rec || ((strlen (ref -> name_record -> name ) == 0 ) && strlen (name ) > 0 ))
1351+ {
1352+ int record_size = sizeof (darshan_record_id ) + strlen (name ) + 1 ;
1353+ if ((record_size + core -> name_mem_used ) > core -> config .name_mem )
1354+ {
1355+ /* no more room for this name record */
1356+ if (is_new_rec ) free (ref );
1357+ return (0 );
1358+ }
1359+ else
1360+ {
1361+ /* initialize new name record structure */
1362+ ref -> name_record = (struct darshan_name_record * )
1363+ ((char * )core -> log_name_p + core -> name_mem_used );
1364+ memset (ref -> name_record , 0 , record_size );
1365+ ref -> name_record -> id = rec_id ;
1366+ strcpy (ref -> name_record -> name , name );
13411367
1342- HASH_ADD (hlink , core -> name_hash , name_record -> id ,
1343- sizeof (darshan_record_id ), ref );
1344- core -> name_mem_used += record_size ;
1368+ core -> name_mem_used += record_size ;
13451369#ifdef __DARSHAN_ENABLE_MMAP_LOGS
1346- core -> log_hdr_p -> name_map .len += record_size ;
1370+ core -> log_hdr_p -> name_map .len += record_size ;
13471371#endif
1372+ }
1373+ }
1374+
1375+ DARSHAN_MOD_FLAG_SET (ref -> mod_flags , mod_id );
13481376
1377+ if (is_new_rec )
1378+ {
1379+ /* add new record reference */
1380+ HASH_ADD (hlink , core -> name_hash , name_record -> id ,
1381+ sizeof (darshan_record_id ), ref );
1382+ }
1383+
1384+ /* successfully updated core record ref */
13491385 return (1 );
13501386}
13511387
@@ -2207,6 +2243,9 @@ static int darshan_core_name_is_excluded(const char *name, darshan_module_id mod
22072243 int tmp_index = 0 ;
22082244 struct darshan_core_regex * regex ;
22092245
2246+ if (!name )
2247+ return (0 );
2248+
22102249 /* set flag if this module's record names are based on file paths */
22112250 name_is_path = 1 ;
22122251 if ((mod_id == DARSHAN_APMPI_MOD ) || (mod_id == DARSHAN_APXC_MOD ) ||
@@ -2606,9 +2645,7 @@ void *darshan_core_register_record(
26062645 size_t rec_size ,
26072646 struct darshan_fs_info * fs_info )
26082647{
2609- struct darshan_core_name_record_ref * ref ;
26102648 void * rec_buf ;
2611- int ret ;
26122649
26132650 __DARSHAN_CORE_LOCK ();
26142651 if (!__darshan_core )
@@ -2625,35 +2662,19 @@ void *darshan_core_register_record(
26252662 return (NULL );
26262663 }
26272664
2628- /* register a name record if a name is given for this record */
2629- if (name )
2665+ if (darshan_core_name_is_excluded (name , mod_id ))
26302666 {
2631- if (darshan_core_name_is_excluded (name , mod_id ))
2632- {
2633- /* do not register record if name matches any exclusion rules */
2634- __DARSHAN_CORE_UNLOCK ();
2635- return (NULL );
2636- }
2667+ /* do not register record if name matches any exclusion rules */
2668+ __DARSHAN_CORE_UNLOCK ();
2669+ return (NULL );
26372670 }
26382671
2639- /* check to see if we've already stored the id->name mapping for
2640- * this record, and add a new name record if not
2641- */
2642- HASH_FIND (hlink , __darshan_core -> name_hash , & rec_id ,
2643- sizeof (darshan_record_id ), ref );
2644- if (!ref )
2672+ if (!darshan_update_name_record_ref (__darshan_core , rec_id , name , mod_id ))
26452673 {
2646- ret = darshan_add_name_record_ref (__darshan_core , rec_id , name , mod_id );
2647- if (ret == 0 )
2648- {
2649- DARSHAN_MOD_FLAG_SET (__darshan_core -> log_hdr_p -> partial_flag , mod_id );
2650- __DARSHAN_CORE_UNLOCK ();
2651- return (NULL );
2652- }
2653- }
2654- else
2655- {
2656- DARSHAN_MOD_FLAG_SET (ref -> mod_flags , mod_id );
2674+ /* unable to update record ref, fail and set this module's partial flag */
2675+ DARSHAN_MOD_FLAG_SET (__darshan_core -> log_hdr_p -> partial_flag , mod_id );
2676+ __DARSHAN_CORE_UNLOCK ();
2677+ return (NULL );
26572678 }
26582679
26592680 __darshan_core -> mod_array [mod_id ]-> rec_mem_avail -= rec_size ;
@@ -2683,7 +2704,7 @@ void *darshan_core_register_record(
26832704 if (fs_info )
26842705 darshan_fs_info_from_path (name , fs_info );
26852706
2686- return (rec_buf );;
2707+ return (rec_buf );
26872708}
26882709
26892710char * darshan_core_lookup_record_name (darshan_record_id rec_id )
0 commit comments