summaryrefslogtreecommitdiffstats
path: root/src/H5FDcore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5FDcore.c')
-rw-r--r--src/H5FDcore.c230
1 files changed, 174 insertions, 56 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index 2ab04dc..0551dd0 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -54,6 +54,7 @@ typedef struct H5FD_core_t {
haddr_t eof; /* current allocated size */
size_t increment; /* multiples for mem allocation */
hbool_t backing_store; /* write to file name on flush */
+ hbool_t write_tracking; /* Whether to track writes */
size_t bstore_page_size; /* backing store page size */
int fd; /* backing store file descriptor */
/* Information for determining uniqueness of a file with a backing store */
@@ -81,7 +82,7 @@ typedef struct H5FD_core_t {
DWORD nFileIndexLow;
DWORD nFileIndexHigh;
DWORD dwVolumeSerialNumber;
-
+
HANDLE hFile; /* Native windows file handle */
#endif /* H5_HAVE_WIN32_API */
hbool_t dirty; /* changes not saved? */
@@ -93,10 +94,14 @@ typedef struct H5FD_core_t {
typedef struct H5FD_core_fapl_t {
size_t increment; /* how much to grow memory */
hbool_t backing_store; /* write to file name on flush */
+ hbool_t write_tracking; /* Whether to track writes */
+ size_t page_size; /* Page size for tracked writes */
} H5FD_core_fapl_t;
/* Allocate memory in multiples of this size by default */
-#define H5FD_CORE_INCREMENT 8192
+#define H5FD_CORE_INCREMENT 8192
+#define H5FD_CORE_WRITE_TRACKING_FLAG FALSE
+#define H5FD_CORE_WRITE_TRACKING_PAGE_SIZE 524288
/* These macros check for overflow of various quantities. These macros
* assume that file_offset_t is signed and haddr_t and size_t are unsigned.
@@ -337,15 +342,18 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size)
unsigned char *ptr = file->mem + addr; /* mutable pointer into the
* buffer (can't change mem)
*/
+ HDoff_t offset = (HDoff_t)addr; /* Offset to write at */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
HDassert(file);
- /* Write to backing store */
- if((off_t)addr != HDlseek(file->fd, (off_t)addr, SEEK_SET))
+#ifndef H5_HAVE_PREADWRITE
+ /* Seek to the correct location (if we don't have pwrite) */
+ if((HDoff_t)addr != HDlseek(file->fd, (off_t)addr, SEEK_SET))
HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "error seeking in backing store")
+#endif /* H5_HAVE_PREADWRITE */
while (size > 0) {
@@ -361,15 +369,22 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size)
bytes_in = (h5_posix_io_t)size;
do {
+#ifdef H5_HAVE_PREADWRITE
+ bytes_wrote = HDpwrite(file->fd, ptr, bytes_in, offset);
+ if(bytes_wrote > 0)
+ offset += bytes_wrote;
+#else
bytes_wrote = HDwrite(file->fd, ptr, bytes_in);
+#endif /* H5_HAVE_PREADWRITE */
} while(-1 == bytes_wrote && EINTR == errno);
if(-1 == bytes_wrote) { /* error */
int myerrno = errno;
time_t mytime = HDtime(NULL);
- HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
- HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)myoffset);
+ offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+
+ HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "write to backing store failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', ptr = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), ptr, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)offset);
} /* end if */
HDassert(bytes_wrote > 0);
@@ -390,7 +405,7 @@ done:
*
* Purpose: Initializes any interface-specific data or routines.
*
- * Return: Non-negative on success/Negative on failure
+ * Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
@@ -415,8 +430,8 @@ done:
* Purpose: Initialize this driver by registering the driver with the
* library.
*
- * Return: Success: The driver ID for the core driver.
- * Failure: Negative.
+ * Return: Success: The driver ID for the core driver
+ * Failure: H5I_INVALID_HID
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
@@ -428,7 +443,7 @@ H5FD_core_init(void)
{
hid_t ret_value = H5I_INVALID_HID; /* Return value */
- FUNC_ENTER_NOAPI(FAIL)
+ FUNC_ENTER_NOAPI(H5I_INVALID_HID)
if(H5I_VFL != H5I_get_type(H5FD_CORE_g))
H5FD_CORE_g = H5FD_register(&H5FD_core_g, sizeof(H5FD_class_t), FALSE);
@@ -466,6 +481,100 @@ H5FD__core_term(void)
/*-------------------------------------------------------------------------
+ * Function: H5Pset_core_write_tracking
+ *
+ * Purpose: Enables/disables core VFD write tracking and page
+ * aggregation size.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Dana Robinson
+ * Tuesday, April 8, 2014
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Pset_core_write_tracking(hid_t plist_id, hbool_t is_enabled, size_t page_size)
+{
+ H5P_genplist_t *plist; /* Property list pointer */
+ H5FD_core_fapl_t fa; /* Core VFD info */
+ const H5FD_core_fapl_t *old_fa; /* Old core VFD info */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE3("e", "ibz", plist_id, is_enabled, page_size);
+
+ /* The page size cannot be zero */
+ if(page_size == 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "page_size cannot be zero")
+
+ /* Get the plist structure */
+ if(NULL == (plist = H5P_object_verify(plist_id, H5P_FILE_ACCESS)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADATOM, FAIL, "can't find object for ID")
+ if(H5FD_CORE != H5P_peek_driver(plist))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "incorrect VFL driver")
+ if(NULL == (old_fa = (const H5FD_core_fapl_t *)H5P_peek_driver_info(plist)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")
+
+ /* Set VFD info values */
+ HDmemset(&fa, 0, sizeof(H5FD_core_fapl_t));
+ fa.increment = old_fa->increment;
+ fa.backing_store = old_fa->backing_store;
+ fa.write_tracking = is_enabled;
+ fa.page_size = page_size;
+
+ /* Set the property values & the driver for the FAPL */
+ if(H5P_set_driver(plist, H5FD_CORE, &fa) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set core VFD as driver")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Pset_core_write_tracking() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Pget_core_write_tracking
+ *
+ * Purpose: Gets information about core VFD write tracking and page
+ * aggregation size.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Dana Robinson
+ * Tuesday, April 8, 2014
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Pget_core_write_tracking(hid_t plist_id, hbool_t *is_enabled, size_t *page_size)
+{
+ H5P_genplist_t *plist; /* Property list pointer */
+ const H5FD_core_fapl_t *fa; /* Core VFD info */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(FAIL)
+ H5TRACE3("e", "i*b*z", plist_id, is_enabled, page_size);
+
+ /* Get the plist structure */
+ if(NULL == (plist = H5P_object_verify(plist_id, H5P_FILE_ACCESS)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADATOM, FAIL, "can't find object for ID")
+ if(H5FD_CORE != H5P_peek_driver(plist))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "incorrect VFL driver")
+ if(NULL == (fa = (const H5FD_core_fapl_t *)H5P_peek_driver_info(plist)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")
+
+ /* Get values */
+ if(is_enabled)
+ *is_enabled = fa->write_tracking;
+ if(page_size)
+ *page_size = fa->page_size;
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Pget_core_write_tracking() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5Pset_fapl_core
*
* Purpose: Modify the file access property list to use the H5FD_CORE
@@ -482,9 +591,9 @@ H5FD__core_term(void)
herr_t
H5Pset_fapl_core(hid_t fapl_id, size_t increment, hbool_t backing_store)
{
- H5FD_core_fapl_t fa;
- H5P_genplist_t *plist; /* Property list pointer */
- herr_t ret_value;
+ H5P_genplist_t *plist; /* Property list pointer */
+ H5FD_core_fapl_t fa; /* Core VFD info */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "izb", fapl_id, increment, backing_store);
@@ -493,10 +602,16 @@ H5Pset_fapl_core(hid_t fapl_id, size_t increment, hbool_t backing_store)
if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
+ /* Set VFD info values */
+ HDmemset(&fa, 0, sizeof(H5FD_core_fapl_t));
fa.increment = increment;
fa.backing_store = backing_store;
+ fa.write_tracking = H5FD_CORE_WRITE_TRACKING_FLAG;
+ fa.page_size = H5FD_CORE_WRITE_TRACKING_PAGE_SIZE;
- ret_value = H5P_set_driver(plist, H5FD_CORE, &fa);
+ /* Set the property values & the driver for the FAPL */
+ if(H5P_set_driver(plist, H5FD_CORE, &fa) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set core VFD as driver")
done:
FUNC_LEAVE_API(ret_value)
@@ -518,9 +633,9 @@ done:
herr_t
H5Pget_fapl_core(hid_t fapl_id, size_t *increment /*out*/, hbool_t *backing_store /*out*/)
{
- H5P_genplist_t *plist; /* Property list pointer */
- const H5FD_core_fapl_t *fa;
- herr_t ret_value = SUCCEED; /* Return value */
+ H5P_genplist_t *plist; /* Property list pointer */
+ const H5FD_core_fapl_t *fa; /* Core VFD info */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE3("e", "ixx", fapl_id, increment, backing_store);
@@ -559,7 +674,7 @@ static void *
H5FD__core_fapl_get(H5FD_t *_file)
{
H5FD_core_t *file = (H5FD_core_t*)_file;
- H5FD_core_fapl_t *fa;
+ H5FD_core_fapl_t *fa; /* Core VFD info */
void *ret_value = NULL; /* Return value */
FUNC_ENTER_STATIC
@@ -569,6 +684,8 @@ H5FD__core_fapl_get(H5FD_t *_file)
fa->increment = file->increment;
fa->backing_store = (hbool_t)(file->fd >= 0);
+ fa->write_tracking = file->write_tracking;
+ fa->page_size = file->bstore_page_size;
/* Set return value */
ret_value = fa;
@@ -640,9 +757,9 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
if((file_image_info.buffer != NULL) && !(H5F_ACC_CREAT & flags)) {
if(HDopen(name, o_flags, H5_POSIX_CREATE_MODE_RW) >= 0)
HGOTO_ERROR(H5E_FILE, H5E_FILEEXISTS, NULL, "file already exists")
-
+
/* If backing store is requested, create and stat the file
- * Note: We are forcing the O_CREAT flag here, even though this is
+ * Note: We are forcing the O_CREAT flag here, even though this is
* technically an open.
*/
if(fa->backing_store) {
@@ -732,20 +849,21 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
HGOTO_ERROR(H5E_FILE, H5E_CANTCOPY, NULL, "image_memcpy callback failed")
} /* end if */
else
- HDmemcpy(file->mem, file_image_info.buffer, size);
+ H5MM_memcpy(file->mem, file_image_info.buffer, size);
} /* end if */
/* Read in existing data from the file if there is no image */
else {
/* Read in existing data, being careful of interrupted system calls,
* partial results, and the end of the file.
*/
-
- uint8_t *mem = file->mem; /* memory pointer for writes */
-
+
+ uint8_t *mem = file->mem; /* memory pointer for writes */
+ HDoff_t offset = (HDoff_t)0; /* offset for reading */
+
while(size > 0) {
h5_posix_io_t bytes_in = 0; /* # of bytes to read */
h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */
-
+
/* Trying to read more bytes than the return type can handle is
* undefined behavior in POSIX.
*/
@@ -753,22 +871,29 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
bytes_in = H5_POSIX_MAX_IO_BYTES;
else
bytes_in = (h5_posix_io_t)size;
-
+
do {
+#ifdef H5_HAVE_PREADWRITE
+ bytes_read = HDpread(file->fd, mem, bytes_in, offset);
+ if(bytes_read > 0)
+ offset += bytes_read;
+#else
bytes_read = HDread(file->fd, mem, bytes_in);
+#endif /* H5_HAVE_PREADWRITE */
} while(-1 == bytes_read && EINTR == errno);
-
+
if(-1 == bytes_read) { /* error */
int myerrno = errno;
time_t mytime = HDtime(NULL);
- HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
- HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)myoffset);
+ offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+
+ HGOTO_ERROR(H5E_IO, H5E_READERROR, NULL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', file->mem = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->name, file->fd, myerrno, HDstrerror(myerrno), file->mem, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)offset);
} /* end if */
-
+
HDassert(bytes_read >= 0);
HDassert((size_t)bytes_read <= size);
-
+
mem += bytes_read;
size -= (size_t)bytes_read;
} /* end while */
@@ -776,35 +901,28 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
} /* end if */
} /* end if */
+ /* Get the write tracking & page size */
+ file->write_tracking = fa->write_tracking;
+ file->bstore_page_size = fa->page_size;
+
/* Set up write tracking if the backing store is on */
file->dirty_list = NULL;
if(fa->backing_store) {
- hbool_t write_tracking_flag = FALSE; /* what the user asked for */
hbool_t use_write_tracking = FALSE; /* what we're actually doing */
- /* Get the write tracking flag */
- if(H5P_get(plist, H5F_ACS_CORE_WRITE_TRACKING_FLAG_NAME, &write_tracking_flag) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get core VFD write tracking flag");
-
- /* Get the page size */
- if(H5P_get(plist, H5F_ACS_CORE_WRITE_TRACKING_PAGE_SIZE_NAME, &(file->bstore_page_size)) < 0)
- HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get core VFD write tracking page size");
-
/* default is to have write tracking OFF for create (hence the check to see
* if the user explicitly set a page size) and ON with the default page size
* on open (when not read-only).
*/
/* Only use write tracking if the file is open for writing */
- use_write_tracking =
- TRUE == write_tracking_flag /* user asked for write tracking */
- && !(o_flags & O_RDONLY) /* file is open for writing (i.e. not read-only) */
- && file->bstore_page_size != 0; /* page size is not zero */
+ use_write_tracking = (TRUE == fa->write_tracking) /* user asked for write tracking */
+ && !(o_flags & O_RDONLY) /* file is open for writing (i.e. not read-only) */
+ && (file->bstore_page_size != 0); /* page size is not zero */
/* initialize the dirty list */
- if(use_write_tracking) {
+ if(use_write_tracking)
if(NULL == (file->dirty_list = H5SL_create(H5SL_TYPE_HADDR, NULL)))
HGOTO_ERROR(H5E_SLIST, H5E_CANTCREATE, NULL, "can't create core vfd dirty region list");
- } /* end if */
} /* end if */
/* Set return value */
@@ -1184,7 +1302,7 @@ H5FD__core_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
nbytes = MIN(size,(size_t)(file->eof-addr));
#endif /* NDEBUG */
- HDmemcpy(buf, file->mem + addr, nbytes);
+ H5MM_memcpy(buf, file->mem + addr, nbytes);
size -= nbytes;
addr += nbytes;
buf = (char *)buf + nbytes;
@@ -1270,7 +1388,7 @@ H5FD__core_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN
}
/* Write from BUF to memory */
- HDmemcpy(file->mem + addr, buf, size);
+ H5MM_memcpy(file->mem + addr, buf, size);
/* Mark memory buffer as modified */
file->dirty = TRUE;
@@ -1349,24 +1467,24 @@ done:
* than the end-of-address.
*
* Addendum -- 12/2/11
- * For file images opened with the core file driver, it is
+ * For file images opened with the core file driver, it is
* necessary that we avoid reallocating the core file driver's
* buffer uneccessarily.
*
* To this end, I have made the following functional changes
- * to this function.
+ * to this function.
*
- * If we are closing, and there is no backing store, this
+ * If we are closing, and there is no backing store, this
* function becomes a no-op.
*
* If we are closing, and there is backing store, we set the
- * eof to equal the eoa, and truncate the backing store to
+ * eof to equal the eoa, and truncate the backing store to
* the new eof
*
- * If we are not closing, we realloc the buffer to size equal
- * to the smallest multiple of the allocation increment that
- * equals or exceeds the eoa and set the eof accordingly.
- * Note that we no longer truncate the backing store to the
+ * If we are not closing, we realloc the buffer to size equal
+ * to the smallest multiple of the allocation increment that
+ * equals or exceeds the eoa and set the eof accordingly.
+ * Note that we no longer truncate the backing store to the
* new eof if applicable.
* -- JRM
*