diff --git a/src/scr.c b/src/scr.c index 7152421e..4654c551 100644 --- a/src/scr.c +++ b/src/scr.c @@ -2120,7 +2120,7 @@ int SCR_Init() if (scr_my_rank_world == 0) { kvtree* nodes_hash = kvtree_new(); kvtree_util_set_int(nodes_hash, SCR_NODES_KEY_NODES, num_nodes); - kvtree_write_path(scr_nodes_file, nodes_hash); + kvtree_write_path_locked(scr_nodes_file, nodes_hash); kvtree_delete(&nodes_hash); } diff --git a/src/scr_flush_file.c b/src/scr_flush_file.c index 4bcd7ed8..10d850ec 100644 --- a/src/scr_flush_file.c +++ b/src/scr_flush_file.c @@ -220,7 +220,7 @@ int main (int argc, char *argv[]) kvtree* hash = kvtree_new(); /* read in our flush file */ - if (kvtree_read_file(file, hash) != KVTREE_SUCCESS) { + if (kvtree_read_with_lock(file, hash) != KVTREE_SUCCESS) { /* failed to read the flush file */ goto cleanup; } diff --git a/src/scr_flush_file_mpi.c b/src/scr_flush_file_mpi.c index 122d17f0..da9c5229 100644 --- a/src/scr_flush_file_mpi.c +++ b/src/scr_flush_file_mpi.c @@ -29,7 +29,7 @@ int scr_flush_file_need_flush(int id) if (scr_my_rank_world == 0) { /* read the flush file */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* if we have the dataset in cache, but not on the parallel file system, * then it needs to be flushed */ @@ -60,7 +60,7 @@ int scr_flush_file_is_flushing(int id) if (scr_my_rank_world == 0) { /* read flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* attempt to look up the FLUSHING state for this checkpoint */ kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); @@ -86,13 +86,13 @@ int scr_flush_file_dataset_remove(int id) if (scr_my_rank_world == 0) { /* read the flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* delete this dataset id from the flush file */ kvtree_unset_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); /* write the hash back to the flush file */ - kvtree_write_path(scr_flush_file, hash); + kvtree_write_path_locked(scr_flush_file, hash); /* delete the hash */ kvtree_delete(&hash); @@ -107,14 +107,14 @@ int scr_flush_file_location_set(int id, const char* location) if (scr_my_rank_world == 0) { /* read the flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* set the location for this dataset */ kvtree* dset_hash = kvtree_set_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); kvtree_set_kv(dset_hash, SCR_FLUSH_KEY_LOCATION, location); /* write the hash back to the flush file */ - kvtree_write_path(scr_flush_file, hash); + kvtree_write_path_locked(scr_flush_file, hash); /* delete the hash */ kvtree_delete(&hash); @@ -130,7 +130,7 @@ int scr_flush_file_location_test(int id, const char* location) if (scr_my_rank_world == 0) { /* read the flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* check the location for this dataset */ kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); @@ -157,14 +157,14 @@ int scr_flush_file_location_unset(int id, const char* location) if (scr_my_rank_world == 0) { /* read the flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* unset the location for this dataset */ kvtree* dset_hash = kvtree_get_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); kvtree_unset_kv(dset_hash, SCR_FLUSH_KEY_LOCATION, location); /* write the hash back to the flush file */ - kvtree_write_path(scr_flush_file, hash); + kvtree_write_path_locked(scr_flush_file, hash); /* delete the hash */ kvtree_delete(&hash); @@ -180,7 +180,7 @@ int scr_flush_file_new_entry(int id, const char* name, const scr_dataset* datase if (scr_my_rank_world == 0) { /* read the flush file into hash */ kvtree* hash = kvtree_new(); - kvtree_read_path(scr_flush_file, hash); + kvtree_read_path_locked(scr_flush_file, hash); /* set the name, location, and flags for this dataset */ kvtree* dset_hash = kvtree_set_kv_int(hash, SCR_FLUSH_KEY_DATASET, id); @@ -200,7 +200,7 @@ int scr_flush_file_new_entry(int id, const char* name, const scr_dataset* datase kvtree_set(dset_hash, SCR_FLUSH_KEY_DSETDESC, dataset_copy); /* write the hash back to the flush file */ - kvtree_write_path(scr_flush_file, hash); + kvtree_write_path_locked(scr_flush_file, hash); /* delete the hash */ kvtree_delete(&hash); diff --git a/src/scr_halt.c b/src/scr_halt.c index ff87e121..3de69c23 100644 --- a/src/scr_halt.c +++ b/src/scr_halt.c @@ -107,7 +107,7 @@ int scr_halt_sync_and_decrement(const spath* file_path, kvtree* hash, int dec_co } /* acquire a file lock before read/modify/write */ - int ret = scr_file_lock_read(file, fd); + int ret = scr_file_lock_write(file, fd); if (ret != SCR_SUCCESS) { scr_close(file,fd); rc = ret; diff --git a/src/scr_index.c b/src/scr_index.c index c58f0282..7707f0ea 100644 --- a/src/scr_index.c +++ b/src/scr_index.c @@ -271,7 +271,7 @@ int scr_summary_read(const spath* dir, kvtree* hash) } /* now attempt to read the file contents into the hash */ - if (kvtree_read_file(summary_file, hash) != KVTREE_SUCCESS) { + if (kvtree_read_with_lock(summary_file, hash) != KVTREE_SUCCESS) { rc = SCR_FAILURE; goto cleanup; } @@ -338,7 +338,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam kvtree_set_kv_int(entries, "RANKS", count); /* write hash to file rank2file part */ - if (kvtree_write_path(rank2file_path, entries) != KVTREE_SUCCESS) { + if (kvtree_write_path_locked(rank2file_path, entries) != KVTREE_SUCCESS) { rc = SCR_FAILURE; elem = NULL; } @@ -367,7 +367,7 @@ static int kvtree_write_scatter_file(const spath* meta_path, const char* filenam /* write out rank2file map */ spath* files_path = spath_dup(meta_path); spath_append_str(files_path, filename); - if (kvtree_write_path(files_path, files_hash) != KVTREE_SUCCESS) { + if (kvtree_write_path_locked(files_path, files_hash) != KVTREE_SUCCESS) { rc = SCR_FAILURE; } spath_delete(&files_path); @@ -397,7 +397,7 @@ int scr_summary_write(const spath* prefix, const spath* dir, kvtree* hash) /* write summary file */ spath* summary_path = spath_dup(meta_path); spath_append_str(summary_path, SCR_SUMMARY_FILENAME); - if (kvtree_write_path(summary_path, hash) != KVTREE_SUCCESS) { + if (kvtree_write_path_locked(summary_path, hash) != KVTREE_SUCCESS) { rc = SCR_FAILURE; } spath_delete(&summary_path); @@ -953,7 +953,7 @@ int scr_scan_flush(const spath* path_prefix, int dset_id, kvtree* scan) spath_append_str(flush_path, "flush.scr"); const char* flush_file = spath_strdup(flush_path); - if (kvtree_read_file(flush_file, flush) == KVTREE_SUCCESS) { + if (kvtree_read_with_lock(flush_file, flush) == KVTREE_SUCCESS) { /* copy dataset kvtree from flush file data */ kvtree* dataset = kvtree_new(); kvtree* hash = kvtree_get_kv_int(flush, SCR_FLUSH_KEY_DATASET, dset_id); diff --git a/src/scr_index_api.c b/src/scr_index_api.c index 992af991..7086d915 100644 --- a/src/scr_index_api.c +++ b/src/scr_index_api.c @@ -197,7 +197,7 @@ int scr_index_write(const spath* dir, kvtree* index) } /* write out the file */ - int kvtree_rc = kvtree_write_path(path_index, index); + int kvtree_rc = kvtree_write_path_locked(path_index, index); int rc = (kvtree_rc == KVTREE_SUCCESS) ? SCR_SUCCESS : SCR_FAILURE; /* free path */ diff --git a/src/scr_nodes_file.c b/src/scr_nodes_file.c index 1f281690..c6a8bb4c 100644 --- a/src/scr_nodes_file.c +++ b/src/scr_nodes_file.c @@ -114,7 +114,7 @@ int main (int argc, char *argv[]) kvtree* hash = kvtree_new(); /* read in our nodes file */ - if (kvtree_read_file(file_str, hash) != KVTREE_SUCCESS) { + if (kvtree_read_with_lock(file_str, hash) != KVTREE_SUCCESS) { /* failed to read the nodes file */ goto cleanup; } diff --git a/src/scr_summary.c b/src/scr_summary.c index ed56ff6c..6c58c58f 100644 --- a/src/scr_summary.c +++ b/src/scr_summary.c @@ -314,7 +314,7 @@ static int scr_summary_read_v5(const spath* dir, kvtree* summary_hash) } /* read in the summary hash file */ - if (kvtree_read_path(summary_path, summary_hash) != KVTREE_SUCCESS) { + if (kvtree_read_path_locked(summary_path, summary_hash) != KVTREE_SUCCESS) { scr_err("Reading summary file %s @ %s:%d", summary_file, __FILE__, __LINE__ ); @@ -484,7 +484,7 @@ int scr_summary_write(const spath* dir, const scr_dataset* dataset, int all_comp kvtree_util_set_int(rank2file_hash, SCR_SUMMARY_6_KEY_RANKS, scr_ranks_world); /* write the hash to a file */ - kvtree_write_path(summary_path, summary_hash); + kvtree_write_path_locked(summary_path, summary_hash); /* free the hash object */ kvtree_delete(&summary_hash); diff --git a/src/scr_util.c b/src/scr_util.c index 0f6f18b8..14a7a9ba 100644 --- a/src/scr_util.c +++ b/src/scr_util.c @@ -361,6 +361,22 @@ int kvtree_write_path(const spath* path, const kvtree* tree) return rc; } +int kvtree_read_path_locked(const spath* path, kvtree* tree) +{ + char* file = spath_strdup(path); + int rc = kvtree_read_with_lock(file, tree); + scr_free(&file); + return rc; +} + +int kvtree_write_path_locked(const spath* path, const kvtree* tree) +{ + char* file = spath_strdup(path); + int rc = kvtree_write_with_lock(file, tree); + scr_free(&file); + return rc; +} + /* given a string defining SCR_PREFIX value as given by user * return spath of fully qualified path, user should free */ spath* scr_get_prefix(const char* str) diff --git a/src/scr_util.h b/src/scr_util.h index 51208fca..daee7001 100644 --- a/src/scr_util.h +++ b/src/scr_util.h @@ -78,6 +78,12 @@ int kvtree_read_path(const spath* path, kvtree* tree); /* convenience to write kvtree to an spath */ int kvtree_write_path(const spath* path, const kvtree* tree); +/* convenience to read kvtree from an spath with a file read lock */ +int kvtree_read_path_locked(const spath* path, kvtree* tree); + +/* convenience to write kvtree to an spath with a file write lock */ +int kvtree_write_path_locked(const spath* path, const kvtree* tree); + /* given a string defining SCR_PREFIX value as given by user * return spath of fully qualified path, user should free */ spath* scr_get_prefix(const char* prefix);