diff options
-rw-r--r-- | src/H5FScache.c | 105 | ||||
-rw-r--r-- | src/H5FSdbg.c | 2 | ||||
-rw-r--r-- | src/H5FSpkg.h | 8 | ||||
-rw-r--r-- | src/H5FSsection.c | 13 |
4 files changed, 69 insertions, 59 deletions
diff --git a/src/H5FScache.c b/src/H5FScache.c index b79dea7..e0ec79a 100644 --- a/src/H5FScache.c +++ b/src/H5FScache.c @@ -147,7 +147,8 @@ H5FS_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_fs_prot, size_t size; /* Header size */ uint8_t *buf = NULL; /* Temporary buffer */ const uint8_t *p; /* Pointer into raw data buffer */ - uint32_t metadata_chksum; /* Metadata checksum value */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ unsigned nclasses; /* Number of section classes */ H5FS_t *ret_value; /* Return value */ @@ -182,7 +183,7 @@ HDfprintf(stderr, "%s: Load free space header, addr = %a\n", FUNC, addr); p = buf; /* Magic number */ - if(HDmemcmp(p, H5FS_HDR_MAGIC, H5FS_SIZEOF_MAGIC)) + if(HDmemcmp(p, H5FS_HDR_MAGIC, (size_t)H5FS_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "wrong free space header signature") p += H5FS_SIZEOF_MAGIC; @@ -190,17 +191,6 @@ HDfprintf(stderr, "%s: Load free space header, addr = %a\n", FUNC, addr); if(*p++ != H5FS_HDR_VERSION) HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "wrong free space header version") - /* Metadata flags (unused, currently) */ -/* XXX: Plan out metadata flags (including "read-only duplicate" feature) */ - if(*p++ != 0) - HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "unknown metadata flag in free space header") - - /* Metadata checksum (unused, currently) */ - UINT32DECODE(p, metadata_chksum); -/* XXX: Verify checksum */ - if(metadata_chksum != 0) - HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "incorrect metadata checksum for free space header") - /* Client ID */ fspace->client = *p++; if(fspace->client >= H5FS_NUM_CLIENT_ID) @@ -244,8 +234,18 @@ HDfprintf(stderr, "%s: Load free space header, addr = %a\n", FUNC, addr); /* Allocated size of serialized free space sections */ H5F_DECODE_LENGTH(f, p, fspace->alloc_sect_size); + /* Compute checksum on indirect block */ + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + + /* Metadata checksum */ + UINT32DECODE(p, stored_chksum); + HDassert((size_t)(p - buf) == size); + /* Verify checksum */ + if(stored_chksum != computed_chksum) + HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap indirect block") + /* Set return value */ ret_value = fspace; @@ -290,6 +290,7 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F if(fspace->cache_info.is_dirty) { uint8_t *buf = NULL; /* Temporary raw data buffer */ uint8_t *p; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ size_t size; /* Header size on disk */ /* Compute the size of the free space header on disk */ @@ -302,21 +303,12 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F p = buf; /* Magic number */ - HDmemcpy(p, H5FS_HDR_MAGIC, H5FS_SIZEOF_MAGIC); + HDmemcpy(p, H5FS_HDR_MAGIC, (size_t)H5FS_SIZEOF_MAGIC); p += H5FS_SIZEOF_MAGIC; /* Version # */ *p++ = H5FS_HDR_VERSION; - /* Metadata status flags */ -/* XXX: Set this? */ - *p++ = 0; - - /* Metadata checksum */ -/* XXX: Set this! (After all the metadata is in the buffer) */ - HDmemset(p, 0, 4); - p += 4; - /* Client ID */ *p++ = fspace->client; @@ -356,6 +348,12 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F /* Allocated size of serialized free space sections */ H5F_ENCODE_LENGTH(f, p, fspace->alloc_sect_size); + /* Compute checksum */ + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + + /* Metadata checksum */ + UINT32ENCODE(p, metadata_chksum); + /* Write the free space header. */ HDassert((size_t)(p - buf) == size); if(H5F_block_write(f, H5FD_MEM_FSPACE_HDR, addr, size, dxpl_id, buf) < 0) @@ -474,7 +472,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5FS_cache_hdr_size(const H5F_t *f, const H5FS_t *fspace, size_t *size_ptr) +H5FS_cache_hdr_size(const H5F_t *f, const H5FS_t UNUSED *fspace, size_t *size_ptr) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FS_cache_hdr_size) @@ -513,7 +511,8 @@ H5FS_cache_sinfo_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void UNUSED * size_t old_sect_size; /* Old section size */ uint8_t *buf = NULL; /* Temporary buffer */ const uint8_t *p; /* Pointer into raw data buffer */ - uint32_t metadata_chksum; /* Metadata checksum value */ + uint32_t stored_chksum; /* Stored metadata checksum value */ + uint32_t computed_chksum; /* Computed metadata checksum value */ H5FS_sinfo_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5FS_cache_sinfo_load) @@ -535,6 +534,10 @@ HDfprintf(stderr, "%s: Load free space sections, addr = %a\n", FUNC, addr); HDassert(fspace->sinfo == NULL); fspace->sinfo = sinfo; + /* Sanity check address */ + if(H5F_addr_ne(addr, fspace->sect_addr)) + HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "incorrect address for free space sections") + /* Allocate space for the buffer to serialize the sections into */ old_sect_size = fspace->sect_size; #ifdef QAK @@ -551,7 +554,7 @@ HDfprintf(stderr, "%s: fspace->sect_size = %Hu\n", FUNC, fspace->sect_size); p = buf; /* Magic number */ - if(HDmemcmp(p, H5FS_SINFO_MAGIC, H5FS_SIZEOF_MAGIC)) + if(HDmemcmp(p, H5FS_SINFO_MAGIC, (size_t)H5FS_SIZEOF_MAGIC)) HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "wrong free space sections signature") p += H5FS_SIZEOF_MAGIC; @@ -559,17 +562,6 @@ HDfprintf(stderr, "%s: fspace->sect_size = %Hu\n", FUNC, fspace->sect_size); if(*p++ != H5FS_SINFO_VERSION) HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "wrong free space sections version") - /* Metadata flags (unused, currently) */ -/* XXX: Plan out metadata flags (including "read-only duplicate" feature) */ - if(*p++ != 0) - HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "unknown metadata flag in free space sections") - - /* Metadata checksum (unused, currently) */ - UINT32DECODE(p, metadata_chksum); -/* XXX: Verify checksum */ - if(metadata_chksum != 0) - HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, NULL, "incorrect metadata checksum for free space sections") - /* Address of free space header for these sections */ H5F_addr_decode(f, &p, &fs_addr); #ifdef QAK @@ -665,10 +657,10 @@ HDfprintf(stderr, "%s: fspace->sect_cls[%u].serial_size = %Zu\n", FUNC, sect_typ if(H5FS_sect_add(f, dxpl_id, fspace, new_sect, H5FS_ADD_DESERIALIZING, NULL) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, NULL, "can't add section to free space manager") } /* end for */ - } while(p < (buf + old_sect_size)); + } while(p < ((buf + old_sect_size) - H5FS_SIZEOF_CHKSUM)); /* Sanity check */ - HDassert((size_t)(p - buf) == old_sect_size); + HDassert((size_t)(p - buf) == (old_sect_size - H5FS_SIZEOF_CHKSUM)); HDassert(old_sect_size == fspace->sect_size); HDassert(old_tot_sect_count == fspace->tot_sect_count); HDassert(old_serial_sect_count == fspace->serial_sect_count); @@ -676,6 +668,19 @@ HDfprintf(stderr, "%s: fspace->sect_cls[%u].serial_size = %Zu\n", FUNC, sect_typ HDassert(old_tot_space == fspace->tot_space); } /* end if */ + /* Compute checksum on indirect block */ + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + + /* Metadata checksum */ + UINT32DECODE(p, stored_chksum); + + /* Sanity check */ + HDassert((size_t)(p - buf) == old_sect_size); + + /* Verify checksum */ + if(stored_chksum != computed_chksum) + HGOTO_ERROR(H5E_HEAP, H5E_BADVALUE, NULL, "incorrect metadata checksum for fractal heap indirect block") + /* Set return value */ ret_value = sinfo; @@ -837,8 +842,13 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F H5FS_iter_ud_t udata; /* User data for callbacks */ uint8_t *buf = NULL; /* Temporary raw data buffer */ uint8_t *p; /* Pointer into raw data buffer */ + uint32_t metadata_chksum; /* Computed metadata checksum value */ unsigned bin; /* Current bin we are on */ + /* Sanity check address */ + if(H5F_addr_ne(addr, sinfo->fspace->sect_addr)) + HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, FAIL, "incorrect address for free space sections") + /* Allocate temporary buffer */ if((buf = H5FL_BLK_MALLOC(sect_block, (size_t)sinfo->fspace->sect_size)) == NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") @@ -846,21 +856,12 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F p = buf; /* Magic number */ - HDmemcpy(p, H5FS_SINFO_MAGIC, H5FS_SIZEOF_MAGIC); + HDmemcpy(p, H5FS_SINFO_MAGIC, (size_t)H5FS_SIZEOF_MAGIC); p += H5FS_SIZEOF_MAGIC; /* Version # */ *p++ = H5FS_SINFO_VERSION; - /* Metadata status flags */ -/* XXX: Set this? */ - *p++ = 0; - - /* Metadata checksum */ -/* XXX: Set this! (After all the metadata is in the buffer) */ - HDmemset(p, 0, 4); - p += 4; - /* Address of free space header for these sections */ #ifdef QAK HDfprintf(stderr, "%s: sinfo->fspace->addr = %a\n", FUNC, sinfo->fspace->addr); @@ -888,6 +889,12 @@ HDfprintf(stderr, "%s: Serializing section bins\n", FUNC); } /* end if */ } /* end for */ + /* Compute checksum */ + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + + /* Metadata checksum */ + UINT32ENCODE(p, metadata_chksum); + /* Sanity check */ HDassert((size_t)(p - buf) == sinfo->fspace->sect_size); HDassert(sinfo->fspace->sect_size <= sinfo->fspace->alloc_sect_size); diff --git a/src/H5FSdbg.c b/src/H5FSdbg.c index 72597b1..27ac5fb 100644 --- a/src/H5FSdbg.c +++ b/src/H5FSdbg.c @@ -222,7 +222,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5FS_sects_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth, +H5FS_sects_debug(H5F_t *f, hid_t dxpl_id, haddr_t UNUSED addr, FILE *stream, int indent, int fwidth, haddr_t fs_addr, haddr_t client_addr) { H5FS_t *fspace = NULL; /* Free space header info */ diff --git a/src/H5FSpkg.h b/src/H5FSpkg.h index 7478754..fa7faa4 100644 --- a/src/H5FSpkg.h +++ b/src/H5FSpkg.h @@ -48,12 +48,14 @@ #define H5FS_HDR_MAGIC "FSHD" /* Header */ #define H5FS_SINFO_MAGIC "FSSE" /* Serialized sections */ +/* Size of checksum information (on disk) */ +#define H5FS_SIZEOF_CHKSUM 4 + /* "Standard" size of prefix information for free space metadata */ #define H5FS_METADATA_PREFIX_SIZE ( \ - 4 /* Signature */ \ + H5FS_SIZEOF_MAGIC /* Signature */ \ + 1 /* Version */ \ - + 1 /* Metadata flags */ \ - + 4 /* Metadata checksum */ \ + + H5FS_SIZEOF_CHKSUM /* Metadata checksum */ \ ) /* Size of the fractal heap header on disk */ diff --git a/src/H5FSsection.c b/src/H5FSsection.c index 2fe32fc..024aa88 100644 --- a/src/H5FSsection.c +++ b/src/H5FSsection.c @@ -154,7 +154,7 @@ HDfprintf(stderr, "%s: sinfo->sect_off_size = %u, sinfo->sect_len_size = %u\n", #endif /* QAK */ /* Allocate space for the section size bins */ - if(NULL == (sinfo->bins = H5FL_SEQ_CALLOC(H5FS_bin_t, sinfo->nbins))) + if(NULL == (sinfo->bins = H5FL_SEQ_CALLOC(H5FS_bin_t, (size_t)sinfo->nbins))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for free space section bin array") /* Set return value */ @@ -662,7 +662,7 @@ HDfprintf(stderr, "%s: sect->size = %Hu, sect->addr = %a\n", FUNC, sect->size, s bin = H5V_log2_gen(sect->size); HDassert(bin < sinfo->nbins); if(sinfo->bins[bin].bin_list == NULL) { - if(NULL == (sinfo->bins[bin].bin_list = H5SL_create(H5SL_TYPE_HSIZE, 0.5, H5FS_DEFAULT_SKIPLIST_HEIGHT))) + if(NULL == (sinfo->bins[bin].bin_list = H5SL_create(H5SL_TYPE_HSIZE, 0.5, (size_t)H5FS_DEFAULT_SKIPLIST_HEIGHT))) HGOTO_ERROR(H5E_FSPACE, H5E_CANTCREATE, FAIL, "can't create skip list for free space nodes") } /* end if */ else { @@ -679,7 +679,7 @@ HDfprintf(stderr, "%s: sect->size = %Hu, sect->addr = %a\n", FUNC, sect->size, s /* Initialize the free list size node */ fspace_node->sect_size = sect->size; fspace_node->serial_count = fspace_node->ghost_count = 0; - if(NULL == (fspace_node->sect_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, H5FS_DEFAULT_SKIPLIST_HEIGHT))) + if(NULL == (fspace_node->sect_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, (size_t)H5FS_DEFAULT_SKIPLIST_HEIGHT))) HGOTO_ERROR(H5E_FSPACE, H5E_CANTCREATE, FAIL, "can't create skip list for free space nodes") /* Insert new free space size node into bin's list */ @@ -759,7 +759,7 @@ H5FS_sect_link_rest(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace, const H5FS_section_ HDfprintf(stderr, "%s: inserting object into merge list, sect->type = %u\n", FUNC, (unsigned)sect->type); #endif /* QAK */ if(fspace->sinfo->merge_list == NULL) - if(NULL == (fspace->sinfo->merge_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, H5FS_DEFAULT_SKIPLIST_HEIGHT))) + if(NULL == (fspace->sinfo->merge_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, (size_t)H5FS_DEFAULT_SKIPLIST_HEIGHT))) HGOTO_ERROR(H5E_FSPACE, H5E_CANTCREATE, FAIL, "can't create skip list for merging free space sections") if(H5SL_insert(fspace->sinfo->merge_list, sect, §->addr) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, FAIL, "can't insert free space node into merging skip list") @@ -1366,7 +1366,6 @@ HDfprintf(stderr, "%s: old_addr = %a, fspace->sect_addr = %a\n", FUNC, old_addr, } /* end if */ else { size_t decrease_threshold; /* Size threshold for decreasing serialized section size */ - size_t new_size; /* New size of space for serialized sections */ haddr_t old_addr; /* Old address of serialized sections */ /* Compute the threshold for decreasing the sections' serialized size */ @@ -1374,6 +1373,8 @@ HDfprintf(stderr, "%s: old_addr = %a, fspace->sect_addr = %a\n", FUNC, old_addr, if(fspace->alloc_sect_size > H5FS_SINFO_SIZE_DEFAULT && fspace->sect_size < decrease_threshold) { + size_t new_size = 0; /* New size of space for serialized sections */ + /* Currently, the old block data is "thrown away" after the space is reallocated, * so avoid data copy in H5MF_realloc() call by just free'ing the space and * allocating new space. @@ -1727,7 +1728,7 @@ HDfprintf(stderr, "%s: to_mergable = %u\n", FUNC, to_mergable); HDfprintf(stderr, "%s: inserting object into merge list, sect->type = %u\n", FUNC, (unsigned)sect->type); #endif /* QAK */ if(fspace->sinfo->merge_list == NULL) - if(NULL == (fspace->sinfo->merge_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, H5FS_DEFAULT_SKIPLIST_HEIGHT))) + if(NULL == (fspace->sinfo->merge_list = H5SL_create(H5SL_TYPE_HADDR, 0.5, (size_t)H5FS_DEFAULT_SKIPLIST_HEIGHT))) HGOTO_ERROR(H5E_FSPACE, H5E_CANTCREATE, FAIL, "can't create skip list for merging free space sections") if(H5SL_insert(fspace->sinfo->merge_list, sect, §->addr) < 0) HGOTO_ERROR(H5E_FSPACE, H5E_CANTINSERT, FAIL, "can't insert free space node into merging skip list") |