summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Robinson <43805+derobins@users.noreply.github.com>2022-05-12 04:05:04 (GMT)
committerGitHub <noreply@github.com>2022-05-12 04:05:04 (GMT)
commit29eb6f4df5b65948463bb67ab97e6d78cffa0066 (patch)
tree9ae5a68531efa9a05ce5a9728dc2be610c9af398
parent6e6dbf2e81660a65d3aec955c85d59fa479f3b3b (diff)
downloadhdf5-29eb6f4df5b65948463bb67ab97e6d78cffa0066.zip
hdf5-29eb6f4df5b65948463bb67ab97e6d78cffa0066.tar.gz
hdf5-29eb6f4df5b65948463bb67ab97e6d78cffa0066.tar.bz2
Onion VFD: Refactoring (#1765)
* Struct cleanup * More renaming * Minor cleanup * Removed aspirational code from the feature * Revert "Removed aspirational code from the feature" This reverts commit 0b162d16a175a08565089f829014d0d93e171a23. * Split header code into new files, history_header --> header * In-memory things are size_t now * Minor renaming * More encode/decode functions use size_t instead of uint64_t
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/H5FDonion.c443
-rw-r--r--src/H5FDonion.h26
-rw-r--r--src/H5FDonion_header.c231
-rw-r--r--src/H5FDonion_header.h56
-rw-r--r--src/H5FDonion_history.c245
-rw-r--r--src/H5FDonion_history.h41
-rw-r--r--src/H5FDonion_index.c71
-rw-r--r--src/H5FDonion_index.h24
-rw-r--r--src/H5FDonion_priv.h1
-rw-r--r--src/Makefile.am2
-rw-r--r--test/onion.c278
12 files changed, 751 insertions, 669 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3ff3610..9cb12c2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -241,6 +241,7 @@ set (H5FD_SOURCES
${HDF5_SRC_DIR}/H5FDmpio.c
${HDF5_SRC_DIR}/H5FDmulti.c
${HDF5_SRC_DIR}/H5FDonion.c
+ ${HDF5_SRC_DIR}/H5FDonion_header.c
${HDF5_SRC_DIR}/H5FDonion_history.c
${HDF5_SRC_DIR}/H5FDonion_index.c
${HDF5_SRC_DIR}/H5FDperform.c
@@ -877,6 +878,7 @@ set (H5_PRIVATE_HEADERS
${HDF5_SRC_DIR}/H5FAprivate.h
${HDF5_SRC_DIR}/H5FDmirror_priv.h
+ ${HDF5_SRC_DIR}/H5FDonion_header.h
${HDF5_SRC_DIR}/H5FDonion_history.h
${HDF5_SRC_DIR}/H5FDonion_index.h
${HDF5_SRC_DIR}/H5FDonion_priv.h
diff --git a/src/H5FDonion.c b/src/H5FDonion.c
index efcf945..c51ed23 100644
--- a/src/H5FDonion.c
+++ b/src/H5FDonion.c
@@ -40,104 +40,110 @@ static hid_t H5FD_ONION_g = 0;
* This structure is created when such a file is "opened" and
* discarded when it is "closed".
*
- * `pub` (H5FD_t)
+ * pu
*
- * Instance of H5FD_t which contains all fields common to all VFDs.
+ * Instance of H5FD_t which contains fields common to all VFDs.
* It must be the first item in this structure, since at higher levels,
* this structure will be treated as an instance of H5FD_t.
*
- * `fa` (H5FD_onion_fapl_info_t)
+ * fa
*
* Instance of `H5FD_onion_fapl_info_t` containing the configuration data
* needed to "open" the HDF5 file.
*
- * `backing_canon` (H5FD_t *)
+ * original_file
*
- * Virtual file handle for the canonical (i.e., logical HDF5) file in the
- * backing store.
+ * VFD handle for the original HDF5 file.
*
- * `backing_onion` (H5FD_t *)
+ * onion_file
*
- * Virtual file handle for the onion file in the backing store.
+ * VFD handle for the onion file.
* NULL if not set to use the single, separate storage target.
*
- * `backing_recov` (H5FD_t *)
+ * recovery_file
*
- * Virtual file handle for the history recovery file.
+ * VFD handle for the history recovery file. This file is a backup of
+ * the existing history when an existing onion file is opened in RW mode.
*
- * `name_recov` (char *)
+ * recovery_file_name
*
* String allocated and populated on file-open in write mode and freed on
* file-close, stores the path/name of the 'recovery' file. The file
* created at this location is to be removed upon successful file-close
* from write mode.
*
- * `is_open_rw` (hbool_t)
+ * is_open_rw
*
* Remember whether the file was opened in a read-write mode.
*
- * `page_align_history` (hbool_t)
+ * align_history_on_pages
*
* Remember whether onion-writes must be aligned to page boundaries.
*
- * `header` (H5FD_onion_history_header_t)
+ * header
*
* In-memory copy of the onion history data header.
*
- * `history` (H5FD_onion_history_t)
+ * history
*
* In-memory copy of the onion history.
*
- * `rev_record` (H5FD_onion_revision_record_t)
+ * curr_rev_record
*
- * `history_eof` (haddr_t)
+ * Record for the currently open revision.
*
- * Last byte in the onion history backing file.
+ * rev_index
*
- * `rev_index` (struct H5FD__onion_revision_index *)
- *
- * Index for maintaining modified pages.
+ * Index for maintaining modified pages (RW mode only).
* Pointer is NULL when the file is not opened in write mode.
* Pointer is allocated on open and must be freed on close.
* Contents must be merged with the revision record's archival index prior
* to commitment of history to backing store.
*
- * `history_eof` (haddr_t)
+ * onion_eof
*
- * Address of first byte past in-use onion history data.
+ * Last byte in the onion file.
*
- * `origin_eof` (haddr_t)
+ * origin_eof
*
- * Size of the origin canonical file.
+ * Size of the original HDF5 file.
*
- * `logi_eoa` (haddr_t)
+ * logical_eoa
*
- * Address of first byte past addressed space in logical 'canonical' file.
+ * Address of first byte past addressed space in the logical 'file'
+ * presented by this VFD.
*
- * `logi_eof` (haddr_t)
+ * logical_eof
*
- * Address of first byte past Last byte in the logical 'canonical' file.
+ * Address of first byte past last byte in the logical 'file' presented
+ * by this VFD.
* Must be copied into the revision record on close to write onion data.
*
******************************************************************************
*/
typedef struct H5FD_onion_t {
- H5FD_t pub;
- H5FD_onion_fapl_info_t fa;
- H5FD_t * backing_canon;
- H5FD_t * backing_onion;
- H5FD_t * backing_recov;
- char * name_recov;
- hbool_t is_open_rw;
- hbool_t page_align_history;
- H5FD_onion_history_header_t header;
+ H5FD_t pub;
+ H5FD_onion_fapl_info_t fa;
+ hbool_t is_open_rw;
+ hbool_t align_history_on_pages;
+
+ /* Onion-related files */
+ H5FD_t *original_file;
+ H5FD_t *onion_file;
+ H5FD_t *recovery_file;
+ char * recovery_file_name;
+
+ /* Onion data structures */
+ H5FD_onion_header_t header;
H5FD_onion_history_t history;
- H5FD_onion_revision_record_t rev_record;
+ H5FD_onion_revision_record_t curr_rev_record;
H5FD_onion_revision_index_t *rev_index;
- haddr_t history_eof;
- haddr_t origin_eof;
- haddr_t logi_eoa;
- haddr_t logi_eof;
+
+ /* End of addresses and files */
+ haddr_t onion_eof;
+ haddr_t origin_eof;
+ haddr_t logical_eoa;
+ haddr_t logical_eof;
} H5FD_onion_t;
H5FL_DEFINE_STATIC(H5FD_onion_t);
@@ -365,10 +371,10 @@ H5FD__onion_sb_size(H5FD_t *_file)
/* Sanity check */
HDassert(file);
- HDassert(file->backing_canon);
+ HDassert(file->original_file);
- if (file->backing_canon)
- ret_value = H5FD_sb_size(file->backing_canon);
+ if (file->original_file)
+ ret_value = H5FD_sb_size(file->original_file);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__onion_sb_size */
@@ -391,9 +397,9 @@ H5FD__onion_sb_encode(H5FD_t *_file, char *name /*out*/, unsigned char *buf /*ou
/* Sanity check */
HDassert(file);
- HDassert(file->backing_canon);
+ HDassert(file->original_file);
- if (file->backing_canon && H5FD_sb_encode(file->backing_canon, name, buf) < 0)
+ if (file->original_file && H5FD_sb_encode(file->original_file, name, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTENCODE, FAIL, "unable to encode the superblock in R/W file")
done:
@@ -418,9 +424,9 @@ H5FD__onion_sb_decode(H5FD_t *_file, const char *name, const unsigned char *buf)
/* Sanity check */
HDassert(file);
- HDassert(file->backing_canon);
+ HDassert(file->original_file);
- if (H5FD_sb_load(file->backing_canon, name, buf) < 0)
+ if (H5FD_sb_load(file->original_file, name, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, FAIL, "unable to decode the superblock in R/W file")
done:
@@ -435,12 +441,12 @@ done:
static herr_t
H5FD__onion_commit_new_revision_record(H5FD_onion_t *file)
{
- uint32_t _sum = 0; /* required */
+ uint32_t checksum = 0; /* required */
size_t size = 0;
haddr_t phys_addr = 0; /* offset in history file to record start */
unsigned char * buf = NULL;
herr_t ret_value = SUCCEED;
- H5FD_onion_revision_record_t *rec = &file->rev_record;
+ H5FD_onion_revision_record_t *rec = &file->curr_rev_record;
H5FD_onion_history_t * history = &file->history;
H5FD_onion_record_loc_t * new_list = NULL;
@@ -453,29 +459,28 @@ H5FD__onion_commit_new_revision_record(H5FD_onion_t *file)
info = HDgmtime(&rawtime);
HDstrftime(rec->time_of_creation, sizeof(rec->time_of_creation), "%Y%m%dT%H%M%SZ", info);
- rec->logi_eof = file->logi_eof;
+ rec->logical_eof = file->logical_eof;
if ((TRUE == file->is_open_rw) && (H5FD__onion_merge_revision_index_into_archival_index(
- file->rev_index, &file->rev_record.archival_index) < 0))
+ file->rev_index, &file->curr_rev_record.archival_index) < 0))
HGOTO_ERROR(H5E_VFL, H5E_INTERNAL, FAIL, "unable to update index to write")
if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_REVISION_RECORD + (size_t)rec->comment_size +
(H5FD__ONION_ENCODED_SIZE_INDEX_ENTRY * rec->archival_index.n_entries))))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer for encoded revision record")
- if (0 == (size = H5FD__onion_revision_record_encode(rec, buf, &_sum)))
+ if (0 == (size = H5FD__onion_revision_record_encode(rec, buf, &checksum)))
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "problem encoding revision record")
- phys_addr = file->history_eof;
- if (H5FD_set_eoa(file->backing_onion, H5FD_MEM_DRAW, phys_addr + size) < 0)
+ phys_addr = file->onion_eof;
+ if (H5FD_set_eoa(file->onion_file, H5FD_MEM_DRAW, phys_addr + size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't modify EOA for new revision record")
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, phys_addr, size, buf) < 0)
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, phys_addr, size, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write new revision record")
- file->history_eof = phys_addr + size;
- if (TRUE == file->page_align_history)
- file->history_eof =
- (file->history_eof + (file->header.page_size - 1)) & (~(file->header.page_size - 1));
+ file->onion_eof = phys_addr + size;
+ if (TRUE == file->align_history_on_pages)
+ file->onion_eof = (file->onion_eof + (file->header.page_size - 1)) & (~(file->header.page_size - 1));
/* Update history info to accommodate new revision */
@@ -517,7 +522,7 @@ H5FD__onion_commit_new_revision_record(H5FD_onion_t *file)
history->n_revisions += 1;
} /* end if one or more revisions present in history */
- file->header.history_addr = file->history_eof;
+ file->header.history_addr = file->onion_eof;
done:
H5MM_xfree(buf);
@@ -546,11 +551,11 @@ H5FD__onion_close(H5FD_t *_file)
if (H5FD_ONION_STORE_TARGET_ONION == file->fa.store_target) {
- HDassert(file->backing_onion);
+ HDassert(file->onion_file);
if (file->is_open_rw) {
- HDassert(file->backing_recov);
+ HDassert(file->recovery_file);
if (H5FD__onion_commit_new_revision_record(file) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "Can't write revision record to backing store")
@@ -558,10 +563,10 @@ H5FD__onion_close(H5FD_t *_file)
if (H5FD__onion_write_final_history(file) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "Can't write history to backing store")
- /* Unset write-lock flag */
+ /* Unset write-lock flag and write header */
if (file->is_open_rw)
file->header.flags &= (uint32_t)~H5FD__ONION_HEADER_FLAG_WRITE_LOCK;
- if (H5FD__onion_write_header(&(file->header), file->backing_onion) < 0)
+ if (H5FD__onion_write_header(&(file->header), file->onion_file) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "Can't write updated header to backing store")
}
}
@@ -573,28 +578,28 @@ H5FD__onion_close(H5FD_t *_file)
done:
/* Destroy things as best we can, even if there were earlier errors */
- if (file->backing_canon)
- if (H5FD_close(file->backing_canon) < 0)
+ if (file->original_file)
+ if (H5FD_close(file->original_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, FAIL, "can't close backing canon file")
- if (file->backing_onion)
- if (H5FD_close(file->backing_onion) < 0)
+ if (file->onion_file)
+ if (H5FD_close(file->onion_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, FAIL, "can't close backing onion file")
- if (file->backing_recov) {
- if (H5FD_close(file->backing_recov) < 0)
+ if (file->recovery_file) {
+ if (H5FD_close(file->recovery_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, FAIL, "can't close backing recovery file")
/* TODO: Use the VFD's del callback instead of remove (this requires
* storing a copy of the fapl that was used to open it)
*/
- HDremove(file->name_recov);
+ HDremove(file->recovery_file_name);
}
if (file->rev_index)
if (H5FD__onion_revision_index_destroy(file->rev_index) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, FAIL, "can't close revision index")
- H5MM_xfree(file->name_recov);
+ H5MM_xfree(file->recovery_file_name);
H5MM_xfree(file->history.record_locs);
- H5MM_xfree(file->rev_record.comment);
- H5MM_xfree(file->rev_record.archival_index.list);
+ H5MM_xfree(file->curr_rev_record.comment);
+ H5MM_xfree(file->curr_rev_record.archival_index.list);
file = H5FL_FREE(H5FD_onion_t, file);
@@ -616,7 +621,7 @@ H5FD__onion_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
FUNC_ENTER_PACKAGE_NOERR;
- FUNC_LEAVE_NOAPI(file->logi_eoa)
+ FUNC_LEAVE_NOAPI(file->logical_eoa)
} /* end H5FD__onion_get_eoa() */
/*-----------------------------------------------------------------------------
@@ -634,7 +639,7 @@ H5FD__onion_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type)
FUNC_ENTER_PACKAGE_NOERR;
- FUNC_LEAVE_NOAPI(file->logi_eof)
+ FUNC_LEAVE_NOAPI(file->logical_eof)
} /* end H5FD__onion_get_eof() */
/*-----------------------------------------------------------------------------
@@ -673,14 +678,14 @@ H5FD__onion_get_legit_fapl_id(hid_t fapl_id)
*/
static herr_t
H5FD__onion_create_truncate_onion(H5FD_onion_t *file, const char *filename, const char *name_onion,
- const char *name_recovery, unsigned int flags, haddr_t maxaddr)
+ const char *recovery_file_nameery, unsigned int flags, haddr_t maxaddr)
{
hid_t backing_fapl_id = H5I_INVALID_HID;
- H5FD_onion_history_header_t * hdr = NULL;
+ H5FD_onion_header_t * hdr = NULL;
H5FD_onion_history_t * history = NULL;
H5FD_onion_revision_record_t *rec = NULL;
unsigned char * buf = NULL;
- uint64_t size = 0;
+ size_t size = 0;
herr_t ret_value = SUCCEED;
FUNC_ENTER_PACKAGE;
@@ -689,7 +694,7 @@ H5FD__onion_create_truncate_onion(H5FD_onion_t *file, const char *filename, cons
hdr = &file->header;
history = &file->history;
- rec = &file->rev_record;
+ rec = &file->curr_rev_record;
hdr->flags = H5FD__ONION_HEADER_FLAG_WRITE_LOCK;
if (H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_DIVERGENT_HISTORY & file->fa.creation_flags)
@@ -705,32 +710,32 @@ H5FD__onion_create_truncate_onion(H5FD_onion_t *file, const char *filename, cons
/* Create backing files for onion history */
- if (NULL == (file->backing_canon = H5FD_open(filename, flags, backing_fapl_id, maxaddr)))
+ if (NULL == (file->original_file = H5FD_open(filename, flags, backing_fapl_id, maxaddr)))
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "cannot open the backing file")
- if (NULL == (file->backing_onion = H5FD_open(name_onion, flags, backing_fapl_id, maxaddr)))
+ if (NULL == (file->onion_file = H5FD_open(name_onion, flags, backing_fapl_id, maxaddr)))
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "cannot open the backing onion file")
- if (NULL == (file->backing_recov = H5FD_open(name_recovery, flags, backing_fapl_id, maxaddr)))
+ if (NULL == (file->recovery_file = H5FD_open(recovery_file_nameery, flags, backing_fapl_id, maxaddr)))
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "cannot open the backing file")
/* Write "empty" .h5 file contents (signature ONIONEOF) */
- if (H5FD_set_eoa(file->backing_canon, H5FD_MEM_DRAW, 8) < 0)
+ if (H5FD_set_eoa(file->original_file, H5FD_MEM_DRAW, 8) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't extend EOA")
- if (H5FD_write(file->backing_canon, H5FD_MEM_DRAW, 0, 8, "ONIONEOF") < 0)
+ if (H5FD_write(file->original_file, H5FD_MEM_DRAW, 0, 8, "ONIONEOF") < 0)
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "cannot write header to the backing h5 file")
/* Write nascent history (with no revisions) to "recovery" */
- if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY)))
+ if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HISTORY)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer")
size = H5FD__onion_history_encode(history, buf, &history->checksum);
- if (H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY != size)
+ if (H5FD__ONION_ENCODED_SIZE_HISTORY != size)
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "can't encode history")
- if (H5FD_set_eoa(file->backing_recov, H5FD_MEM_DRAW, size) < 0)
+ if (H5FD_set_eoa(file->recovery_file, H5FD_MEM_DRAW, size) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't extend EOA")
- if (H5FD_write(file->backing_recov, H5FD_MEM_DRAW, 0, size, buf) < 0)
+ if (H5FD_write(file->recovery_file, H5FD_MEM_DRAW, 0, size, buf) < 0)
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "cannot write history to the backing recovery file")
hdr->history_size = size; /* record for later use */
H5MM_xfree(buf);
@@ -742,16 +747,16 @@ H5FD__onion_create_truncate_onion(H5FD_onion_t *file, const char *filename, cons
if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HEADER)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer")
- size = H5FD__onion_history_header_encode(hdr, buf, &hdr->checksum);
+ size = H5FD__onion_header_encode(hdr, buf, &hdr->checksum);
if (H5FD__ONION_ENCODED_SIZE_HEADER != size)
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "can't encode history header")
- if (H5FD_set_eoa(file->backing_onion, H5FD_MEM_DRAW, size) < 0)
+ if (H5FD_set_eoa(file->onion_file, H5FD_MEM_DRAW, size) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't extend EOA")
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, 0, size, buf) < 0)
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, 0, size, buf) < 0)
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, FAIL, "cannot write header to the backing onion file")
- file->history_eof = (haddr_t)size;
- if (TRUE == file->page_align_history)
- file->history_eof = (file->history_eof + (hdr->page_size - 1)) & (~(hdr->page_size - 1));
+ file->onion_eof = (haddr_t)size;
+ if (TRUE == file->align_history_on_pages)
+ file->onion_eof = (file->onion_eof + (hdr->page_size - 1)) & (~(hdr->page_size - 1));
rec->archival_index.list = NULL;
@@ -762,7 +767,7 @@ done:
H5MM_xfree(buf);
if (FAIL == ret_value)
- HDremove(name_recovery); /* destroy new temp file, if 'twas created */
+ HDremove(recovery_file_nameery); /* destroy new temp file, if 'twas created */
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5FD__onion_create_truncate_onion() */
@@ -783,12 +788,12 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
H5FD_onion_t * file = NULL;
const H5FD_onion_fapl_info_t *fa = NULL;
;
- hid_t backing_fapl_id = H5I_INVALID_HID;
- char * name_onion = NULL;
- char * name_recovery = NULL;
- H5FD_t *ret_value = NULL;
- bool new_open = false;
- haddr_t canon_eof = 0;
+ hid_t backing_fapl_id = H5I_INVALID_HID;
+ char * name_onion = NULL;
+ char * recovery_file_nameery = NULL;
+ H5FD_t *ret_value = NULL;
+ bool new_open = false;
+ haddr_t canon_eof = 0;
FUNC_ENTER_PACKAGE
@@ -818,14 +823,14 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "unable to allocate onion name string")
HDsnprintf(name_onion, HDstrlen(filename) + 7, "%s.onion", filename);
- if (NULL == (name_recovery = H5MM_malloc(sizeof(char) * (HDstrlen(name_onion) + 10))))
+ if (NULL == (recovery_file_nameery = H5MM_malloc(sizeof(char) * (HDstrlen(name_onion) + 10))))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "unable to allocate recovery name string")
- HDsnprintf(name_recovery, HDstrlen(name_onion) + 10, "%s.recovery", name_onion);
- file->name_recov = name_recovery;
+ HDsnprintf(recovery_file_nameery, HDstrlen(name_onion) + 10, "%s.recovery", name_onion);
+ file->recovery_file_name = recovery_file_nameery;
- if (NULL == (file->name_recov = H5MM_malloc(sizeof(char) * (HDstrlen(name_onion) + 10))))
+ if (NULL == (file->recovery_file_name = H5MM_malloc(sizeof(char) * (HDstrlen(name_onion) + 10))))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "unable to allocate recovery name string")
- HDsnprintf(file->name_recov, HDstrlen(name_onion) + 10, "%s.recovery", name_onion);
+ HDsnprintf(file->recovery_file_name, HDstrlen(name_onion) + 10, "%s.recovery", name_onion);
/* Translate H5P_DEFAULT to a a real fapl ID, if necessary */
backing_fapl_id = H5FD__onion_get_legit_fapl_id(file->fa.backing_fapl_id);
@@ -839,10 +844,10 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
file->header.version = H5FD__ONION_HEADER_VERSION_CURR;
file->header.page_size = file->fa.page_size; /* guarded on FAPL-set */
- file->history.version = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR;
+ file->history.version = H5FD__ONION_HISTORY_VERSION_CURR;
- file->rev_record.version = H5FD__ONION_REVISION_RECORD_VERSION_CURR;
- file->rev_record.archival_index.version = H5FD__ONION_ARCHIVAL_INDEX_VERSION_CURR;
+ file->curr_rev_record.version = H5FD__ONION_REVISION_RECORD_VERSION_CURR;
+ file->curr_rev_record.archival_index.version = H5FD__ONION_ARCHIVAL_INDEX_VERSION_CURR;
/* Check that the page size is a power of two */
if ((fa->page_size == 0) || ((fa->page_size & (fa->page_size - 1)) != 0))
@@ -854,8 +859,8 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
* instead of division, which is some severely premature optimization
* with a major hit on maintainability.
*/
- double log2_page_size = HDlog2((double)(fa->page_size));
- file->rev_record.archival_index.page_size_log2 = (uint32_t)log2_page_size;
+ double log2_page_size = HDlog2((double)(fa->page_size));
+ file->curr_rev_record.archival_index.page_size_log2 = (uint32_t)log2_page_size;
/* Proceed with open. */
@@ -866,12 +871,12 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
/* Set flags */
if (fa->creation_flags & H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT) {
file->header.flags |= H5FD__ONION_HEADER_FLAG_PAGE_ALIGNMENT;
- file->page_align_history = TRUE;
+ file->align_history_on_pages = TRUE;
}
/* Truncate and create everything as necessary */
- if (H5FD__onion_create_truncate_onion(file, filename, name_onion, file->name_recov, flags, maxaddr) <
- 0)
+ if (H5FD__onion_create_truncate_onion(file, filename, name_onion, file->recovery_file_name, flags,
+ maxaddr) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTCREATE, NULL, "unable to create/truncate onionized files")
file->is_open_rw = TRUE;
}
@@ -880,33 +885,33 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
/* Opening an existing onion file */
/* Open the existing file using the specified fapl */
- if (NULL == (file->backing_canon = H5FD_open(filename, flags, backing_fapl_id, maxaddr)))
+ if (NULL == (file->original_file = H5FD_open(filename, flags, backing_fapl_id, maxaddr)))
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open canonical file (does not exist?)")
/* Try to open any existing onion file */
H5E_BEGIN_TRY
{
- file->backing_onion = H5FD_open(name_onion, flags, backing_fapl_id, maxaddr);
+ file->onion_file = H5FD_open(name_onion, flags, backing_fapl_id, maxaddr);
}
H5E_END_TRY;
/* If that didn't work, create a new onion file */
/* TODO: Move to a new function */
- if (NULL == file->backing_onion) {
+ if (NULL == file->onion_file) {
if (H5F_ACC_RDWR & flags) {
- H5FD_onion_history_header_t * hdr = NULL;
+ H5FD_onion_header_t * hdr = NULL;
H5FD_onion_history_t * history = NULL;
H5FD_onion_revision_record_t *rec = NULL;
unsigned char * head_buf = NULL;
- unsigned char * wh_buf = NULL;
- uint64_t size = 0;
- uint64_t saved_size = 0;
+ unsigned char * hist_buf = NULL;
+ size_t size = 0;
+ size_t saved_size = 0;
HDassert(file != NULL);
hdr = &file->header;
history = &file->history;
- rec = &file->rev_record;
+ rec = &file->curr_rev_record;
new_open = true;
@@ -914,16 +919,16 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
hdr->flags |= H5FD__ONION_HEADER_FLAG_DIVERGENT_HISTORY;
if (H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT & file->fa.creation_flags) {
hdr->flags |= H5FD__ONION_HEADER_FLAG_PAGE_ALIGNMENT;
- file->page_align_history = TRUE;
+ file->align_history_on_pages = TRUE;
}
- if (HADDR_UNDEF == (canon_eof = H5FD_get_eof(file->backing_canon, H5FD_MEM_DEFAULT))) {
+ if (HADDR_UNDEF == (canon_eof = H5FD_get_eof(file->original_file, H5FD_MEM_DEFAULT))) {
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "cannot get size of canonical file")
}
- if (H5FD_set_eoa(file->backing_canon, H5FD_MEM_DRAW, canon_eof) < 0)
+ if (H5FD_set_eoa(file->original_file, H5FD_MEM_DRAW, canon_eof) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't extend EOA")
- hdr->origin_eof = canon_eof;
- file->logi_eof = canon_eof;
+ hdr->origin_eof = canon_eof;
+ file->logical_eof = canon_eof;
backing_fapl_id = H5FD__onion_get_legit_fapl_id(file->fa.backing_fapl_id);
if (H5I_INVALID_HID == backing_fapl_id)
@@ -931,51 +936,50 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
/* Create backing files for onion history */
- if ((file->backing_onion =
- H5FD_open(name_onion, (H5F_ACC_RDWR | H5F_ACC_CREAT | H5F_ACC_TRUNC),
- backing_fapl_id, maxaddr)) == NULL) {
+ if ((file->onion_file = H5FD_open(name_onion, (H5F_ACC_RDWR | H5F_ACC_CREAT | H5F_ACC_TRUNC),
+ backing_fapl_id, maxaddr)) == NULL) {
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "cannot open the backing onion file")
}
/* Write history header with "no" history */
- hdr->history_size = H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY; /* record for later use */
+ hdr->history_size = H5FD__ONION_ENCODED_SIZE_HISTORY; /* record for later use */
hdr->history_addr =
H5FD__ONION_ENCODED_SIZE_HEADER + 1; /* TODO: comment these 2 or do some other way */
head_buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HEADER);
if (NULL == head_buf)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "can't allocate buffer")
- size = H5FD__onion_history_header_encode(hdr, head_buf, &hdr->checksum);
+ size = H5FD__onion_header_encode(hdr, head_buf, &hdr->checksum);
if (H5FD__ONION_ENCODED_SIZE_HEADER != size)
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't encode history header")
- wh_buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY);
- if (NULL == wh_buf)
+ hist_buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HISTORY);
+ if (NULL == hist_buf)
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "can't allocate buffer")
saved_size = size;
history->n_revisions = 0;
- size = H5FD__onion_history_encode(history, wh_buf, &history->checksum);
+ size = H5FD__onion_history_encode(history, hist_buf, &history->checksum);
file->header.history_size = size; /* record for later use */
- if (H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY != size) {
+ if (H5FD__ONION_ENCODED_SIZE_HISTORY != size) {
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, NULL, "can't encode history")
}
- if (H5FD_set_eoa(file->backing_onion, H5FD_MEM_DRAW, saved_size + size + 1) < 0)
+ if (H5FD_set_eoa(file->onion_file, H5FD_MEM_DRAW, saved_size + size + 1) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't extend EOA")
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, 0, saved_size, head_buf) < 0) {
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, 0, saved_size, head_buf) < 0) {
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, NULL,
"cannot write header to the backing onion file")
}
- file->history_eof = (haddr_t)saved_size;
- if (TRUE == file->page_align_history)
- file->history_eof = (file->history_eof + (hdr->page_size - 1)) & (~(hdr->page_size - 1));
+ file->onion_eof = (haddr_t)saved_size;
+ if (TRUE == file->align_history_on_pages)
+ file->onion_eof = (file->onion_eof + (hdr->page_size - 1)) & (~(hdr->page_size - 1));
rec->archival_index.list = NULL;
- file->header.history_addr = file->history_eof;
+ file->header.history_addr = file->onion_eof;
/* Write nascent history (with no revisions) to the backing onion file */
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, saved_size + 1, size, wh_buf) < 0) {
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, saved_size + 1, size, hist_buf) < 0) {
HGOTO_ERROR(H5E_FILE, H5E_WRITEERROR, NULL,
"cannot write history to the backing onion file")
}
@@ -983,23 +987,23 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
file->header.history_size = size; /* record for later use */
H5MM_xfree(head_buf);
- H5MM_xfree(wh_buf);
+ H5MM_xfree(hist_buf);
}
else {
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, NULL, "unable to open onion file (does not exist?).")
}
}
- if (HADDR_UNDEF == (canon_eof = H5FD_get_eof(file->backing_canon, H5FD_MEM_DEFAULT))) {
+ if (HADDR_UNDEF == (canon_eof = H5FD_get_eof(file->original_file, H5FD_MEM_DEFAULT))) {
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, NULL, "cannot get size of canonical file")
}
- if (H5FD_set_eoa(file->backing_canon, H5FD_MEM_DRAW, canon_eof) < 0)
+ if (H5FD_set_eoa(file->original_file, H5FD_MEM_DRAW, canon_eof) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, NULL, "can't extend EOA")
/* Get the history header from the onion file */
- if (H5FD__onion_ingest_history_header(&file->header, file->backing_onion, 0) < 0)
+ if (H5FD__onion_ingest_header(&file->header, file->onion_file, 0) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, NULL, "can't get history header from backing store")
- file->page_align_history =
+ file->align_history_on_pages =
(file->header.flags & H5FD__ONION_HEADER_FLAG_PAGE_ALIGNMENT) ? TRUE : FALSE;
if (H5FD__ONION_HEADER_FLAG_WRITE_LOCK & file->header.flags) {
@@ -1008,7 +1012,7 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
}
else {
/* Read in the history from the onion file */
- if (H5FD__onion_ingest_history(&file->history, file->backing_onion, file->header.history_addr,
+ if (H5FD__onion_ingest_history(&file->history, file->onion_file, file->header.history_addr,
file->header.history_size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, NULL, "can't get history from backing store")
@@ -1018,11 +1022,11 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "target revision ID out of range")
if (fa->revision_num == 0) {
- file->rev_record.logi_eof = canon_eof;
+ file->curr_rev_record.logical_eof = canon_eof;
}
else if (file->history.n_revisions > 0 &&
H5FD__onion_ingest_revision_record(
- &file->rev_record, file->backing_onion, &file->history,
+ &file->curr_rev_record, file->onion_file, &file->history,
MIN(fa->revision_num - 1, (file->history.n_revisions - 1))) < 0) {
HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, NULL, "can't get revision record from backing store")
}
@@ -1038,40 +1042,39 @@ H5FD__onion_open(const char *filename, unsigned flags, hid_t fapl_id, haddr_t ma
if ((H5F_ACC_RDWR | H5F_ACC_CREAT | H5F_ACC_TRUNC) & flags) {
if (fa->comment) {
/* Free the old comment */
- file->rev_record.comment = H5MM_xfree(file->rev_record.comment);
+ file->curr_rev_record.comment = H5MM_xfree(file->curr_rev_record.comment);
/* TODO: Lengths of strings should be size_t */
- file->rev_record.comment_size = (uint32_t)HDstrlen(fa->comment) + 1;
+ file->curr_rev_record.comment_size = (uint32_t)HDstrlen(fa->comment) + 1;
- if (NULL == (file->rev_record.comment = H5MM_xstrdup(fa->comment)))
+ if (NULL == (file->curr_rev_record.comment = H5MM_xstrdup(fa->comment)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, NULL, "unable to allocate comment string")
}
}
- file->origin_eof = file->header.origin_eof;
- file->logi_eof = MAX(file->rev_record.logi_eof, file->logi_eof);
- file->logi_eoa = 0;
+ file->origin_eof = file->header.origin_eof;
+ file->logical_eof = MAX(file->curr_rev_record.logical_eof, file->logical_eof);
+ file->logical_eoa = 0;
- file->history_eof = H5FD_get_eoa(file->backing_onion, H5FD_MEM_DRAW);
- if (TRUE == file->page_align_history)
- file->history_eof =
- (file->history_eof + (file->header.page_size - 1)) & (~(file->header.page_size - 1));
+ file->onion_eof = H5FD_get_eoa(file->onion_file, H5FD_MEM_DRAW);
+ if (TRUE == file->align_history_on_pages)
+ file->onion_eof = (file->onion_eof + (file->header.page_size - 1)) & (~(file->header.page_size - 1));
ret_value = (H5FD_t *)file;
done:
H5MM_xfree(name_onion);
- H5MM_xfree(name_recovery);
+ H5MM_xfree(recovery_file_nameery);
if ((NULL == ret_value) && file) {
- if (file->backing_canon)
- if (H5FD_close(file->backing_canon) < 0)
+ if (file->original_file)
+ if (H5FD_close(file->original_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, NULL, "can't destroy backing canon")
- if (file->backing_onion)
- if (H5FD_close(file->backing_onion) < 0)
+ if (file->onion_file)
+ if (H5FD_close(file->onion_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, NULL, "can't destroy backing onion")
- if (file->backing_recov)
- if (H5FD_close(file->backing_recov) < 0)
+ if (file->recovery_file)
+ if (H5FD_close(file->recovery_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTRELEASE, NULL, "can't destroy backing recov")
if (file->rev_index)
@@ -1080,8 +1083,8 @@ done:
H5MM_xfree(file->history.record_locs);
- H5MM_xfree(file->name_recov);
- H5MM_xfree(file->rev_record.comment);
+ H5MM_xfree(file->recovery_file_name);
+ H5MM_xfree(file->curr_rev_record.comment);
H5FL_FREE(H5FD_onion_t, file);
}
@@ -1106,8 +1109,8 @@ static herr_t
H5FD__onion_open_rw(H5FD_onion_t *file, unsigned int flags, haddr_t maxaddr, bool new_open)
{
unsigned char *buf = NULL;
- uint64_t size = 0;
- uint32_t _sum = 0;
+ size_t size = 0;
+ uint32_t checksum = 0;
herr_t ret_value = SUCCEED;
FUNC_ENTER_PACKAGE;
@@ -1121,11 +1124,12 @@ H5FD__onion_open_rw(H5FD_onion_t *file, unsigned int flags, haddr_t maxaddr, boo
/* Copy history to recovery file */
- if (NULL == (file->backing_recov = H5FD_open(file->name_recov, (flags | H5F_ACC_CREAT | H5F_ACC_TRUNC),
- file->fa.backing_fapl_id, maxaddr)))
+ if (NULL ==
+ (file->recovery_file = H5FD_open(file->recovery_file_name, (flags | H5F_ACC_CREAT | H5F_ACC_TRUNC),
+ file->fa.backing_fapl_id, maxaddr)))
HGOTO_ERROR(H5E_VFL, H5E_CANTOPENFILE, FAIL, "unable to create recovery file")
- if (0 == (size = H5FD__onion_write_history(&file->history, file->backing_recov, 0, 0)))
+ if (0 == (size = H5FD__onion_write_history(&file->history, file->recovery_file, 0, 0)))
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write history to recovery file")
if (size != file->header.history_size)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "written history differed from expected size")
@@ -1137,27 +1141,27 @@ H5FD__onion_open_rw(H5FD_onion_t *file, unsigned int flags, haddr_t maxaddr, boo
file->header.flags |= H5FD__ONION_HEADER_FLAG_WRITE_LOCK;
- if (0 == (size = H5FD__onion_history_header_encode(&file->header, buf, &_sum)))
+ if (0 == (size = H5FD__onion_header_encode(&file->header, buf, &checksum)))
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "problem encoding history header")
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, 0, (haddr_t)size, buf) < 0)
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, 0, size, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write updated history header")
/* Prepare revision index and finalize write-mode open */
if (NULL == (file->rev_index = H5FD__onion_revision_index_init(file->fa.page_size)))
HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize revision index")
- file->rev_record.parent_revision_num = file->rev_record.revision_num;
+ file->curr_rev_record.parent_revision_num = file->curr_rev_record.revision_num;
if (!new_open)
- file->rev_record.revision_num += 1;
+ file->curr_rev_record.revision_num += 1;
file->is_open_rw = TRUE;
done:
if (FAIL == ret_value) {
- if (file->backing_recov != NULL) {
- if (H5FD_close(file->backing_recov) < 0)
+ if (file->recovery_file != NULL) {
+ if (H5FD_close(file->recovery_file) < 0)
HDONE_ERROR(H5E_VFL, H5E_CANTCLOSEFILE, FAIL, "can't close recovery file")
- file->backing_recov = NULL;
+ file->recovery_file = NULL;
}
if (file->rev_index != NULL) {
@@ -1198,14 +1202,14 @@ H5FD__onion_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, h
HDassert(file != NULL);
HDassert(buf_out != NULL);
- if ((uint64_t)(offset + len) > file->logi_eoa)
+ if ((uint64_t)(offset + len) > file->logical_eoa)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Read extends beyond addressed space")
if (0 == len)
goto done;
page_size = file->header.page_size;
- page_size_log2 = file->rev_record.archival_index.page_size_log2;
+ page_size_log2 = file->curr_rev_record.archival_index.page_size_log2;
page_0 = offset >> page_size_log2;
n_pages = (len + page_size - 1) >> page_size_log2;
@@ -1233,24 +1237,28 @@ H5FD__onion_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, h
if (TRUE == file->is_open_rw && file->fa.revision_num != 0 &&
H5FD__onion_revision_index_find(file->rev_index, page_i, &entry_out)) {
- if (H5FD_read(file->backing_onion, H5FD_MEM_DRAW, entry_out->phys_addr + page_gap_head,
+ /* Page exists in 'live' revision index */
+ if (H5FD_read(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr + page_gap_head,
page_readsize, buf_out) < 0)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get working file data")
- } /* end if page exists in 'live' revision index */
+ }
else if (file->fa.revision_num != 0 &&
- H5FD__onion_archival_index_find(&file->rev_record.archival_index, page_i, &entry_out)) {
- if (H5FD_read(file->backing_onion, H5FD_MEM_DRAW, entry_out->phys_addr + page_gap_head,
+ H5FD__onion_archival_index_find(&file->curr_rev_record.archival_index, page_i, &entry_out)) {
+ /* Page exists in archival index */
+ if (H5FD_read(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr + page_gap_head,
page_readsize, buf_out) < 0)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get previously-amended file data")
- } /* end if page exists in 'dead' archival index */
+ }
else {
- /* casts prevent truncation */
+ /* Page does not exist in either index */
+
+ /* Casts prevent truncation */
haddr_t addr_start = (haddr_t)page_i * (haddr_t)page_size + (haddr_t)page_gap_head;
haddr_t overlap_size = (addr_start > file->origin_eof) ? 0 : file->origin_eof - addr_start;
haddr_t read_size = MIN(overlap_size, page_readsize);
/* Get all original bytes in page range */
- if ((read_size > 0) && H5FD_read(file->backing_canon, type, addr_start, read_size, buf_out) < 0) {
+ if ((read_size > 0) && H5FD_read(file->original_file, type, addr_start, read_size, buf_out) < 0) {
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get original file data")
}
@@ -1259,7 +1267,7 @@ H5FD__onion_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, h
*/
for (size_t j = read_size; j < page_readsize; j++)
buf_out[j] = 0;
- } /* end if page exists in neither index */
+ }
buf_out += page_readsize;
bytes_to_read -= page_readsize;
@@ -1286,7 +1294,7 @@ H5FD__onion_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr)
FUNC_ENTER_PACKAGE_NOERR;
- file->logi_eoa = addr;
+ file->logical_eoa = addr;
FUNC_LEAVE_NOAPI(SUCCEED);
} /* end H5FD__onion_set_eoa() */
@@ -1318,7 +1326,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
HDassert(file != NULL);
HDassert(buf != NULL);
HDassert(file->rev_index != NULL);
- HDassert((uint64_t)(offset + len) <= file->logi_eoa);
+ HDassert((uint64_t)(offset + len) <= file->logical_eoa);
if (FALSE == file->is_open_rw)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "Write not allowed if file not opened in write mode")
@@ -1327,7 +1335,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
goto done;
page_size = file->header.page_size;
- page_size_log2 = file->rev_record.archival_index.page_size_log2;
+ page_size_log2 = file->curr_rev_record.archival_index.page_size_log2;
page_0 = offset >> page_size_log2;
n_pages = (len + page_size - 1) >> page_size_log2;
@@ -1363,16 +1371,14 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
if (H5FD__onion_revision_index_find(file->rev_index, page_i, &entry_out)) {
if (page_gap_head | page_gap_tail) {
/* Copy existing page verbatim. */
- if (H5FD_read(file->backing_onion, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, page_buf) <
- 0)
+ if (H5FD_read(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, page_buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get working file data")
/* Overlay delta from input buffer onto page buffer. */
HDmemcpy(page_buf + page_gap_head, buf, page_n_used);
write_buf = page_buf;
} /* end if partial page */
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, write_buf) <
- 0)
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, write_buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "write amended page data to backing file")
buf += page_n_used; /* overflow never touched */
@@ -1383,12 +1389,13 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
if (page_gap_head || page_gap_tail) {
/* Fill gaps with existing data or zeroes. */
- if (H5FD__onion_archival_index_find(&file->rev_record.archival_index, page_i, &entry_out)) {
- /* Copy existing page verbatim. */
- if (H5FD_read(file->backing_onion, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, page_buf) <
- 0)
+ if (H5FD__onion_archival_index_find(&file->curr_rev_record.archival_index, page_i, &entry_out)) {
+ /* Page exists in archival index */
+
+ /* Copy existing page verbatim */
+ if (H5FD_read(file->onion_file, H5FD_MEM_DRAW, entry_out->phys_addr, page_size, page_buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get previously-amended data")
- } /* end if page exists in 'dead' archival index */
+ }
else {
haddr_t addr_start = (haddr_t)(page_i * page_size);
haddr_t overlap_size = (addr_start > file->origin_eof) ? 0 : file->origin_eof - addr_start;
@@ -1396,7 +1403,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
/* Get all original bytes in page range */
if ((read_size > 0) &&
- H5FD_read(file->backing_canon, type, addr_start, read_size, page_buf) < 0) {
+ H5FD_read(file->original_file, type, addr_start, read_size, page_buf) < 0) {
HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't get original file data")
}
@@ -1420,19 +1427,19 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
} /* end if data range does not span entire page */
- new_entry.logi_page = page_i;
- new_entry.phys_addr = file->history_eof;
+ new_entry.logical_page = page_i;
+ new_entry.phys_addr = file->onion_eof;
- if (H5FD_set_eoa(file->backing_onion, H5FD_MEM_DRAW, file->history_eof + page_size) < 0)
+ if (H5FD_set_eoa(file->onion_file, H5FD_MEM_DRAW, file->onion_eof + page_size) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't modify EOA for new page amendment")
- if (H5FD_write(file->backing_onion, H5FD_MEM_DRAW, file->history_eof, page_size, write_buf) < 0)
+ if (H5FD_write(file->onion_file, H5FD_MEM_DRAW, file->onion_eof, page_size, write_buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "write amended page data to backing file")
if (H5FD__onion_revision_index_insert(file->rev_index, &new_entry) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTINSERT, FAIL, "can't insert new index entry into revision index")
- file->history_eof += page_size;
+ file->onion_eof += page_size;
buf += page_n_used; /* possible overflow never touched */
bytes_to_write -= page_n_used;
@@ -1440,7 +1447,7 @@ H5FD__onion_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id,
HDassert(0 == bytes_to_write);
- file->logi_eof = MAX(file->logi_eof, (offset + len));
+ file->logical_eof = MAX(file->logical_eof, (offset + len));
done:
H5MM_xfree(page_buf);
@@ -1589,8 +1596,8 @@ H5FD__onion_write_final_history(H5FD_onion_t *file)
FUNC_ENTER_PACKAGE;
/* TODO: history EOF may not be correct (under what circumstances?) */
- if (0 == (size = H5FD__onion_write_history(&(file->history), file->backing_onion, file->history_eof,
- file->history_eof)))
+ if (0 == (size = H5FD__onion_write_history(&(file->history), file->onion_file, file->onion_eof,
+ file->onion_eof)))
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write final history")
if (size != file->header.history_size)
@@ -1599,7 +1606,7 @@ H5FD__onion_write_final_history(H5FD_onion_t *file)
/* Is last write operation to history file; no need to extend to page
* boundary if set to page-align.
*/
- file->history_eof += size;
+ file->onion_eof += size;
done:
FUNC_LEAVE_NOAPI(ret_value);
diff --git a/src/H5FDonion.h b/src/H5FDonion.h
index c91010c..54af14e 100644
--- a/src/H5FDonion.h
+++ b/src/H5FDonion.h
@@ -21,19 +21,29 @@
#define H5FD_ONION (H5FDperform_init(H5FD_onion_init))
#define H5FD_ONION_VALUE H5_VFD_ONION
-#define H5FD_ONION_ENABLE_INDEX_STATS 0
+/* Current version of the fapl info struct */
+#define H5FD_ONION_FAPL_INFO_VERSION_CURR 1
-#define H5FD_ONION_FAPL_INFO_VERSION_CURR 1
-#define H5FD_ONION_FAPL_INFO_FLAG_FORCE_OPEN 1
-#define H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_DIVERGENT_HISTORY 1
-#define H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT 2
-#define H5FD_ONION_FAPL_INFO_COMMENT_MAX_LEN 255
-#define H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST UINT64_MAX
+/* Flag to open a file that has a locked header (after crashes, for example) */
+#define H5FD_ONION_FAPL_INFO_FLAG_FORCE_OPEN 1
+
+/* Flag to enable opening older revisions in write mode, creating a tree */
+#define H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_DIVERGENT_HISTORY 0x1
+
+/* Flag to require page alignment of onion revision data */
+#define H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT 0x2
+
+/* Max length of a comment */
+#define H5FD_ONION_FAPL_INFO_COMMENT_MAX_LEN 255
+
+/* Indicates that you want the latest revision
+ * TODO: Does this work?
+ */
+#define H5FD_ONION_FAPL_INFO_REVISION_ID_LATEST UINT64_MAX
typedef enum H5FD_onion_target_file_constant_t {
H5FD_ONION_STORE_TARGET_H5, /* Onion history as part of HDF5 file */
H5FD_ONION_STORE_TARGET_ONION, /* Separate, single "onion" file */
- /* TODO: other storage location/scheme? */
} H5FD_onion_target_file_constant_t;
/*-----------------------------------------------------------------------------
diff --git a/src/H5FDonion_header.c b/src/H5FDonion_header.c
new file mode 100644
index 0000000..6889140
--- /dev/null
+++ b/src/H5FDonion_header.c
@@ -0,0 +1,231 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Onion Virtual File Driver (VFD)
+ *
+ * Purpose: Code for the onion file's header
+ */
+
+/* This source code file is part of the H5FD driver module */
+#include "H5FDdrvr_module.h"
+
+#include "H5private.h" /* Generic Functions */
+#include "H5Eprivate.h" /* Error handling */
+#include "H5FDprivate.h" /* File drivers */
+#include "H5FDonion.h" /* Onion file driver */
+#include "H5FDonion_priv.h" /* Onion file driver internals */
+
+/*-----------------------------------------------------------------------------
+ * Function: H5FD_ingest_header
+ *
+ * Purpose: Read and decode the history header information from `raw_file`
+ * at `addr`, and store the decoded information in the structure
+ * at `hdr_out`.
+ *
+ * Return: SUCCEED/FAIL
+ *-----------------------------------------------------------------------------
+ */
+herr_t
+H5FD__onion_ingest_header(H5FD_onion_header_t *hdr_out, H5FD_t *raw_file, haddr_t addr)
+{
+ unsigned char *buf = NULL;
+ herr_t ret_value = SUCCEED;
+ haddr_t size = (haddr_t)H5FD__ONION_ENCODED_SIZE_HEADER;
+ uint32_t sum = 0;
+
+ FUNC_ENTER_PACKAGE;
+
+ if (H5FD_get_eof(raw_file, H5FD_MEM_DRAW) < (addr + size))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "header indicates history beyond EOF")
+
+ if (NULL == (buf = H5MM_malloc(sizeof(char) * size)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer space")
+
+ if (H5FD_set_eoa(raw_file, H5FD_MEM_DRAW, (addr + size)) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't modify EOA")
+
+ if (H5FD_read(raw_file, H5FD_MEM_DRAW, addr, size, buf) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't read history header from file")
+
+ if (H5FD__onion_header_decode(buf, hdr_out) == 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, FAIL, "can't decode history header")
+
+ sum = H5_checksum_fletcher32(buf, size - 4);
+ if (hdr_out->checksum != sum)
+ HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "checksum mismatch between buffer and stored")
+
+done:
+ H5MM_xfree(buf);
+
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5FD__onion_ingest_header() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5FD__onion_write_header
+ *
+ * Purpose: Write in-memory history header to appropriate backing file.
+ * Overwrites existing header data.
+ *
+ * Return: SUCCEED/FAIL
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5FD__onion_write_header(H5FD_onion_header_t *header, H5FD_t *file)
+{
+ uint32_t sum = 0; /* Not used, but required by the encoder */
+ uint64_t size = 0;
+ unsigned char *buf = NULL;
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_PACKAGE;
+
+ if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HEADER)))
+ HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "can't allocate buffer for updated history header")
+
+ if (0 == (size = H5FD__onion_header_encode(header, buf, &sum)))
+ HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "problem encoding updated history header")
+
+ if (H5FD_write(file, H5FD_MEM_DRAW, 0, (haddr_t)size, buf) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write updated history header")
+
+done:
+ H5MM_xfree(buf);
+
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5FD__onion_write_header()*/
+
+/*-----------------------------------------------------------------------------
+ * Function: H5FD__onion_header_decode
+ *
+ * Purpose: Attempt to read a buffer and store it as a history-header
+ * structure.
+ *
+ * Implementation must correspond with
+ * H5FD__onion_header_encode().
+ *
+ * Return: Success: Number of bytes read from buffer
+ * Failure: 0
+ *-----------------------------------------------------------------------------
+ */
+size_t
+H5FD__onion_header_decode(unsigned char *buf, H5FD_onion_header_t *header)
+{
+ uint32_t ui32 = 0;
+ uint32_t sum = 0;
+ uint64_t ui64 = 0;
+ uint8_t * ui8p = NULL;
+ unsigned char *ptr = NULL;
+ size_t ret_value = 0;
+
+ FUNC_ENTER_PACKAGE;
+
+ HDassert(buf != NULL);
+ HDassert(header != NULL);
+ HDassert(H5FD__ONION_HEADER_VERSION_CURR == header->version);
+
+ if (HDstrncmp((const char *)buf, H5FD__ONION_HEADER_SIGNATURE, 4))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid header signature")
+
+ if (buf[4] != H5FD__ONION_HEADER_VERSION_CURR)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid header version")
+
+ ptr = buf + 5;
+ ui32 = 0;
+ HDmemcpy(&ui32, ptr, 3);
+ ui8p = (uint8_t *)&ui32;
+ UINT32DECODE(ui8p, header->flags);
+ ptr += 3;
+
+ HDmemcpy(&ui32, ptr, 4);
+ ui8p = (uint8_t *)&ui32;
+ UINT32DECODE(ui8p, header->page_size);
+ ptr += 4;
+
+ HDmemcpy(&ui64, ptr, 8);
+ ui8p = (uint8_t *)&ui64;
+ UINT32DECODE(ui8p, header->origin_eof);
+ ptr += 8;
+
+ HDmemcpy(&ui64, ptr, 8);
+ ui8p = (uint8_t *)&ui64;
+ UINT32DECODE(ui8p, header->history_addr);
+ ptr += 8;
+
+ HDmemcpy(&ui64, ptr, 8);
+ ui8p = (uint8_t *)&ui64;
+ UINT32DECODE(ui8p, header->history_size);
+ ptr += 8;
+
+ sum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
+
+ HDmemcpy(&ui32, ptr, 4);
+ ui8p = (uint8_t *)&ui32;
+ UINT32DECODE(ui8p, header->checksum);
+ ptr += 4;
+
+ if (sum != header->checksum)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "checksum mismatch")
+
+ ret_value = (size_t)(ptr - buf);
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5FD__onion_header_decode() */
+
+/*-----------------------------------------------------------------------------
+ * Function: H5FD__onion_header_encode
+ *
+ * Purpose: Write history-header structure to the given buffer.
+ * All multi-byte elements are stored in little-endian word order.
+ *
+ * Implementation must correspond with
+ * H5FD__onion_header_decode().
+ *
+ * The destination buffer must be sufficiently large to hold the
+ * encoded contents (H5FD__ONION_ENCODED_SIZE_HEADER).
+ *
+ * Return: Number of bytes written to buffer.
+ * The checksum of the generated buffer contents (excluding the
+ * checksum itself) is stored in the pointer `checksum`).
+ *-----------------------------------------------------------------------------
+ */
+size_t
+H5FD__onion_header_encode(H5FD_onion_header_t *header, unsigned char *buf, uint32_t *checksum /*out*/)
+{
+ unsigned char *ptr = buf;
+ size_t ret_value = 0;
+
+ FUNC_ENTER_PACKAGE_NOERR;
+
+ HDassert(buf != NULL);
+ HDassert(checksum != NULL);
+ HDassert(header != NULL);
+ HDassert(H5FD__ONION_HEADER_VERSION_CURR == header->version);
+ HDassert(0 == (header->flags & 0xFF000000)); /* max three bits long */
+
+ HDmemcpy(ptr, H5FD__ONION_HEADER_SIGNATURE, 4);
+ ptr += 4;
+ HDmemcpy(ptr, (unsigned char *)&header->version, 1);
+ ptr += 1;
+ UINT32ENCODE(ptr, header->flags);
+ ptr -= 1; /* truncate to three bytes */
+ UINT32ENCODE(ptr, header->page_size);
+ UINT64ENCODE(ptr, header->origin_eof);
+ UINT64ENCODE(ptr, header->history_addr);
+ UINT64ENCODE(ptr, header->history_size);
+ *checksum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
+ UINT32ENCODE(ptr, *checksum);
+ ret_value = (size_t)(ptr - buf);
+
+ FUNC_LEAVE_NOAPI(ret_value);
+} /* end H5FD__onion_header_encode() */
diff --git a/src/H5FDonion_header.h b/src/H5FDonion_header.h
new file mode 100644
index 0000000..1728aef
--- /dev/null
+++ b/src/H5FDonion_header.h
@@ -0,0 +1,56 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Onion Virtual File Driver (VFD)
+ *
+ * Purpose: Interface for the onion file's header
+ */
+
+#ifndef H5FDonion_header_H
+#define H5FDonion_header_H
+
+/* Number of bytes to encode fixed-size components */
+#define H5FD__ONION_ENCODED_SIZE_HEADER 40
+
+/* Flags must align exactly one per bit, up to 24 bits */
+#define H5FD__ONION_HEADER_FLAG_WRITE_LOCK 0x1
+#define H5FD__ONION_HEADER_FLAG_DIVERGENT_HISTORY 0x2
+#define H5FD__ONION_HEADER_FLAG_PAGE_ALIGNMENT 0x4
+#define H5FD__ONION_HEADER_SIGNATURE "OHDH"
+#define H5FD__ONION_HEADER_VERSION_CURR 1
+
+/* In-memory representation of the on-store onion history file header.
+ */
+typedef struct H5FD_onion_header_t {
+ uint8_t version;
+ uint32_t flags; /* At most three bytes used! */
+ uint32_t page_size;
+ uint64_t origin_eof; /* Size of the 'original' canonical file */
+ uint64_t history_addr;
+ uint64_t history_size;
+ uint32_t checksum;
+} H5FD_onion_header_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+H5_DLL herr_t H5FD__onion_ingest_header(H5FD_onion_header_t *hdr_out, H5FD_t *raw_file, haddr_t addr);
+H5_DLL herr_t H5FD__onion_write_header(H5FD_onion_header_t *header, H5FD_t *file);
+H5_DLL size_t H5FD__onion_header_decode(unsigned char *buf, H5FD_onion_header_t *header);
+H5_DLL size_t H5FD__onion_header_encode(H5FD_onion_header_t *header, unsigned char *buf, uint32_t *checksum);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H5FDonion_header_H */
diff --git a/src/H5FDonion_history.c b/src/H5FDonion_history.c
index 39acbb1..f7ed2f3 100644
--- a/src/H5FDonion_history.c
+++ b/src/H5FDonion_history.c
@@ -26,51 +26,6 @@
#include "H5FDonion_priv.h" /* Onion file driver internals */
/*-----------------------------------------------------------------------------
- * Function: H5FD_ingest_history_header
- *
- * Purpose: Read and decode the history header information from `raw_file`
- * at `addr`, and store the decoded information in the structure
- * at `hdr_out`.
- *
- * Return: SUCCEED/FAIL
- *-----------------------------------------------------------------------------
- */
-herr_t
-H5FD__onion_ingest_history_header(H5FD_onion_history_header_t *hdr_out, H5FD_t *raw_file, haddr_t addr)
-{
- unsigned char *buf = NULL;
- herr_t ret_value = SUCCEED;
- haddr_t size = (haddr_t)H5FD__ONION_ENCODED_SIZE_HEADER;
- uint32_t sum = 0;
-
- FUNC_ENTER_PACKAGE;
-
- if (H5FD_get_eof(raw_file, H5FD_MEM_DRAW) < (addr + size))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "header indicates history beyond EOF")
-
- if (NULL == (buf = H5MM_malloc(sizeof(char) * size)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer space")
-
- if (H5FD_set_eoa(raw_file, H5FD_MEM_DRAW, (addr + size)) < 0)
- HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "can't modify EOA")
-
- if (H5FD_read(raw_file, H5FD_MEM_DRAW, addr, size, buf) < 0)
- HGOTO_ERROR(H5E_VFL, H5E_READERROR, FAIL, "can't read history header from file")
-
- if (H5FD__onion_history_header_decode(buf, hdr_out) == 0)
- HGOTO_ERROR(H5E_VFL, H5E_CANTDECODE, FAIL, "can't decode history header")
-
- sum = H5_checksum_fletcher32(buf, size - 4);
- if (hdr_out->checksum != sum)
- HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "checksum mismatch between buffer and stored")
-
-done:
- H5MM_xfree(buf);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5FD__onion_ingest_history_header() */
-
-/*-----------------------------------------------------------------------------
* Read and decode the history information from `raw_file` at
* `addr` .. `addr + size` (taken from history header), and store the decoded
* information in the structure at `history_out`.
@@ -122,40 +77,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5FD__onion_ingest_history() */
-/*-------------------------------------------------------------------------
- * Function: H5FD__onion_write_header
- *
- * Purpose: Write in-memory history header to appropriate backing file.
- * Overwrites existing header data.
- *
- * Return: SUCCEED/FAIL
- *-------------------------------------------------------------------------
- */
-herr_t
-H5FD__onion_write_header(H5FD_onion_history_header_t *header, H5FD_t *backing_file)
-{
- uint32_t sum = 0; /* Not used, but required by the encoder */
- uint64_t size = 0;
- unsigned char *buf = NULL;
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER_PACKAGE;
-
- if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HEADER)))
- HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "can't allocate buffer for updated history header")
-
- if (0 == (size = H5FD__onion_history_header_encode(header, buf, &sum)))
- HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "problem encoding updated history header")
-
- if (H5FD_write(backing_file, H5FD_MEM_DRAW, 0, (haddr_t)size, buf) < 0)
- HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, FAIL, "can't write updated history header")
-
-done:
- H5MM_xfree(buf);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5FD__onion_write_header()*/
-
/*-----------------------------------------------------------------------------
* Function: H5FD__onion_write_history
*
@@ -166,7 +87,7 @@ done:
*-----------------------------------------------------------------------------
*/
uint64_t
-H5FD__onion_write_history(H5FD_onion_history_t *history, H5FD_t *file_dest, haddr_t off_start,
+H5FD__onion_write_history(H5FD_onion_history_t *history, H5FD_t *file, haddr_t off_start,
haddr_t filesize_curr)
{
uint32_t _sum = 0; /* Required by the API call but unused here */
@@ -176,17 +97,17 @@ H5FD__onion_write_history(H5FD_onion_history_t *history, H5FD_t *file_dest, hadd
FUNC_ENTER_PACKAGE;
- if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY +
+ if (NULL == (buf = H5MM_malloc(H5FD__ONION_ENCODED_SIZE_HISTORY +
(H5FD__ONION_ENCODED_SIZE_RECORD_POINTER * history->n_revisions))))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, 0, "can't allocate buffer for updated history")
if (0 == (size = H5FD__onion_history_encode(history, buf, &_sum)))
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, 0, "problem encoding updated history")
- if ((size + off_start > filesize_curr) && (H5FD_set_eoa(file_dest, H5FD_MEM_DRAW, off_start + size) < 0))
+ if ((size + off_start > filesize_curr) && (H5FD_set_eoa(file, H5FD_MEM_DRAW, off_start + size) < 0))
HGOTO_ERROR(H5E_VFL, H5E_CANTSET, 0, "can't modify EOA for updated history")
- if (H5FD_write(file_dest, H5FD_MEM_DRAW, off_start, size, buf) < 0)
+ if (H5FD_write(file, H5FD_MEM_DRAW, off_start, size, buf) < 0)
HGOTO_ERROR(H5E_VFL, H5E_WRITEERROR, 0, "can't write history as intended")
ret_value = size;
@@ -198,132 +119,6 @@ done:
} /* end H5FD__onion_write_history() */
/*-----------------------------------------------------------------------------
- * Function: H5FD__onion_history_header_decode
- *
- * Purpose: Attempt to read a buffer and store it as a history-header
- * structure.
- *
- * Implementation must correspond with
- * H5FD__onion_history_header_encode().
- *
- * Return: Success: Number of bytes read from buffer
- * Failure: 0
- *-----------------------------------------------------------------------------
- */
-uint64_t
-H5FD__onion_history_header_decode(unsigned char *buf, H5FD_onion_history_header_t *header)
-{
- uint32_t ui32 = 0;
- uint32_t sum = 0;
- uint64_t ui64 = 0;
- uint8_t * ui8p = NULL;
- unsigned char *ptr = NULL;
- uint64_t ret_value = 0;
-
- FUNC_ENTER_PACKAGE;
-
- HDassert(buf != NULL);
- HDassert(header != NULL);
- HDassert(H5FD__ONION_HEADER_VERSION_CURR == header->version);
-
- if (HDstrncmp((const char *)buf, H5FD__ONION_HEADER_SIGNATURE, 4))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid header signature")
-
- if (buf[4] != H5FD__ONION_HEADER_VERSION_CURR)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid header version")
-
- ptr = buf + 5;
- ui32 = 0;
- HDmemcpy(&ui32, ptr, 3);
- ui8p = (uint8_t *)&ui32;
- UINT32DECODE(ui8p, header->flags);
- ptr += 3;
-
- HDmemcpy(&ui32, ptr, 4);
- ui8p = (uint8_t *)&ui32;
- UINT32DECODE(ui8p, header->page_size);
- ptr += 4;
-
- HDmemcpy(&ui64, ptr, 8);
- ui8p = (uint8_t *)&ui64;
- UINT32DECODE(ui8p, header->origin_eof);
- ptr += 8;
-
- HDmemcpy(&ui64, ptr, 8);
- ui8p = (uint8_t *)&ui64;
- UINT32DECODE(ui8p, header->history_addr);
- ptr += 8;
-
- HDmemcpy(&ui64, ptr, 8);
- ui8p = (uint8_t *)&ui64;
- UINT32DECODE(ui8p, header->history_size);
- ptr += 8;
-
- sum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
-
- HDmemcpy(&ui32, ptr, 4);
- ui8p = (uint8_t *)&ui32;
- UINT32DECODE(ui8p, header->checksum);
- ptr += 4;
-
- if (sum != header->checksum)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "checksum mismatch")
-
- ret_value = (uint64_t)(ptr - buf);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5FD__onion_history_header_decode() */
-
-/*-----------------------------------------------------------------------------
- * Function: H5FD__onion_history_header_encode
- *
- * Purpose: Write history-header structure to the given buffer.
- * All multi-byte elements are stored in little-endian word order.
- *
- * Implementation must correspond with
- * H5FD__onion_history_header_decode().
- *
- * The destination buffer must be sufficiently large to hold the
- * encoded contents (H5FD__ONION_ENCODED_SIZE_HEADER).
- *
- * Return: Number of bytes written to buffer.
- * The checksum of the generated buffer contents (excluding the
- * checksum itself) is stored in the pointer `sum_out`).
- *-----------------------------------------------------------------------------
- */
-uint64_t
-H5FD__onion_history_header_encode(H5FD_onion_history_header_t *header, unsigned char *buf, uint32_t *sum_out)
-{
- unsigned char *ptr = buf;
- uint64_t ret_value = 0;
-
- FUNC_ENTER_PACKAGE_NOERR;
-
- HDassert(buf != NULL);
- HDassert(sum_out != NULL);
- HDassert(header != NULL);
- HDassert(H5FD__ONION_HEADER_VERSION_CURR == header->version);
- HDassert(0 == (header->flags & 0xFF000000)); /* max three bits long */
-
- HDmemcpy(ptr, H5FD__ONION_HEADER_SIGNATURE, 4);
- ptr += 4;
- HDmemcpy(ptr, (unsigned char *)&header->version, 1);
- ptr += 1;
- UINT32ENCODE(ptr, header->flags);
- ptr -= 1; /* truncate to three bytes */
- UINT32ENCODE(ptr, header->page_size);
- UINT64ENCODE(ptr, header->origin_eof);
- UINT64ENCODE(ptr, header->history_addr);
- UINT64ENCODE(ptr, header->history_size);
- *sum_out = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- UINT32ENCODE(ptr, *sum_out);
- ret_value = (uint64_t)(ptr - buf);
-
- FUNC_LEAVE_NOAPI(ret_value);
-} /* end H5FD__onion_history_header_encode() */
-
-/*-----------------------------------------------------------------------------
* Function: H5FD__onion_history_decode
*
* Purpose: Attempt to read a buffer and store it as a history
@@ -351,7 +146,7 @@ H5FD__onion_history_header_encode(H5FD_onion_history_header_t *header, unsigned
* Failure: 0
*-----------------------------------------------------------------------------
*/
-uint64_t
+size_t
H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
{
uint32_t ui32 = 0;
@@ -360,18 +155,18 @@ H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
uint64_t n_revisions = 0;
uint8_t * ui8p = NULL;
unsigned char *ptr = NULL;
- uint64_t ret_value = 0;
+ size_t ret_value = 0;
FUNC_ENTER_PACKAGE;
HDassert(buf != NULL);
HDassert(history != NULL);
- HDassert(H5FD__ONION_WHOLE_HISTORY_VERSION_CURR == history->version);
+ HDassert(H5FD__ONION_HISTORY_VERSION_CURR == history->version);
if (HDstrncmp((const char *)buf, "OWHS", 4))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid signature")
- if (H5FD__ONION_WHOLE_HISTORY_VERSION_CURR != buf[4])
+ if (H5FD__ONION_HISTORY_VERSION_CURR != buf[4])
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "invalid version")
ptr = buf + 8;
@@ -422,7 +217,7 @@ H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history)
if (sum != history->checksum)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "checksum mismatch")
- ret_value = (uint64_t)(ptr - buf);
+ ret_value = (size_t)(ptr - buf);
done:
FUNC_LEAVE_NOAPI(ret_value);
@@ -445,36 +240,36 @@ done:
*
* Return: Number of bytes written to buffer.
* The checksum of the generated buffer contents (excluding the
- * checksum itself) is stored in the pointer `sum_out`).
+ * checksum itself) is stored in the pointer `checksum`).
*-----------------------------------------------------------------------------
*/
-uint64_t
-H5FD__onion_history_encode(H5FD_onion_history_t *history, unsigned char *buf, uint32_t *sum_out)
+size_t
+H5FD__onion_history_encode(H5FD_onion_history_t *history, unsigned char *buf, uint32_t *checksum)
{
unsigned char *ptr = buf;
- uint32_t vers_u32 = (uint32_t)history->version; /* pad out unused bytes */
+ size_t vers_u32 = (uint32_t)history->version; /* pad out unused bytes */
FUNC_ENTER_PACKAGE_NOERR;
HDassert(history != NULL);
- HDassert(H5FD__ONION_WHOLE_HISTORY_VERSION_CURR == history->version);
+ HDassert(H5FD__ONION_HISTORY_VERSION_CURR == history->version);
HDassert(buf != NULL);
- HDassert(sum_out != NULL);
+ HDassert(checksum != NULL);
- HDmemcpy(ptr, H5FD__ONION_WHOLE_HISTORY_SIGNATURE, 4);
+ HDmemcpy(ptr, H5FD__ONION_HISTORY_SIGNATURE, 4);
ptr += 4;
UINT32ENCODE(ptr, vers_u32);
UINT64ENCODE(ptr, history->n_revisions);
if (history->n_revisions > 0) {
- HDassert(history->record_locs != NULL); /* TODO: error? */
+ HDassert(history->record_locs != NULL);
for (uint64_t i = 0; i < history->n_revisions; i++) {
UINT64ENCODE(ptr, history->record_locs[i].phys_addr);
UINT64ENCODE(ptr, history->record_locs[i].record_size);
UINT32ENCODE(ptr, history->record_locs[i].checksum);
}
}
- *sum_out = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- UINT32ENCODE(ptr, *sum_out);
+ *checksum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
+ UINT32ENCODE(ptr, *checksum);
- FUNC_LEAVE_NOAPI((uint64_t)(ptr - buf));
+ FUNC_LEAVE_NOAPI((size_t)(ptr - buf));
} /* end H5FD__onion_history_encode() */
diff --git a/src/H5FDonion_history.h b/src/H5FDonion_history.h
index e9034a2..47d566a 100644
--- a/src/H5FDonion_history.h
+++ b/src/H5FDonion_history.h
@@ -20,30 +20,10 @@
#define H5FDonion_history_H
/* Number of bytes to encode fixed-size components */
-#define H5FD__ONION_ENCODED_SIZE_HEADER 40
-#define H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY 20
+#define H5FD__ONION_ENCODED_SIZE_HISTORY 20
-/* Flags must align exactly one per bit, up to 24 bits */
-#define H5FD__ONION_HEADER_FLAG_WRITE_LOCK 0x1
-#define H5FD__ONION_HEADER_FLAG_DIVERGENT_HISTORY 0x2
-#define H5FD__ONION_HEADER_FLAG_PAGE_ALIGNMENT 0x4
-#define H5FD__ONION_HEADER_SIGNATURE "OHDH"
-#define H5FD__ONION_HEADER_VERSION_CURR 1
-
-#define H5FD__ONION_WHOLE_HISTORY_SIGNATURE "OWHS"
-#define H5FD__ONION_WHOLE_HISTORY_VERSION_CURR 1
-
-/* In-memory representation of the on-store onion history file header.
- */
-typedef struct H5FD_onion_history_header_t {
- uint8_t version;
- uint32_t flags; /* At most three bytes used! */
- uint32_t page_size;
- uint64_t origin_eof; /* Size of the 'original' canonical file */
- uint64_t history_addr;
- uint64_t history_size;
- uint32_t checksum;
-} H5FD_onion_history_header_t;
+#define H5FD__ONION_HISTORY_SIGNATURE "OWHS"
+#define H5FD__ONION_HISTORY_VERSION_CURR 1
/* In-memory representation of the on-store revision record.
* Used in the history.
@@ -66,20 +46,15 @@ typedef struct H5FD_onion_history_t {
#ifdef __cplusplus
extern "C" {
#endif
-H5_DLL herr_t H5FD__onion_ingest_history_header(H5FD_onion_history_header_t *hdr_out, H5FD_t *raw_file,
- haddr_t addr);
H5_DLL herr_t H5FD__onion_ingest_history(H5FD_onion_history_t *history_out, H5FD_t *raw_file, haddr_t addr,
haddr_t size);
-H5_DLL herr_t H5FD__onion_write_header(H5FD_onion_history_header_t *header, H5FD_t *backing_file);
-H5_DLL uint64_t H5FD__onion_write_history(H5FD_onion_history_t *history, H5FD_t *backing_file,
- haddr_t off_start, haddr_t filesize_curr);
-
-H5_DLL uint64_t H5FD__onion_history_header_decode(unsigned char *, H5FD_onion_history_header_t *);
-H5_DLL uint64_t H5FD__onion_history_header_encode(H5FD_onion_history_header_t *, unsigned char *, uint32_t *);
+H5_DLL uint64_t H5FD__onion_write_history(H5FD_onion_history_t *history, H5FD_t *file, haddr_t off_start,
+ haddr_t filesize_curr);
-H5_DLL uint64_t H5FD__onion_history_decode(unsigned char *, H5FD_onion_history_t *);
-H5_DLL uint64_t H5FD__onion_history_encode(H5FD_onion_history_t *, unsigned char *, uint32_t *);
+H5_DLL size_t H5FD__onion_history_decode(unsigned char *buf, H5FD_onion_history_t *history);
+H5_DLL size_t H5FD__onion_history_encode(H5FD_onion_history_t *history, unsigned char *buf,
+ uint32_t *checksum);
#ifdef __cplusplus
}
diff --git a/src/H5FDonion_index.c b/src/H5FDonion_index.c
index 66af1a1..f861f6d 100644
--- a/src/H5FDonion_index.c
+++ b/src/H5FDonion_index.c
@@ -83,7 +83,7 @@ H5FD__onion_ingest_revision_record(H5FD_onion_revision_record_t *r_out, H5FD_t *
}
/* Perform binary search on records to find target revision by ID.
- * As IDs are added sequentially, they are "guaranteed" to be sorted.
+ * As IDs are added sequentially, they are guaranteed to be sorted.
*/
while (range > 0) {
n = (range / 2) + low;
@@ -192,10 +192,10 @@ H5FD__onion_archival_index_is_valid(const H5FD_onion_archival_index_t *aix)
if (NULL == aix->list)
HGOTO_DONE(FALSE)
- /* Ensure list is sorted on logi_page field */
+ /* Ensure list is sorted on logical_page field */
if (aix->n_entries > 1)
for (uint64_t i = 1; i < aix->n_entries - 1; i++)
- if (aix->list[i + 1].logi_page <= aix->list[i].logi_page)
+ if (aix->list[i + 1].logical_page <= aix->list[i].logical_page)
HGOTO_DONE(FALSE)
done:
@@ -217,7 +217,7 @@ done:
*-----------------------------------------------------------------------------
*/
int
-H5FD__onion_archival_index_find(const H5FD_onion_archival_index_t *aix, uint64_t logi_page,
+H5FD__onion_archival_index_find(const H5FD_onion_archival_index_t *aix, uint64_t logical_page,
const H5FD_onion_index_entry_t **entry_out)
{
uint64_t low = 0;
@@ -239,7 +239,8 @@ H5FD__onion_archival_index_find(const H5FD_onion_archival_index_t *aix, uint64_t
range = high;
/* Trivial cases */
- if (aix->n_entries == 0 || logi_page > aix->list[high].logi_page || logi_page < aix->list[0].logi_page)
+ if (aix->n_entries == 0 || logical_page > aix->list[high].logical_page ||
+ logical_page < aix->list[0].logical_page)
HGOTO_DONE(0)
/*
@@ -251,12 +252,12 @@ H5FD__onion_archival_index_find(const H5FD_onion_archival_index_t *aix, uint64_t
HDassert(high < aix->n_entries);
n = low + (range / 2);
x = &(aix->list[n]);
- if (x->logi_page == logi_page) {
+ if (x->logical_page == logical_page) {
*entry_out = x; /* element found at fence */
ret_value = 1;
goto done;
}
- else if (x->logi_page < logi_page) {
+ else if (x->logical_page < logical_page) {
low = (n == high) ? high : n + 1;
}
else {
@@ -268,7 +269,7 @@ H5FD__onion_archival_index_find(const H5FD_onion_archival_index_t *aix, uint64_t
HDassert(high == low); /* one element */
/* n == low/high check because we may have tested it already above */
- if ((n != low || n != high) && (aix->list[low].logi_page == logi_page)) {
+ if ((n != low || n != high) && (aix->list[low].logical_page == logical_page)) {
*entry_out = &aix->list[low];
ret_value = 1;
}
@@ -406,7 +407,7 @@ H5FD__onion_revision_index_resize(H5FD_onion_revision_index_t *rix)
node = rix->_hash_table[i];
rix->_hash_table[i] = node->next;
node->next = NULL;
- key = node->entry_data.logi_page & (new_size - 1);
+ key = node->entry_data.logical_page & (new_size - 1);
if (NULL == new_table[key]) {
new_table[key] = node;
@@ -463,7 +464,7 @@ H5FD__onion_revision_index_insert(H5FD_onion_revision_index_t *rix, const H5FD_o
HGOTO_ERROR(H5E_RESOURCE, H5E_NONE_MINOR, FAIL, "unable to resize and hash table")
}
- key = entry->logi_page & (rix->_hash_table_size - 1);
+ key = entry->logical_page & (rix->_hash_table_size - 1);
HDassert(key < rix->_hash_table_size);
if (NULL == rix->_hash_table[key]) {
@@ -477,7 +478,7 @@ H5FD__onion_revision_index_insert(H5FD_onion_revision_index_t *rix, const H5FD_o
for (node = rix->_hash_table[key]; node != NULL; node = node->next) {
append_dest = &node->next; /* look for bucket tail */
- if (entry->logi_page == node->entry_data.logi_page) {
+ if (entry->logical_page == node->entry_data.logical_page) {
if (entry->phys_addr != node->entry_data.phys_addr) {
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "physical address mismatch");
}
@@ -517,7 +518,7 @@ done:
*-----------------------------------------------------------------------------
*/
int
-H5FD__onion_revision_index_find(const H5FD_onion_revision_index_t *rix, uint64_t logi_page,
+H5FD__onion_revision_index_find(const H5FD_onion_revision_index_t *rix, uint64_t logical_page,
const H5FD_onion_index_entry_t **entry_out)
{
uint64_t key = 0;
@@ -530,14 +531,14 @@ H5FD__onion_revision_index_find(const H5FD_onion_revision_index_t *rix, uint64_t
HDassert(rix->_hash_table);
HDassert(entry_out);
- key = logi_page & (rix->_hash_table_size - 1);
+ key = logical_page & (rix->_hash_table_size - 1);
HDassert(key < rix->_hash_table_size);
if (rix->_hash_table[key] != NULL) {
H5FD_onion_revision_index_hash_chain_node_t *node = NULL;
for (node = rix->_hash_table[key]; node != NULL; node = node->next) {
- if (logi_page == node->entry_data.logi_page) {
+ if (logical_page == node->entry_data.logical_page) {
*entry_out = &node->entry_data;
ret_value = 1;
break;
@@ -582,7 +583,7 @@ H5FD__onion_revision_index_find(const H5FD_onion_revision_index_t *rix, uint64_t
* Failure: 0
*-----------------------------------------------------------------------------
*/
-uint64_t
+size_t
H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_record_t *record)
{
uint32_t ui32 = 0;
@@ -593,7 +594,7 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
uint32_t comment_size = 0;
uint8_t * ui8p = NULL;
unsigned char *ptr = NULL;
- uint64_t ret_value = 0;
+ size_t ret_value = 0;
FUNC_ENTER_PACKAGE;
@@ -625,7 +626,7 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
HDmemcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
- UINT64DECODE(ui8p, record->logi_eof);
+ UINT64DECODE(ui8p, record->logical_eof);
ptr += 8;
HDmemcpy(&ui32, ptr, 4);
@@ -671,14 +672,14 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
HDmemcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
- UINT64DECODE(ui8p, entry->logi_page);
+ UINT64DECODE(ui8p, entry->logical_page);
ptr += 8;
- /* logi_page actually encoded as address; check and convert */
- if (entry->logi_page & (page_size - 1))
+ /* logical_page actually encoded as address; check and convert */
+ if (entry->logical_page & (page_size - 1))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "logical address does not align with page size")
- entry->logi_page = entry->logi_page >> record->archival_index.page_size_log2;
+ entry->logical_page = entry->logical_page >> record->archival_index.page_size_log2;
HDmemcpy(&ui64, ptr, 8);
ui8p = (uint8_t *)&ui64;
@@ -718,7 +719,7 @@ H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_recor
if (sum != record->checksum)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, 0, "checksum mismatch")
- ret_value = (uint64_t)(ptr - buf);
+ ret_value = (size_t)(ptr - buf);
done:
FUNC_LEAVE_NOAPI(ret_value);
@@ -741,12 +742,12 @@ done:
*
* Return: Number of bytes written to buffer.
* The checksum of the generated buffer contents (excluding the
- * checksum itself) is stored in the pointer `sum_out`).
+ * checksum itself) is stored in the pointer `checksum`).
*-----------------------------------------------------------------------------
*/
-uint64_t
+size_t
H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigned char *buf,
- uint32_t *sum_out)
+ uint32_t *checksum)
{
unsigned char *ptr = buf; /* original pointer */
uint32_t vers_u32 = (uint32_t)record->version; /* pad out unused bytes */
@@ -754,7 +755,7 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
FUNC_ENTER_PACKAGE_NOERR;
- HDassert(sum_out != NULL);
+ HDassert(checksum != NULL);
HDassert(buf != NULL);
HDassert(record != NULL);
HDassert(vers_u32 < 0x100);
@@ -770,7 +771,7 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
UINT64ENCODE(ptr, record->parent_revision_num);
HDmemcpy(ptr, record->time_of_creation, 16);
ptr += 16;
- UINT64ENCODE(ptr, record->logi_eof);
+ UINT64ENCODE(ptr, record->logical_eof);
UINT32ENCODE(ptr, page_size);
UINT64ENCODE(ptr, record->archival_index.n_entries);
UINT32ENCODE(ptr, record->comment_size);
@@ -785,7 +786,7 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
uint64_t logi_addr = 0;
entry = &record->archival_index.list[i];
- logi_addr = entry->logi_page << page_size_log2;
+ logi_addr = entry->logical_page << page_size_log2;
UINT64ENCODE(ptr, logi_addr);
UINT64ENCODE(ptr, entry->phys_addr);
@@ -800,14 +801,14 @@ H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigne
ptr += record->comment_size;
}
- *sum_out = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
- UINT32ENCODE(ptr, *sum_out);
+ *checksum = H5_checksum_fletcher32(buf, (size_t)(ptr - buf));
+ UINT32ENCODE(ptr, *checksum);
- FUNC_LEAVE_NOAPI((uint64_t)(ptr - buf));
+ FUNC_LEAVE_NOAPI((size_t)(ptr - buf));
} /* end H5FD__onion_revision_record_encode() */
/*-----------------------------------------------------------------------------
- * Callback for comparisons in sorting archival index entries by logi_page.
+ * Callback for comparisons in sorting archival index entries by logical_page.
*-----------------------------------------------------------------------------
*/
static int
@@ -816,9 +817,9 @@ H5FD__onion_archival_index_list_sort_cmp(const void *_a, const void *_b)
const H5FD_onion_index_entry_t *a = (const H5FD_onion_index_entry_t *)_a;
const H5FD_onion_index_entry_t *b = (const H5FD_onion_index_entry_t *)_b;
- if (a->logi_page < b->logi_page)
+ if (a->logical_page < b->logical_page)
return -1;
- else if (a->logi_page > b->logi_page)
+ else if (a->logical_page > b->logical_page)
return 1;
return 0;
} /* end H5FD__onion_archival_index_list_sort_cmp() */
@@ -898,7 +899,7 @@ H5FD__onion_merge_revision_index_into_archival_index(const H5FD_onion_revision_i
const H5FD_onion_index_entry_t *entry = NULL;
/* Add only if page not already added from revision index */
- if (H5FD__onion_archival_index_find(&new_aix, aix->list[i].logi_page, &entry) == 0) {
+ if (H5FD__onion_archival_index_find(&new_aix, aix->list[i].logical_page, &entry) == 0) {
HDmemcpy(&kept_list[n_kept], &aix->list[i], sizeof(H5FD_onion_index_entry_t));
n_kept++;
}
diff --git a/src/H5FDonion_index.h b/src/H5FDonion_index.h
index 0850537..2027076 100644
--- a/src/H5FDonion_index.h
+++ b/src/H5FDonion_index.h
@@ -38,16 +38,20 @@
* Structure H5FD__onion_index_entry
*
* Purpose: Map a page in the logical file to a 'physical address' in the
- * backing store.
+ * onion file.
*
- * logi_page: Page 'id' in the logical file.
+ * logical_page:
*
- * phys_addr: Address/offset of start of page in the backing store.
+ * Page 'id' in the logical file.
+ *
+ * phys_addr:
+ *
+ * Address/offset of start of page in the onion file.
*
*-----------------------------------------------------------------------------
*/
typedef struct H5FD_onion_index_entry_t {
- uint64_t logi_page;
+ uint64_t logical_page;
haddr_t phys_addr;
} H5FD_onion_index_entry_t;
@@ -62,7 +66,7 @@ typedef struct H5FD_onion_index_entry_t {
* Must equal H5FD__ONION_ARCHIVAL_INDEX_VERSION_CURR to be
* considered valid.
*
- * page_size: Interval to which the `logi_page` component of each list
+ * page_size: Interval to which the `logical_page` component of each list
* entry must align.
* Value is taken from the onion history data; must not change
* following onionization or file or creation of onion file.
@@ -71,7 +75,7 @@ typedef struct H5FD_onion_index_entry_t {
*
* list: Pointer to array of archival index entries.
* Cannot be NULL.
- * Entries must be sorted by `logi_page_id` in ascending order.
+ * Entries must be sorted by `logical_page_id` in ascending order.
*
*-----------------------------------------------------------------------------
*/
@@ -108,7 +112,7 @@ typedef struct H5FD_onion_revision_record_t {
uint64_t revision_num;
uint64_t parent_revision_num;
char time_of_creation[16];
- uint64_t logi_eof;
+ uint64_t logical_eof;
H5FD_onion_archival_index_t archival_index;
uint32_t comment_size;
char * comment;
@@ -135,9 +139,9 @@ H5_DLL int H5FD__onion_revision_index_find(const H5FD_onion_revision_index_t *,
H5_DLL herr_t H5FD__onion_merge_revision_index_into_archival_index(const H5FD_onion_revision_index_t *,
H5FD_onion_archival_index_t *);
-H5_DLL uint64_t H5FD__onion_revision_record_decode(unsigned char *, H5FD_onion_revision_record_t *);
-H5_DLL uint64_t H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *, unsigned char *,
- uint32_t *);
+H5_DLL size_t H5FD__onion_revision_record_decode(unsigned char *buf, H5FD_onion_revision_record_t *record);
+H5_DLL size_t H5FD__onion_revision_record_encode(H5FD_onion_revision_record_t *record, unsigned char *buf,
+ uint32_t *checksum);
#ifdef __cplusplus
}
diff --git a/src/H5FDonion_priv.h b/src/H5FDonion_priv.h
index da4b2d1..031c132 100644
--- a/src/H5FDonion_priv.h
+++ b/src/H5FDonion_priv.h
@@ -21,6 +21,7 @@
#ifndef H5FDonion_priv_H
#define H5FDonion_priv_H
+#include "H5FDonion_header.h"
#include "H5FDonion_history.h"
#include "H5FDonion_index.h"
diff --git a/src/Makefile.am b/src/Makefile.am
index fc6ccfd..c468f36 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -62,7 +62,7 @@ libhdf5_la_SOURCES= H5.c H5checksum.c H5dbg.c H5lib_settings.c H5system.c \
H5FA.c H5FAcache.c H5FAdbg.c H5FAdblock.c H5FAdblkpage.c H5FAhdr.c \
H5FAint.c H5FAstat.c H5FAtest.c \
H5FD.c H5FDcore.c H5FDfamily.c H5FDint.c H5FDlog.c H5FDmulti.c \
- H5FDonion.c H5FDonion_history.c H5FDonion_index.c \
+ H5FDonion.c H5FDonion_header.c H5FDonion_history.c H5FDonion_index.c \
H5FDperform.c H5FDsec2.c H5FDspace.c \
H5FDsplitter.c H5FDstdio.c H5FDtest.c \
H5FL.c H5FO.c H5FS.c H5FScache.c H5FSdbg.c H5FSint.c H5FSsection.c \
diff --git a/test/onion.c b/test/onion.c
index 7e2a17d..6633918 100644
--- a/test/onion.c
+++ b/test/onion.c
@@ -52,7 +52,7 @@ struct onion_filepaths {
struct expected_revision {
uint64_t revision_num;
uint64_t parent_revision_num;
- uint64_t logi_eof;
+ uint64_t logical_eof;
uint64_t n_index_entries;
const char *comment;
};
@@ -313,7 +313,7 @@ test_revision_index(void)
{
H5FD_onion_revision_index_t *rix_p = NULL;
H5FD_onion_index_entry_t entry = {
- 42, /* logi_page */
+ 42, /* logical_page */
111112, /* phys_addr */
};
const H5FD_onion_index_entry_t *entry_out_p = NULL;
@@ -331,7 +331,7 @@ test_revision_index(void)
/* Test missed search */
- if (H5FD__onion_revision_index_find(rix_p, entry.logi_page, &entry_out_p) != 0)
+ if (H5FD__onion_revision_index_find(rix_p, entry.logical_page, &entry_out_p) != 0)
TEST_ERROR;
/* Test successful insertion and lookup */
@@ -342,45 +342,45 @@ test_revision_index(void)
if (1 != rix_p->n_entries)
TEST_ERROR;
/* Lookup failed */
- if (H5FD__onion_revision_index_find(rix_p, entry.logi_page, &entry_out_p) < 0)
+ if (H5FD__onion_revision_index_find(rix_p, entry.logical_page, &entry_out_p) < 0)
TEST_ERROR;
/* Failure to set output parameter */
if (NULL == entry_out_p)
TEST_ERROR;
- if (entry.logi_page != entry_out_p->logi_page)
+ if (entry.logical_page != entry_out_p->logical_page)
TEST_ERROR;
/* Seeking missing page should miss */
- if (H5FD__onion_revision_index_find(rix_p, entry.logi_page + 1, &entry_out_p) != 0)
+ if (H5FD__onion_revision_index_find(rix_p, entry.logical_page + 1, &entry_out_p) != 0)
TEST_ERROR;
/* Test / demonstrate stored entry independent of user object */
- entry.logi_page = 100;
- entry.phys_addr = 101;
+ entry.logical_page = 100;
+ entry.phys_addr = 101;
if (H5FD__onion_revision_index_insert(rix_p, &entry) < 0)
TEST_ERROR;
if (2 != rix_p->n_entries)
TEST_ERROR;
- entry.logi_page = 500;
- entry.phys_addr = 501;
+ entry.logical_page = 500;
+ entry.phys_addr = 501;
if (H5FD__onion_revision_index_find(rix_p, 100, &entry_out_p) < 0)
TEST_ERROR;
- if (100 != entry_out_p->logi_page || 101 != entry_out_p->phys_addr)
+ if (100 != entry_out_p->logical_page || 101 != entry_out_p->phys_addr)
TEST_ERROR;
/* Demonstrate updating an entry */
/* Error cases */
- entry.logi_page = 100; /* phys_addr still 501, checksum bbbbbbbb */
+ entry.logical_page = 100; /* phys_addr still 501, checksum bbbbbbbb */
if (H5FD__onion_revision_index_insert(rix_p, &entry) >= 0)
TEST_ERROR; /* all components but sum must match */
entry.phys_addr = 101;
/* Successful update */
- entry.logi_page = 100;
- entry.phys_addr = 101;
+ entry.logical_page = 100;
+ entry.phys_addr = 101;
if (H5FD__onion_revision_index_insert(rix_p, &entry) < 0)
TEST_ERROR;
@@ -389,7 +389,7 @@ test_revision_index(void)
TEST_ERROR;
if (H5FD__onion_revision_index_find(rix_p, 100, &entry_out_p) < 0)
TEST_ERROR;
- if (100 != entry_out_p->logi_page || 101 != entry_out_p->phys_addr)
+ if (100 != entry_out_p->logical_page || 101 != entry_out_p->phys_addr)
TEST_ERROR;
if (H5FD__onion_revision_index_destroy(rix_p) < 0)
@@ -420,7 +420,7 @@ test_revision_index_collisions(void)
{
H5FD_onion_revision_index_t *rix_p = NULL;
H5FD_onion_index_entry_t entry = {
- 0, /* logi_page */
+ 0, /* logical_page */
0, /* phys_addr */
};
const H5FD_onion_index_entry_t *entry_out_p = NULL;
@@ -433,8 +433,8 @@ test_revision_index_collisions(void)
TEST_ERROR;
for (uint64_t i = 0; i < n_insert; i++) {
- entry.phys_addr = i;
- entry.logi_page = U64_EXP2(i) + offset_from_power;
+ entry.phys_addr = i;
+ entry.logical_page = U64_EXP2(i) + offset_from_power;
if (H5FD__onion_revision_index_insert(rix_p, &entry) < 0)
TEST_ERROR;
}
@@ -481,7 +481,7 @@ test_revision_index_resizing(void)
{
H5FD_onion_revision_index_t *rix_p = NULL;
H5FD_onion_index_entry_t entry = {
- 0, /* logi_page */
+ 0, /* logical_page */
0, /* phys_addr */
};
const H5FD_onion_index_entry_t *entry_out_p = NULL;
@@ -493,8 +493,8 @@ test_revision_index_resizing(void)
TEST_ERROR;
for (uint64_t i = 0; i < n_insert; i++) {
- entry.logi_page = i;
- entry.phys_addr = ((uint64_t)(-1) - i);
+ entry.logical_page = i;
+ entry.phys_addr = ((uint64_t)(-1) - i);
if (H5FD__onion_revision_index_insert(rix_p, &entry) < 0)
TEST_ERROR;
}
@@ -538,7 +538,7 @@ test_revision_index_to_archival_index(void)
{
H5FD_onion_revision_index_t *rix_p = NULL;
H5FD_onion_index_entry_t rix_entry = {
- 0, /* logi_page */
+ 0, /* logical_page */
0, /* phys_addr */
};
H5FD_onion_archival_index_t aix = {
@@ -562,8 +562,8 @@ test_revision_index_to_archival_index(void)
for (uint64_t i = 0; i < n_insert; i++) {
uint64_t n = 2003 * (n_insert - i) + 47;
- rix_entry.logi_page = n;
- rix_entry.phys_addr = n * 13;
+ rix_entry.logical_page = n;
+ rix_entry.phys_addr = n * 13;
if (H5FD__onion_revision_index_insert(rix_p, &rix_entry) < 0)
TEST_ERROR;
}
@@ -591,7 +591,7 @@ test_revision_index_to_archival_index(void)
aix_entry_p = &aix.list[i];
- if (aix_entry_p->logi_page != n)
+ if (aix_entry_p->logical_page != n)
TEST_ERROR;
if (aix_entry_p->phys_addr != (n * 13))
TEST_ERROR;
@@ -603,11 +603,11 @@ test_revision_index_to_archival_index(void)
aix.list = NULL;
if (NULL == (aix.list = H5MM_malloc(sizeof(H5FD_onion_index_entry_t) * 2)))
TEST_ERROR;
- aix.list[0].logi_page = 47;
- aix.list[0].phys_addr = 47 * 13;
- aix.list[1].logi_page = (2003 * (n_insert + 1) + 47);
- aix.list[1].phys_addr = (2003 * (n_insert + 1) + 47) * 13;
- aix.n_entries = 2;
+ aix.list[0].logical_page = 47;
+ aix.list[0].phys_addr = 47 * 13;
+ aix.list[1].logical_page = (2003 * (n_insert + 1) + 47);
+ aix.list[1].phys_addr = (2003 * (n_insert + 1) + 47) * 13;
+ aix.n_entries = 2;
if (!H5FD__onion_archival_index_is_valid(&aix))
TEST_ERROR;
@@ -627,7 +627,7 @@ test_revision_index_to_archival_index(void)
aix_entry_p = &aix.list[i];
- if (aix_entry_p->logi_page != n)
+ if (aix_entry_p->logical_page != n)
TEST_ERROR;
if (aix_entry_p->phys_addr != (n * 13))
TEST_ERROR;
@@ -639,11 +639,11 @@ test_revision_index_to_archival_index(void)
aix.list = NULL;
if (NULL == (aix.list = H5MM_malloc(sizeof(H5FD_onion_index_entry_t) * 2)))
TEST_ERROR;
- aix.list[0].logi_page = 2003 * (n_insert / 2) + 47;
- aix.list[0].phys_addr = 103;
- aix.list[1].logi_page = 2003 * (n_insert / 2 + 1) + 47;
- aix.list[1].phys_addr = 101;
- aix.n_entries = 2;
+ aix.list[0].logical_page = 2003 * (n_insert / 2) + 47;
+ aix.list[0].phys_addr = 103;
+ aix.list[1].logical_page = 2003 * (n_insert / 2 + 1) + 47;
+ aix.list[1].phys_addr = 101;
+ aix.n_entries = 2;
if (!H5FD__onion_archival_index_is_valid(&aix))
TEST_ERROR;
@@ -663,7 +663,7 @@ test_revision_index_to_archival_index(void)
aix_entry_p = &aix.list[i];
- if (aix_entry_p->logi_page != n)
+ if (aix_entry_p->logical_page != n)
TEST_ERROR;
if (aix_entry_p->phys_addr != (n * 13))
TEST_ERROR;
@@ -898,19 +898,19 @@ test_header_encode_decode(void)
88, 0, 0, 0, 0, 0, 0, 0, /* history_size */
0, 0, 0, 0 /* sum populated below */
};
- unsigned char * ptr = NULL;
- uint32_t sum = 0;
- uint32_t sum_out = 0;
- size_t i = 0;
- uint64_t size_ret = 0;
- H5FD_onion_history_header_t hdr;
- H5FD_onion_history_header_t hdr_out;
+ unsigned char * ptr = NULL;
+ uint32_t checksum = 0;
+ uint32_t checksum_out = 0;
+ size_t i = 0;
+ uint64_t size_ret = 0;
+ H5FD_onion_header_t hdr;
+ H5FD_onion_header_t hdr_out;
TESTING("encode/decode history header");
- sum = H5_checksum_fletcher32(exp, H5FD__ONION_ENCODED_SIZE_HEADER - 4);
- ptr = exp + H5FD__ONION_ENCODED_SIZE_HEADER - 4;
- UINT32ENCODE(ptr, sum);
+ checksum = H5_checksum_fletcher32(exp, H5FD__ONION_ENCODED_SIZE_HEADER - 4);
+ ptr = exp + H5FD__ONION_ENCODED_SIZE_HEADER - 4;
+ UINT32ENCODE(ptr, checksum);
hdr.version = H5FD__ONION_HEADER_VERSION_CURR;
hdr.flags = 12;
@@ -918,10 +918,10 @@ test_header_encode_decode(void)
hdr.history_addr = 123456;
hdr.history_size = 88;
- if (H5FD__onion_history_header_encode(&hdr, buf, &sum_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
+ if (H5FD__onion_header_encode(&hdr, buf, &checksum_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
TEST_ERROR;
- if (sum != sum_out)
+ if (checksum != checksum_out)
TEST_ERROR;
for (i = 0; i < H5FD__ONION_ENCODED_SIZE_HEADER; i++) {
@@ -943,7 +943,7 @@ test_header_encode_decode(void)
exp[3] = 'X'; /* invalidate encoded signature */
H5E_BEGIN_TRY
{
- size_ret = H5FD__onion_history_header_decode(exp, &hdr_out);
+ size_ret = H5FD__onion_header_decode(exp, &hdr_out);
}
H5E_END_TRY;
if (0 != size_ret)
@@ -957,7 +957,7 @@ test_header_encode_decode(void)
exp[4] = 0; /* encoded version 0?!? */
H5E_BEGIN_TRY
{
- size_ret = H5FD__onion_history_header_decode(exp, &hdr_out);
+ size_ret = H5FD__onion_header_decode(exp, &hdr_out);
}
H5E_END_TRY;
if (0 != size_ret)
@@ -966,7 +966,7 @@ test_header_encode_decode(void)
exp[4] = H5FD__ONION_HEADER_VERSION_CURR + 1; /* encoded super-version?! */
H5E_BEGIN_TRY
{
- size_ret = H5FD__onion_history_header_decode(exp, &hdr_out);
+ size_ret = H5FD__onion_header_decode(exp, &hdr_out);
}
H5E_END_TRY;
if (0 != size_ret)
@@ -977,7 +977,7 @@ test_header_encode_decode(void)
/* Valid header can be decoded */
- if (H5FD__onion_history_header_decode(buf, &hdr_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
+ if (H5FD__onion_header_decode(buf, &hdr_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
TEST_ERROR;
if (H5FD__ONION_HEADER_VERSION_CURR != hdr_out.version)
TEST_ERROR;
@@ -1017,30 +1017,30 @@ test_history_encode_decode_empty(void)
1, 0, 0, 0, /* NOTE: update version w/ "current" as needed */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* sum populated below */
};
- unsigned char * ptr = NULL;
- uint32_t sum = 0;
- uint32_t sum_out = 0;
- size_t i = 0;
- uint64_t size_ret = 0;
- H5FD_onion_history_t history = {
- H5FD__ONION_WHOLE_HISTORY_VERSION_CURR, 0, /* n_revisions */
- NULL, /* list */
- 0, /* checksum */
+ unsigned char * ptr = NULL;
+ uint32_t checksum = 0;
+ uint32_t checksum_out = 0;
+ size_t i = 0;
+ uint64_t size_ret = 0;
+ H5FD_onion_history_t history = {
+ H5FD__ONION_HISTORY_VERSION_CURR, 0, /* n_revisions */
+ NULL, /* list */
+ 0, /* checksum */
};
H5FD_onion_history_t history_out = {
- H5FD__ONION_WHOLE_HISTORY_VERSION_CURR, 0, /* n_revisions */
- NULL, /* list */
- 0, /* checksum */
+ H5FD__ONION_HISTORY_VERSION_CURR, 0, /* n_revisions */
+ NULL, /* list */
+ 0, /* checksum */
};
TESTING("encode/decode history (empty and failures)");
/* Generage checksum but don't store it yet */
- sum = H5_checksum_fletcher32(exp, H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY - 4);
- ptr = exp + H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY - 4;
- UINT32ENCODE(ptr, sum);
+ checksum = H5_checksum_fletcher32(exp, H5FD__ONION_ENCODED_SIZE_HISTORY - 4);
+ ptr = exp + H5FD__ONION_ENCODED_SIZE_HISTORY - 4;
+ UINT32ENCODE(ptr, checksum);
- if (H5FD__onion_history_encode(&history, buf, &sum_out) != H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY)
+ if (H5FD__onion_history_encode(&history, buf, &checksum_out) != H5FD__ONION_ENCODED_SIZE_HISTORY)
TEST_ERROR;
for (i = 0; i < 20; i++) {
if (exp[i] != buf[i]) {
@@ -1048,9 +1048,9 @@ test_history_encode_decode_empty(void)
TEST_ERROR;
}
}
- if (sum != sum_out)
+ if (checksum != checksum_out)
TEST_ERROR;
- history.checksum = sum; /* set to compare later */
+ history.checksum = checksum; /* set to compare later */
/* Invalid signature prevents decoding */
@@ -1076,7 +1076,7 @@ test_history_encode_decode_empty(void)
if (0 != size_ret)
TEST_ERROR;
- exp[4] = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR + 1;
+ exp[4] = H5FD__ONION_HISTORY_VERSION_CURR + 1;
H5E_BEGIN_TRY
{
size_ret = H5FD__onion_history_decode(exp, &history_out);
@@ -1085,13 +1085,13 @@ test_history_encode_decode_empty(void)
if (0 != size_ret)
TEST_ERROR;
- exp[4] = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR; /* reset */
+ exp[4] = H5FD__ONION_HISTORY_VERSION_CURR; /* reset */
/* Valid summary can be decoded */
- if (H5FD__onion_history_decode(buf, &history_out) != H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY)
+ if (H5FD__onion_history_decode(buf, &history_out) != H5FD__ONION_ENCODED_SIZE_HISTORY)
TEST_ERROR;
- if (H5FD__ONION_WHOLE_HISTORY_VERSION_CURR != history_out.version)
+ if (H5FD__ONION_HISTORY_VERSION_CURR != history_out.version)
TEST_ERROR;
if (history.n_revisions != history_out.n_revisions)
TEST_ERROR;
@@ -1134,21 +1134,21 @@ test_history_encode_decode(void)
/* final checksum */
0, 0, 0, 0 /* sum populated below */
};
- unsigned char * buf_p = NULL;
- uint32_t sum_out = 0;
- size_t i = 0;
- H5FD_onion_history_t history = {
- H5FD__ONION_WHOLE_HISTORY_VERSION_CURR, 3, /* n_revisions */
- NULL, /* list set below */
- 0, /* checksum not set by us */
+ unsigned char * buf_p = NULL;
+ uint32_t checksum_out = 0;
+ size_t i = 0;
+ H5FD_onion_history_t history = {
+ H5FD__ONION_HISTORY_VERSION_CURR, 3, /* n_revisions */
+ NULL, /* list set below */
+ 0, /* checksum not set by us */
};
H5FD_onion_history_t history_out = {
- H5FD__ONION_WHOLE_HISTORY_VERSION_CURR, 0, /* n_revisions must start as zero */
- NULL, /* list */
- 0, /* checksum */
+ H5FD__ONION_HISTORY_VERSION_CURR, 0, /* n_revisions must start as zero */
+ NULL, /* list */
+ 0, /* checksum */
};
- uint64_t exp_size = H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY +
- H5FD__ONION_ENCODED_SIZE_RECORD_POINTER * history.n_revisions;
+ size_t exp_size =
+ H5FD__ONION_ENCODED_SIZE_HISTORY + H5FD__ONION_ENCODED_SIZE_RECORD_POINTER * history.n_revisions;
TESTING("encode/decode history");
@@ -1169,7 +1169,7 @@ test_history_encode_decode(void)
/* Populate revision pointer sums in exp */
for (i = 0; i < history.n_revisions; i++) {
- uint64_t history_pre = H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY - 4;
+ uint64_t history_pre = H5FD__ONION_ENCODED_SIZE_HISTORY - 4;
uint64_t ptr_pre = H5FD__ONION_ENCODED_SIZE_RECORD_POINTER - 4;
uint64_t ptr_size = H5FD__ONION_ENCODED_SIZE_RECORD_POINTER;
@@ -1187,13 +1187,13 @@ test_history_encode_decode(void)
if (NULL == (buf = HDmalloc(exp_size)))
TEST_ERROR;
- if (H5FD__onion_history_encode(&history, buf, &sum_out) != exp_size)
+ if (H5FD__onion_history_encode(&history, buf, &checksum_out) != exp_size)
TEST_ERROR;
for (i = 0; i < exp_size; i++) {
if (exp[i] != buf[i])
TEST_ERROR;
}
- if (history.checksum != sum_out)
+ if (history.checksum != checksum_out)
TEST_ERROR;
/* Initial decode, gets always-present components */
@@ -1201,7 +1201,7 @@ test_history_encode_decode(void)
history_out.n_revisions = 0; /* must be initialized to 0 */
if (H5FD__onion_history_decode(exp, &history_out) != exp_size)
TEST_ERROR;
- if (H5FD__ONION_WHOLE_HISTORY_VERSION_CURR != history_out.version)
+ if (H5FD__ONION_HISTORY_VERSION_CURR != history_out.version)
TEST_ERROR;
if (history.n_revisions != history_out.n_revisions)
TEST_ERROR;
@@ -1217,7 +1217,7 @@ test_history_encode_decode(void)
if (H5FD__onion_history_decode(exp, &history_out) != exp_size)
TEST_ERROR;
- if (H5FD__ONION_WHOLE_HISTORY_VERSION_CURR != history_out.version)
+ if (H5FD__ONION_HISTORY_VERSION_CURR != history_out.version)
TEST_ERROR;
if (history.n_revisions != history_out.n_revisions)
TEST_ERROR;
@@ -1307,7 +1307,7 @@ test_revision_record_encode_decode(void)
size_t i = 0;
uint64_t size_ret;
H5FD_onion_revision_record_t r_out;
- uint32_t sum_out = 0;
+ uint32_t checksum = 0;
char comment[25] = "Example comment message.";
H5FD_onion_revision_record_t record = {
H5FD__ONION_REVISION_RECORD_VERSION_CURR,
@@ -1325,9 +1325,9 @@ test_revision_record_encode_decode(void)
comment, /* comment */
0, /* checksum (computed later) */
};
- uint64_t exp_size = H5FD__ONION_ENCODED_SIZE_REVISION_RECORD +
- (H5FD__ONION_ENCODED_SIZE_INDEX_ENTRY * record.archival_index.n_entries) +
- HDstrlen("Example comment message.") + 1;
+ size_t exp_size = H5FD__ONION_ENCODED_SIZE_REVISION_RECORD +
+ (H5FD__ONION_ENCODED_SIZE_INDEX_ENTRY * record.archival_index.n_entries) +
+ HDstrlen("Example comment message.") + 1;
r_out.archival_index.list = NULL;
r_out.comment = NULL;
@@ -1339,15 +1339,15 @@ test_revision_record_encode_decode(void)
if (NULL == record.archival_index.list)
TEST_ERROR;
- /* Convert logi_page and should match address in expected buffer */
- record.archival_index.list[0].logi_page = 491ull;
- record.archival_index.list[0].phys_addr = 587ull;
- record.archival_index.list[1].logi_page = 751ull;
- record.archival_index.list[1].phys_addr = 167ull;
- record.archival_index.list[2].logi_page = 8589934933ull;
- record.archival_index.list[2].phys_addr = 8589934609ull;
- record.archival_index.list[3].logi_page = 590ull;
- record.archival_index.list[3].phys_addr = 433ull;
+ /* Convert logical_page and should match address in expected buffer */
+ record.archival_index.list[0].logical_page = 491ull;
+ record.archival_index.list[0].phys_addr = 587ull;
+ record.archival_index.list[1].logical_page = 751ull;
+ record.archival_index.list[1].phys_addr = 167ull;
+ record.archival_index.list[2].logical_page = 8589934933ull;
+ record.archival_index.list[2].phys_addr = 8589934609ull;
+ record.archival_index.list[3].logical_page = 590ull;
+ record.archival_index.list[3].phys_addr = 433ull;
/* Set expected checksum for each archival index entry in buffer */
for (i = 0; i < record.archival_index.n_entries; i++) {
@@ -1355,13 +1355,13 @@ test_revision_record_encode_decode(void)
uint64_t idx_pre = H5FD__ONION_ENCODED_SIZE_INDEX_ENTRY - 4;
uint64_t idx_size = H5FD__ONION_ENCODED_SIZE_INDEX_ENTRY;
- buf_p = exp + rec_pre + idx_size * i;
- sum_out = H5_checksum_fletcher32(buf_p, idx_pre);
+ buf_p = exp + rec_pre + idx_size * i;
+ checksum = H5_checksum_fletcher32(buf_p, idx_pre);
buf_p += idx_pre;
- UINT32ENCODE(buf_p, sum_out);
+ UINT32ENCODE(buf_p, checksum);
}
- sum_out = 0;
+ checksum = 0;
record.checksum = H5_checksum_fletcher32(exp, exp_size - 4);
buf_p = exp + exp_size - 4;
@@ -1380,7 +1380,7 @@ test_revision_record_encode_decode(void)
/* Test encode */
- if (H5FD__onion_revision_record_encode(&record, buf, &sum_out) != exp_size)
+ if (H5FD__onion_revision_record_encode(&record, buf, &checksum) != exp_size)
TEST_ERROR;
hbool_t badness = FALSE;
@@ -1410,7 +1410,7 @@ test_revision_record_encode_decode(void)
}
if (badness)
TEST_ERROR;
- if (record.checksum != sum_out)
+ if (record.checksum != checksum)
TEST_ERROR;
/* Test decode (malformed encoding) */
@@ -1501,7 +1501,7 @@ test_revision_record_encode_decode(void)
if (ep->phys_addr != ap->phys_addr)
TEST_ERROR;
- if (ep->logi_page != ap->logi_page)
+ if (ep->logical_page != ap->logical_page)
TEST_ERROR;
}
@@ -1589,7 +1589,7 @@ static int
verify_history_as_expected_onion(H5FD_t *raw_file, struct expected_history *filter)
{
unsigned char * buf = NULL; /* allocated area for actual file bytes */
- H5FD_onion_history_header_t hdr_out;
+ H5FD_onion_header_t hdr_out;
H5FD_onion_history_t history_out;
H5FD_onion_revision_record_t rev_out;
uint64_t filesize = 0;
@@ -1598,7 +1598,7 @@ verify_history_as_expected_onion(H5FD_t *raw_file, struct expected_history *filt
hdr_out.version = H5FD__ONION_HEADER_VERSION_CURR;
- history_out.version = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR;
+ history_out.version = H5FD__ONION_HISTORY_VERSION_CURR;
history_out.n_revisions = 0;
history_out.record_locs = NULL;
@@ -1617,7 +1617,7 @@ verify_history_as_expected_onion(H5FD_t *raw_file, struct expected_history *filt
if (H5FDread(raw_file, H5FD_MEM_DRAW, H5P_DEFAULT, 0, readsize, buf) < 0)
TEST_ERROR;
- readsize = H5FD__onion_history_header_decode(buf, &hdr_out);
+ readsize = H5FD__onion_header_decode(buf, &hdr_out);
if (0 == readsize)
TEST_ERROR;
if (H5FD__ONION_HEADER_VERSION_CURR != hdr_out.version)
@@ -1648,7 +1648,7 @@ verify_history_as_expected_onion(H5FD_t *raw_file, struct expected_history *filt
readsize = H5FD__onion_history_decode(buf, &history_out);
if (0 == readsize)
TEST_ERROR;
- if (H5FD__ONION_WHOLE_HISTORY_VERSION_CURR != history_out.version)
+ if (H5FD__ONION_HISTORY_VERSION_CURR != history_out.version)
TEST_ERROR;
if (HDmemcmp(&history_out.checksum, &buf[readsize - 4], 4) != 0)
TEST_ERROR;
@@ -1712,7 +1712,7 @@ verify_history_as_expected_onion(H5FD_t *raw_file, struct expected_history *filt
TEST_ERROR;
if (erp->parent_revision_num != rev_out.parent_revision_num)
TEST_ERROR;
- if (erp->logi_eof != rev_out.logi_eof)
+ if (erp->logical_eof != rev_out.logical_eof)
TEST_ERROR;
/* Final read, get variable-length data */
@@ -1794,7 +1794,7 @@ verify_stored_onion_create_0_open(struct onion_filepaths *paths, H5FD_onion_fapl
'O', 'W', 'H', 'S', 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* checksum encoded below */
};
unsigned char *ptr = NULL;
- uint32_t sum = 0;
+ uint32_t checksum = 0;
hid_t onion_fapl_id = H5I_INVALID_HID;
onion_fapl_id = H5Pcreate(H5P_FILE_ACCESS);
@@ -1806,15 +1806,15 @@ verify_stored_onion_create_0_open(struct onion_filepaths *paths, H5FD_onion_fapl
/* Finish populating expected header bytes */
ptr = hdr_exp_bytes + 8; /* WARNING: must match format */
UINT32ENCODE(ptr, onion_info->page_size);
- sum = H5_checksum_fletcher32(hdr_exp_bytes, H5FD__ONION_ENCODED_SIZE_HEADER - 4);
- ptr = hdr_exp_bytes + H5FD__ONION_ENCODED_SIZE_HEADER - 4;
- UINT32ENCODE(ptr, sum);
+ checksum = H5_checksum_fletcher32(hdr_exp_bytes, H5FD__ONION_ENCODED_SIZE_HEADER - 4);
+ ptr = hdr_exp_bytes + H5FD__ONION_ENCODED_SIZE_HEADER - 4;
+ UINT32ENCODE(ptr, checksum);
ptr = NULL;
/* Finish populating expected history bytes */
- sum = H5_checksum_fletcher32(history_exp_bytes, H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY - 4);
- ptr = history_exp_bytes + H5FD__ONION_ENCODED_SIZE_WHOLE_HISTORY - 4;
- UINT32ENCODE(ptr, sum);
+ checksum = H5_checksum_fletcher32(history_exp_bytes, H5FD__ONION_ENCODED_SIZE_HISTORY - 4);
+ ptr = history_exp_bytes + H5FD__ONION_ENCODED_SIZE_HISTORY - 4;
+ UINT32ENCODE(ptr, checksum);
ptr = NULL;
/* Look at h5 file: should have zero bytes */
@@ -2097,7 +2097,7 @@ test_create_oniontarget(hbool_t truncate_canonical, hbool_t with_initial_data)
filter.revisions[0].n_index_entries = (uint64_t)(-1); /* don't care */
filter.revisions[0].revision_num = 0;
filter.revisions[0].parent_revision_num = 0;
- filter.revisions[0].logi_eof = (TRUE == with_initial_data) ? a_list_size_s : 0;
+ filter.revisions[0].logical_eof = (TRUE == with_initial_data) ? a_list_size_s : 0;
if (verify_history_as_expected_onion(vfile_raw, &filter) < 0)
TEST_ERROR;
@@ -2230,7 +2230,7 @@ test_several_revisions_with_logical_gaps(void)
* SETUP *
*********/
- history_out.version = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR;
+ history_out.version = H5FD__ONION_HISTORY_VERSION_CURR;
history_out.n_revisions = 0;
history_out.record_locs = NULL;
@@ -2467,26 +2467,26 @@ test_several_revisions_with_logical_gaps(void)
filter.revisions[0].n_index_entries = 0;
filter.revisions[0].revision_num = 0;
filter.revisions[0].parent_revision_num = 0;
- filter.revisions[0].logi_eof = 0;
+ filter.revisions[0].logical_eof = 0;
filter.revisions[1].comment = "second";
filter.revisions[1].n_index_entries = (a_list_size_s + ONION_TEST_PAGE_SIZE_5 - 1) >> 5;
filter.revisions[1].revision_num = 1;
filter.revisions[1].parent_revision_num = 0;
- filter.revisions[1].logi_eof = a_off + a_list_size_s;
+ filter.revisions[1].logical_eof = a_off + a_list_size_s;
filter.revisions[2].comment = "third";
filter.revisions[2].n_index_entries =
filter.revisions[1].n_index_entries + ((b_list_size_s + ONION_TEST_PAGE_SIZE_5 - 1) >> 5);
filter.revisions[2].revision_num = 2;
filter.revisions[2].parent_revision_num = 1;
- filter.revisions[2].logi_eof = b_off + b_list_size_s;
+ filter.revisions[2].logical_eof = b_off + b_list_size_s;
filter.revisions[3].comment = "fourth";
filter.revisions[3].n_index_entries = filter.revisions[2].n_index_entries + 1;
filter.revisions[3].revision_num = 3;
filter.revisions[3].parent_revision_num = 2;
- filter.revisions[3].logi_eof = b_off + b_list_size_s;
+ filter.revisions[3].logical_eof = b_off + b_list_size_s;
if (verify_history_as_expected_onion(file, &filter) < 0)
TEST_ERROR;
@@ -2658,13 +2658,13 @@ test_page_aligned_history_create(void)
H5FD_ONION_FAPL_INFO_CREATE_FLAG_ENABLE_PAGE_ALIGNMENT,
"initial commit" /* comment */
};
- H5FD_t * file = NULL; /* Onion virtual file for read/write */
- unsigned char * buf = NULL;
- struct revise_revision about[2];
- H5FD_onion_history_header_t hdr_out;
- H5FD_onion_history_t history_out;
- size_t i = 0;
- uint64_t a_off = b_list_size_s - a_list_size_s;
+ H5FD_t * file = NULL; /* Onion virtual file for read/write */
+ unsigned char * buf = NULL;
+ struct revise_revision about[2];
+ H5FD_onion_header_t hdr_out;
+ H5FD_onion_history_t history_out;
+ size_t i = 0;
+ uint64_t a_off = b_list_size_s - a_list_size_s;
TESTING("page-aligned history on onion-created file");
@@ -2673,7 +2673,7 @@ test_page_aligned_history_create(void)
*********/
hdr_out.version = H5FD__ONION_HEADER_VERSION_CURR;
- history_out.version = H5FD__ONION_WHOLE_HISTORY_VERSION_CURR;
+ history_out.version = H5FD__ONION_HISTORY_VERSION_CURR;
history_out.n_revisions = 0;
history_out.record_locs = NULL;
@@ -2760,7 +2760,7 @@ test_page_aligned_history_create(void)
TEST_ERROR;
if (H5FDread(file, H5FD_MEM_DRAW, H5P_DEFAULT, 0, H5FD__ONION_ENCODED_SIZE_HEADER, buf) < 0)
TEST_ERROR;
- if (H5FD__onion_history_header_decode(buf, &hdr_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
+ if (H5FD__onion_header_decode(buf, &hdr_out) != H5FD__ONION_ENCODED_SIZE_HEADER)
TEST_ERROR;
if (hdr_out.history_addr & ((1 << 5) - 1)) /* 5::PAGE_SIZE_5 */
TEST_ERROR;