static int builtin_posix_module_dataset_close (hio_dataset_t dataset) { builtin_posix_module_dataset_t *posix_dataset = (builtin_posix_module_dataset_t *) dataset; builtin_posix_module_t *posix_module = (builtin_posix_module_t *) dataset->ds_module; hio_context_t context = hioi_object_context ((hio_object_t) dataset); hio_module_t *module = dataset->ds_module; unsigned char *manifest; uint64_t start, stop; int rc = HIO_SUCCESS; size_t manifest_size; start = hioi_gettime (); for (int i = 0 ; i < HIO_POSIX_MAX_OPEN_FILES ; ++i) { if (posix_dataset->files[i].f_file.f_hndl != NULL) { fclose (posix_dataset->files[i].f_file.f_hndl); posix_dataset->files[i].f_file.f_hndl = NULL; } } if (dataset->ds_flags & HIO_FLAG_WRITE) { rc = hioi_dataset_gather_manifest (dataset, &manifest, &manifest_size, dataset->ds_use_bzip); if (HIO_SUCCESS != rc) { dataset->ds_status = rc; } if (0 == context->c_rank) { char *path; rc = asprintf (&path, "%s/manifest.json%s", posix_dataset->base_path, dataset->ds_use_bzip ? ".bz2" : ""); if (0 < rc) { int fd; errno = 0; fd = open (path, O_CREAT | O_WRONLY, posix_module->access_mode); if (0 <= fd) { (void) write (fd, manifest, manifest_size); close (fd); } free (manifest); rc = hioi_err_errno (errno); free (path); if (HIO_SUCCESS != rc) { hioi_err_push (rc, &dataset->ds_object, "posix: error writing dataset manifest"); } } else { rc = HIO_ERR_OUT_OF_RESOURCE; } } } #if HIO_USE_MPI /* ensure all ranks have closed the dataset before continuing */ if (hioi_context_using_mpi (context)) { MPI_Allreduce (MPI_IN_PLACE, &rc, 1, MPI_INT, MPI_MIN, context->c_comm); } #endif free (posix_dataset->base_path); pthread_mutex_destroy (&posix_dataset->lock); stop = hioi_gettime (); hioi_log (context, HIO_VERBOSE_DEBUG_LOW, "posix:dataset_open: successfully closed posix dataset %s:%llu on data root %s. " "close time %lu usec", hioi_object_identifier(dataset), dataset->ds_id, module->data_root, stop - start); return rc; }
static int builtin_posix_module_dataset_close (hio_dataset_t dataset) { builtin_posix_module_dataset_t *posix_dataset = (builtin_posix_module_dataset_t *) dataset; hio_context_t context = hioi_object_context ((hio_object_t) dataset); hio_module_t *module = dataset->ds_module; unsigned char *manifest = NULL; uint64_t start, stop; int rc = HIO_SUCCESS; size_t manifest_size; start = hioi_gettime (); for (int i = 0 ; i < HIO_POSIX_MAX_OPEN_FILES ; ++i) { if (posix_dataset->files[i].f_bid >= 0) { POSIX_TRACE_CALL(posix_dataset, hioi_file_close (posix_dataset->files + i), "file_close", posix_dataset->files[i].f_bid, 0); } } #if HIO_MPI_HAVE(3) /* release the shared state if it was allocated */ (void) hioi_dataset_shared_fini (dataset); /* release the dataset map if one was allocated */ (void) hioi_dataset_map_release (dataset); #endif if (dataset->ds_flags & HIO_FLAG_WRITE) { char *path; /* write manifest header */ POSIX_TRACE_CALL(posix_dataset, rc = hioi_dataset_gather_manifest (dataset, &manifest, &manifest_size, false, true), "gather_manifest", 0, 0); if (HIO_SUCCESS != rc) { dataset->ds_status = rc; } if (0 == context->c_rank) { rc = asprintf (&path, "%s/manifest.json", posix_dataset->base_path); if (0 > rc) { /* out of memory. not much we can do now */ return hioi_err_errno (errno); } rc = hioi_manifest_save (dataset, manifest, manifest_size, path); free (manifest); free (path); if (HIO_SUCCESS != rc) { hioi_err_push (rc, &dataset->ds_object, "posix: error writing dataset manifest"); } } #if HIO_MPI_HAVE(3) if (HIO_FILE_MODE_OPTIMIZED == posix_dataset->ds_fmode) { /* optimized mode requires a data manifest to describe how the data landed on the filesystem */ POSIX_TRACE_CALL(posix_dataset, rc = hioi_dataset_gather_manifest_comm (dataset, context->c_shared_comm, &manifest, &manifest_size, posix_dataset->ds_use_bzip, false), "gather_manifest", 0, 0); if (HIO_SUCCESS != rc) { dataset->ds_status = rc; } if (NULL != manifest) { rc = asprintf (&path, "%s/manifest.%x.json%s", posix_dataset->base_path, context->c_rank, posix_dataset->ds_use_bzip ? ".bz2" : ""); if (0 > rc) { return hioi_err_errno (errno); } rc = hioi_manifest_save (dataset, manifest, manifest_size, path); free (manifest); free (path); if (HIO_SUCCESS != rc) { hioi_err_push (rc, &dataset->ds_object, "posix: error writing dataset manifest"); } } } #endif } #if HIO_MPI_HAVE(1) /* ensure all ranks have closed the dataset before continuing */ if (hioi_context_using_mpi (context)) { MPI_Allreduce (MPI_IN_PLACE, &rc, 1, MPI_INT, MPI_MIN, context->c_comm); } #endif free (posix_dataset->base_path); stop = hioi_gettime (); builtin_posix_trace (posix_dataset, "close", 0, 0, start, stop); hioi_log (context, HIO_VERBOSE_DEBUG_LOW, "posix:dataset_open: successfully closed posix dataset " "%s:%" PRIu64 " on data root %s. close time %" PRIu64 " usec", hioi_object_identifier(dataset), dataset->ds_id, module->data_root, stop - start); builtin_posix_trace (posix_dataset, "trace_end", 0, 0, 0, 0); if (posix_dataset->ds_trace_fh) { fclose (posix_dataset->ds_trace_fh); } return rc; }