[svn-r14372] Description:

Further cleanups & simplifications to prepare for next phase of work.

Tested on:
	FreeBSD/32 6.2 (duty)
	Mac OS X/32 10.5.1 (amazon)
This commit is contained in:
Quincey Koziol 2008-01-03 18:05:04 -05:00
parent 6237d44a08
commit 1831bc1d13
6 changed files with 60 additions and 59 deletions

View File

@ -900,6 +900,11 @@ H5F_new(H5F_file_t *shared, hid_t fcpl_id, hid_t fapl_id, H5FD_t *lf)
if(H5P_get(plist, H5F_ACS_LATEST_FORMAT_NAME, &(f->shared->latest_format)) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get 'latest format' flag")
/* Get the VFD values to cache */
f->shared->maxaddr = H5FD_get_maxaddr(lf);
if(!H5F_addr_defined(f->shared->maxaddr))
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, NULL, "bad maximum address from VFD")
/* Bump superblock version if we are to use the latest version of the format */
if(f->shared->latest_format)
super_vers = HDF5_SUPERBLOCK_VERSION_LATEST;

View File

@ -1804,6 +1804,36 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
}
/*-------------------------------------------------------------------------
* Function: H5FD_get_maxaddr
*
* Purpose: Private version of H5FDget_eof()
*
* Return: Success: The maximum address allowed in the file.
* Failure: HADDR_UNDEF
*
* Programmer: Quincey Koziol
* Thursday, January 3, 2008
*
*-------------------------------------------------------------------------
*/
haddr_t
H5FD_get_maxaddr(const H5FD_t *file)
{
haddr_t ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5FD_get_maxaddr, HADDR_UNDEF)
HDassert(file);
/* Set return value */
ret_value = file->maxaddr;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_get_maxaddr() */
/*-------------------------------------------------------------------------
* Function: H5FDread

View File

@ -62,6 +62,7 @@ H5_DLL haddr_t H5FD_realloc(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_
H5_DLL haddr_t H5FD_get_eoa(const H5FD_t *file, H5FD_mem_t type);
H5_DLL herr_t H5FD_set_eoa(H5FD_t *file, H5FD_mem_t type, haddr_t addr);
H5_DLL haddr_t H5FD_get_eof(const H5FD_t *file);
H5_DLL haddr_t H5FD_get_maxaddr(const H5FD_t *file);
H5_DLL herr_t H5FD_read(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,
void *buf/*out*/);
H5_DLL herr_t H5FD_write(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr, size_t size,

View File

@ -87,7 +87,7 @@ typedef struct H5F_file_t {
unsigned sohm_vers; /* Version of shared message table on disk */
unsigned sohm_nindexes; /* Number of shared messages indexes in the table */
haddr_t driver_addr; /* File driver information block address*/
hbool_t fam_to_sec2; /* Is h5repart changing driver from family to sec2 */
haddr_t maxaddr; /* Maximum address for file */
H5AC_t *cache; /* The object cache */
H5AC_cache_config_t
@ -105,7 +105,8 @@ typedef struct H5F_file_t {
hsize_t alignment; /* Alignment */
unsigned gc_ref; /* Garbage-collect references? */
hbool_t latest_format; /* Always use the latest format? */
hbool_t store_msg_crt_idx; /* Store creation index for object header messages? */
hbool_t store_msg_crt_idx; /* Store creation index for object header messages? */
hbool_t fam_to_sec2; /* Is h5repart changing driver from family to sec2? */
int ncwfs; /* Num entries on cwfs list */
struct H5HG_heap_t **cwfs; /* Global heap cache */
struct H5G_t *root_grp; /* Open root group */

View File

@ -58,6 +58,7 @@
/********************/
/* Local Prototypes */
/********************/
static hbool_t H5MF_alloc_overflow(H5F_t *f, hsize_t size);
/*********************/
@ -107,10 +108,6 @@ H5MF_alloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, hsize_t size)
if(0 == (f->intent & H5F_ACC_RDWR))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTINIT, HADDR_UNDEF, "file is read-only")
/* Check that the file can address the new space */
if(H5MF_alloc_overflow(f, size))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file")
/* Allocate space from the virtual file layer */
if(HADDR_UNDEF == (ret_value = H5FD_alloc(f->shared->lf, type, dxpl_id, size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "file allocation failed")
@ -207,11 +204,6 @@ H5MF_realloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t old_addr, hsize_t
/* Convert old relative address to absolute address */
old_addr += f->shared->base_addr;
/* Check that the file can address the new space. */
/* In the worst case, this means adding new_size bytes to the end of the file. */
if(H5MF_alloc_overflow(f, new_size))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, HADDR_UNDEF, "not enough address space in file")
/* Reallocate memory from the virtual file layer */
ret_value = H5FD_realloc(f->shared->lf, type, dxpl_id, old_addr, old_size, new_size);
if(HADDR_UNDEF == ret_value)
@ -235,8 +227,8 @@ done:
* F is the file whose space is being allocated, SIZE is the amount
* of space needed.
*
* Return: 0 if no overflow would result
* 1 if overflow would result (the allocation should not be allowed)
* Return: FALSE if no overflow would result
* TRUE if overflow would result (the allocation should not be allowed)
*
* Programmer: James Laird
* Nat Furrer
@ -244,40 +236,27 @@ done:
*
*-------------------------------------------------------------------------
*/
hbool_t
static hbool_t
H5MF_alloc_overflow(H5F_t *f, hsize_t size)
{
hsize_t space_needed = 0; /* Accumulator variable */
size_t c; /* Local index variable */
hbool_t ret_value; /* Return value */
haddr_t eoa; /* End-of-allocation in the file */
haddr_t space_avail; /* Unallocated space still available in file */
hbool_t ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOFUNC(H5MF_alloc_overflow)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5MF_alloc_overflow)
/* Start with the current end of the file's address. */
space_needed = (hsize_t)H5F_get_eoa(f);
eoa = H5F_get_eoa(f);
HDassert(H5F_addr_defined(eoa));
HDassert(H5F_addr_defined(space_needed));
/* Subtract the file's base address to get the actual amount of
* space being used:
* (end of allocated space - beginning of allocated space)
/* Subtract EOA from the file's maximum address to get the actual amount of
* addressable space left in the file.
*/
HDassert(H5F_BASE_ADDR(f) < space_needed);
space_needed -= (hsize_t)H5F_BASE_ADDR(f);
HDassert(f->shared->maxaddr >= eoa);
space_avail = (hsize_t)(f->shared->maxaddr - eoa);
/* Add the amount of space requested for this allocation */
space_needed += size;
/* Ensure that this final number is less than the file's
* address space. We do this by shifting in multiples
* of 16 bits because some systems will do nothing if
* we shift by 64 bits all at once (<cough> Linux <cough>).
* Thus, we break one shift into several smaller shifts.
*/
for(c = 0; c < H5F_SIZEOF_ADDR(f); c += 2)
space_needed = space_needed >> 16;
if(space_needed != 0)
/* Ensure that there's enough room left in the file for something of this size */
if(size > space_avail)
ret_value = TRUE;
else
ret_value = FALSE;
@ -292,14 +271,11 @@ H5MF_alloc_overflow(H5F_t *f, hsize_t size)
* Purpose: Check if a block in the file can be extended.
*
* Return: Success: TRUE(1)/FALSE(0)
*
* Failure: FAIL
*
* Programmer: Quincey Koziol
* Friday, June 11, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
htri_t
@ -316,10 +292,6 @@ H5MF_can_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t e
if((ret_value = H5FD_can_extend(f->shared->lf, type, addr, size, extra_requested)) < 0)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory");
/* Make sure there is enough addressable space to satisfy the request */
if(ret_value == TRUE)
ret_value = !H5MF_alloc_overflow(f, extra_requested);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5MF_can_extend() */
@ -331,14 +303,11 @@ done:
* Purpose: Extend a block in the file.
*
* Return: Success: Non-negative
*
* Failure: Negative
*
* Programmer: Quincey Koziol
* Saturday, June 12, 2004
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
herr_t
@ -348,11 +317,7 @@ H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size, hsize_t extra
FUNC_ENTER_NOAPI(H5MF_extend, FAIL)
/* Make sure there is enough addressable space to satisfy the request */
if(H5MF_alloc_overflow(f, extra_requested))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "unable to allocate new file memory: out of address space")
/* Convert old relative address to absolute address */
/* Convert relative address to absolute address */
addr += H5F_BASE_ADDR(f);
/* Pass the request down to the virtual file layer */

View File

@ -29,9 +29,8 @@
#define _H5MFprivate_H
/* Private headers needed by this file */
#include "H5private.h"
#include "H5Fprivate.h"
#include "H5FDprivate.h" /*file driver */
#include "H5Fprivate.h" /* File access */
#include "H5FDprivate.h" /* File Drivers */
/*
* Feature: Define H5MF_DEBUG on the compiler command line if you want to
@ -49,10 +48,10 @@ H5_DLL herr_t H5MF_xfree(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t addr,
hsize_t size);
H5_DLL haddr_t H5MF_realloc(H5F_t *f, H5FD_mem_t type, hid_t dxpl_id, haddr_t old_addr,
hsize_t old_size, hsize_t new_size);
H5_DLL hbool_t H5MF_alloc_overflow(H5F_t *f, hsize_t size);
H5_DLL htri_t H5MF_can_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr,
hsize_t size, hsize_t extra_requested);
H5_DLL herr_t H5MF_extend(H5F_t *f, H5FD_mem_t type, haddr_t addr, hsize_t size,
hsize_t extra_requested);
#endif
#endif /* end _H5MFprivate_H */