summaryrefslogtreecommitdiffstats
path: root/src/H5FDlog.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2011-02-05 23:31:02 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2011-02-05 23:31:02 (GMT)
commit299ac26d98a27cb309c87eafeb0ff7ac53eeb94b (patch)
treebcd48f00faa2410605c9a0cfbbf4a281cafd9076 /src/H5FDlog.c
parentc087ecdbdea8f142f1a4823db71ea47fa60a8c59 (diff)
downloadhdf5-299ac26d98a27cb309c87eafeb0ff7ac53eeb94b.zip
hdf5-299ac26d98a27cb309c87eafeb0ff7ac53eeb94b.tar.gz
hdf5-299ac26d98a27cb309c87eafeb0ff7ac53eeb94b.tar.bz2
[svn-r20050] Description:
Bring sec2 and log VFDs back into agreement. Correct several compiler warnings. Also add some additional statistics to the log VFD and promote the parameter for H5Pset_fapl_log from 'unsigned' to 'unsigned long long'. Tested on: Mac OS X/32 10.6.6 (amazon) w/debug & production FreeBSD/32 8.2 (loyalty) w/debug FreeBSD/64 8.2 (freedom) w/debug
Diffstat (limited to 'src/H5FDlog.c')
-rw-r--r--src/H5FDlog.c571
1 files changed, 312 insertions, 259 deletions
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index 8546e01..96df596 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -35,27 +35,18 @@
#include "H5Fprivate.h" /* File access */
#include "H5FDprivate.h" /* File drivers */
#include "H5FDlog.h" /* Logging file driver */
+#include "H5FLprivate.h" /* Free Lists */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5Pprivate.h" /* Property lists */
-#ifdef MAX
-#undef MAX
-#define MAX(X,Y) ((X)>(Y)?(X):(Y))
-#endif /* MAX */
-
/* The driver identification number, initialized at runtime */
static hid_t H5FD_LOG_g = 0;
-/* File operations */
-#define OP_UNKNOWN 0
-#define OP_READ 1
-#define OP_WRITE 2
-
/* Driver-specific file access properties */
typedef struct H5FD_log_fapl_t {
char *logfile; /* Allocated log file name */
- unsigned flags; /* Flags for logging behavior */
+ unsigned long long flags; /* Flags for logging behavior */
size_t buf_size; /* Size of buffers for track flavor and number of times each byte is accessed */
} H5FD_log_fapl_t;
@@ -88,23 +79,19 @@ typedef struct H5FD_log_t {
haddr_t eoa; /*end of allocated region */
haddr_t eof; /*end of file; current file size*/
haddr_t pos; /*current file I/O position */
- int op; /*last operation */
- unsigned char *nread; /* Number of reads from a file location */
- unsigned char *nwrite; /* Number of write to a file location */
- unsigned char *flavor; /* Flavor of information written to file location */
- double total_read_time; /* Total time spent in read operations */
- double total_seek_time; /* Total time spent in seek operations */
- double total_write_time; /* Total time spent in write operations */
- size_t iosize; /* Size of I/O information buffers */
- FILE *logfp; /* Log file pointer */
- H5FD_log_fapl_t fa; /* Driver-specific file access properties*/
+ H5FD_file_op_t op; /*last operation */
+ char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */
#ifndef _WIN32
/*
* On most systems the combination of device and i-node number uniquely
* identify a file.
*/
dev_t device; /*file device number */
+#ifdef H5_VMS
+ ino_t inode[3]; /*file i-node number */
+#else
ino_t inode; /*file i-node number */
+#endif /*H5_VMS*/
#else
/*
* On _WIN32 the low-order word of a unique identifier associated with the
@@ -118,6 +105,25 @@ typedef struct H5FD_log_t {
DWORD fileindexlo;
DWORD fileindexhi;
#endif
+
+ /* Information from properties set by 'h5repart' tool */
+ hbool_t fam_to_sec2; /* Whether to eliminate the family driver info
+ * and convert this file to a single file */
+
+ /* Fields for tracking I/O operations */
+ unsigned char *nread; /* Number of reads from a file location */
+ unsigned char *nwrite; /* Number of write to a file location */
+ unsigned char *flavor; /* Flavor of information written to file location */
+ unsigned long long total_read_ops; /* Total number of read operations */
+ unsigned long long total_write_ops; /* Total number of write operations */
+ unsigned long long total_seek_ops; /* Total number of seek operations */
+ unsigned long long total_truncate_ops; /* Total number of truncate operations */
+ double total_read_time; /* Total time spent in read operations */
+ double total_write_time; /* Total time spent in write operations */
+ double total_seek_time; /* Total time spent in seek operations */
+ size_t iosize; /* Size of I/O information buffers */
+ FILE *logfp; /* Log file pointer */
+ H5FD_log_fapl_t fa; /* Driver-specific file access properties*/
} H5FD_log_t;
@@ -126,30 +132,14 @@ typedef struct H5FD_log_t {
* some macros here so we don't have to have conditional compilations later
* throughout the code.
*
- * file_offset_t: The datatype for file offsets, the second argument of
- * the lseek() or lseek64() call.
+ * HDoff_t: The datatype for file offsets, the second argument of
+ * the lseek() or lseek64() call.
*
- * file_seek: The function which adjusts the current file position,
- * either lseek() or lseek64().
*/
-/* adding for windows NT file system support. */
-
-#ifdef H5_HAVE_LSEEK64
-# define file_offset_t off64_t
-# define file_seek lseek64
-#elif defined (_WIN32)
-# /*MSVC*/
-# define file_offset_t __int64
-# define file_seek _lseeki64
-#else
-# define file_offset_t off_t
-# define file_seek lseek
-#endif
-
/*
* 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.
+ * assume that HDoff_t is signed and haddr_t and size_t are unsigned.
*
* ADDR_OVERFLOW: Checks whether a file address of type `haddr_t'
* is too large to be represented by the second argument
@@ -162,14 +152,13 @@ typedef struct H5FD_log_t {
* which can be addressed entirely by the second
* argument of the file seek function.
*/
-#define MAXADDR (((haddr_t)1<<(8*sizeof(file_offset_t)-1))-1)
+#define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_t)-1))-1)
#define ADDR_OVERFLOW(A) (HADDR_UNDEF==(A) || \
((A) & ~(haddr_t)MAXADDR))
#define SIZE_OVERFLOW(Z) ((Z) & ~(hsize_t)MAXADDR)
#define REGION_OVERFLOW(A,Z) (ADDR_OVERFLOW(A) || SIZE_OVERFLOW(Z) || \
- sizeof(file_offset_t)<sizeof(size_t) || \
HADDR_UNDEF==(A)+(Z) || \
- (file_offset_t)((A)+(Z))<(file_offset_t)(A))
+ (HDoff_t)((A)+(Z))<(HDoff_t)(A))
/* Prototypes */
static void *H5FD_log_fapl_get(H5FD_t *file);
@@ -191,21 +180,6 @@ static herr_t H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id, hadd
size_t size, const void *buf);
static herr_t H5FD_log_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
-#ifdef OLD_WAY
-/*
- * The free list map which causes each request type to use no free lists
- */
-#define H5FD_FLMAP_NOLIST { \
- H5FD_MEM_NOLIST, /*default*/ \
- H5FD_MEM_NOLIST, /*super*/ \
- H5FD_MEM_NOLIST, /*btree*/ \
- H5FD_MEM_NOLIST, /*draw*/ \
- H5FD_MEM_NOLIST, /*gheap*/ \
- H5FD_MEM_NOLIST, /*lheap*/ \
- H5FD_MEM_NOLIST /*ohdr*/ \
-}
-#endif /* OLD_WAY */
-
static const H5FD_class_t H5FD_log_g = {
"log", /*name */
MAXADDR, /*maxaddr */
@@ -240,6 +214,9 @@ static const H5FD_class_t H5FD_log_g = {
H5FD_FLMAP_SINGLE /*fl_map */
};
+/* Declare a free list to manage the H5FD_log_t struct */
+H5FL_DEFINE_STATIC(H5FD_log_t);
+
/*--------------------------------------------------------------------------
NAME
@@ -270,32 +247,29 @@ H5FD_log_init_interface(void)
* library.
*
* Return: Success: The driver ID for the log driver.
- *
* Failure: Negative.
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
hid_t
H5FD_log_init(void)
{
- hid_t ret_value; /* Return value */
+ hid_t ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_init, FAIL)
- if (H5I_VFL!=H5Iget_type(H5FD_LOG_g))
- H5FD_LOG_g = H5FD_register(&H5FD_log_g,sizeof(H5FD_class_t),FALSE);
+ if(H5I_VFL != H5I_get_type(H5FD_LOG_g))
+ H5FD_LOG_g = H5FD_register(&H5FD_log_g, sizeof(H5FD_class_t), FALSE);
/* Set return value */
- ret_value=H5FD_LOG_g;
+ ret_value = H5FD_LOG_g;
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_log_init() */
/*---------------------------------------------------------------------------
@@ -308,8 +282,6 @@ done:
* Programmer: Quincey Koziol
* Friday, Jan 30, 2004
*
- * Modification:
- *
*---------------------------------------------------------------------------
*/
void
@@ -318,7 +290,7 @@ H5FD_log_term(void)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_term)
/* Reset VFL ID */
- H5FD_LOG_g=0;
+ H5FD_LOG_g = 0;
FUNC_LEAVE_NOAPI_VOID
} /* end H5FD_log_term() */
@@ -339,7 +311,7 @@ H5FD_log_term(void)
*-------------------------------------------------------------------------
*/
herr_t
-H5Pset_fapl_log(hid_t fapl_id, const char *logfile, unsigned flags, size_t buf_size)
+H5Pset_fapl_log(hid_t fapl_id, const char *logfile, unsigned long long flags, size_t buf_size)
{
H5FD_log_fapl_t fa; /* File access property list information */
H5P_genplist_t *plist; /* Property list pointer */
@@ -370,28 +342,24 @@ done:
*
* Return: Success: Ptr to new file access property list with all
* members copied from the file struct.
- *
* Failure: NULL
*
* Programmer: Quincey Koziol
* Thursday, April 20, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void *
H5FD_log_fapl_get(H5FD_t *_file)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
+ H5FD_log_t *file = (H5FD_log_t *)_file;
void *ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_fapl_get, NULL)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_fapl_get)
/* Set return value */
ret_value = H5FD_log_fapl_copy(&(file->fa));
-done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_fapl_get() */
@@ -416,7 +384,7 @@ H5FD_log_fapl_copy(const void *_old_fa)
H5FD_log_fapl_t *new_fa = NULL; /* New FAPL info */
void *ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_fapl_copy, NULL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_fapl_copy)
HDassert(old_fa);
@@ -492,25 +460,29 @@ H5FD_log_fapl_free(void *_fa)
*-------------------------------------------------------------------------
*/
static H5FD_t *
-H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
- haddr_t maxaddr)
+H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
{
- int o_flags;
- int fd = (-1);
H5FD_log_t *file = NULL;
- H5FD_log_fapl_t *fa; /* File access property list information */
+ H5P_genplist_t *plist; /* Property list */
+ H5FD_log_fapl_t *fa; /* File access property list information */
+ int fd = (-1); /* File descriptor */
+ int o_flags; /* Flags for open() call */
#ifdef _WIN32
HFILE filehandle;
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
#endif
#ifdef H5_HAVE_GETTIMEOFDAY
- struct timeval timeval_start, timeval_stop;
+ struct timeval timeval_start;
+ struct timeval open_timeval_diff;
+ struct timeval stat_timeval_diff;
#endif /* H5_HAVE_GETTIMEOFDAY */
- h5_stat_t sb;
- H5P_genplist_t *plist; /* Property list */
- H5FD_t *ret_value;
+ h5_stat_t sb;
+ H5FD_t *ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_open, NULL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_open)
+
+ /* Sanity check on file offsets */
+ HDcompile_assert(sizeof(HDoff_t) >= sizeof(size_t));
/* Check arguments */
if(!name || !*name)
@@ -540,17 +512,52 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Open the file */
- if((fd = HDopen(name, o_flags, 0666)) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file")
+ if((fd = HDopen(name, o_flags, 0666)) < 0) {
+ int myerrno = errno;
+
+ HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags);
+ } /* end if */
#ifdef H5_HAVE_GETTIMEOFDAY
- if(fa->flags & H5FD_LOG_TIME_OPEN)
+ if(fa->flags & H5FD_LOG_TIME_OPEN) {
+ struct timeval timeval_stop;
+
HDgettimeofday(&timeval_stop, NULL);
+
+ /* Calculate the elapsed gettimeofday time */
+ open_timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec;
+ open_timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec;
+ if(open_timeval_diff.tv_usec < 0) {
+ open_timeval_diff.tv_usec += 1000000;
+ open_timeval_diff.tv_sec--;
+ } /* end if */
+ } /* end if */
+#endif /* H5_HAVE_GETTIMEOFDAY */
+
+#ifdef H5_HAVE_GETTIMEOFDAY
+ if(fa->flags & H5FD_LOG_TIME_STAT)
+ HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
+ /* Get the file stats */
if(HDfstat(fd, &sb) < 0)
- HGOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file")
+ HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file")
+#ifdef H5_HAVE_GETTIMEOFDAY
+ if(fa->flags & H5FD_LOG_TIME_STAT) {
+ struct timeval timeval_stop;
+
+ HDgettimeofday(&timeval_stop, NULL);
+
+ /* Calculate the elapsed gettimeofday time */
+ stat_timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec;
+ stat_timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec;
+ if(stat_timeval_diff.tv_usec < 0) {
+ stat_timeval_diff.tv_usec += 1000000;
+ stat_timeval_diff.tv_sec--;
+ } /* end if */
+ } /* end if */
+#endif /* H5_HAVE_GETTIMEOFDAY */
/* Create the new file struct */
- if(NULL == (file = (H5FD_log_t *)H5MM_calloc(sizeof(H5FD_log_t))))
+ if(NULL == (file = H5FL_CALLOC(H5FD_log_t)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct")
file->fd = fd;
@@ -562,10 +569,21 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
(void)GetFileInformationByHandle((HANDLE)filehandle, &fileinfo);
file->fileindexhi = fileinfo.nFileIndexHigh;
file->fileindexlo = fileinfo.nFileIndexLow;
-#else
+#else /* _WIN32 */
file->device = sb.st_dev;
+#ifdef H5_VMS
+ file->inode[0] = sb.st_ino[0];
+ file->inode[1] = sb.st_ino[1];
+ file->inode[2] = sb.st_ino[2];
+#else
file->inode = sb.st_ino;
-#endif
+#endif /*H5_VMS*/
+
+#endif /* _WIN32 */
+
+ /* Retain a copy of the name used to open the file, for possible error reporting */
+ HDstrncpy(file->filename, name, sizeof(file->filename));
+ file->filename[sizeof(file->filename) - 1] = '\0';
/* Get the flags for logging */
file->fa.flags = fa->flags;
@@ -587,11 +605,6 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
HDassert(file->flavor);
} /* end if */
- /* Initialize the total read/write/seek times to zero */
- file->total_read_time = (double)0.0;
- file->total_seek_time = (double)0.0;
- file->total_write_time = (double)0.0;
-
/* Set the log file pointer */
if(fa->logfile)
file->logfp = HDfopen(fa->logfile, "w");
@@ -599,19 +612,24 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
file->logfp = stderr;
#ifdef H5_HAVE_GETTIMEOFDAY
- if(file->fa.flags & H5FD_LOG_TIME_OPEN) {
- struct timeval timeval_diff;
-
- /* Calculate the elapsed gettimeofday time */
- timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec;
- timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec;
- if(timeval_diff.tv_usec < 0) {
- timeval_diff.tv_usec += 1000000;
- timeval_diff.tv_sec--;
- } /* end if */
- HDfprintf(file->logfp, "Open took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0));
- } /* end if */
+ if(file->fa.flags & H5FD_LOG_TIME_OPEN)
+ HDfprintf(file->logfp, "Open took: (%f s)\n", (double)open_timeval_diff.tv_sec + ((double)open_timeval_diff.tv_usec / (double)1000000.0));
+ if(file->fa.flags & H5FD_LOG_TIME_STAT)
+ HDfprintf(file->logfp, "Stat took: (%f s)\n", (double)stat_timeval_diff.tv_sec + ((double)stat_timeval_diff.tv_usec / (double)1000000.0));
#endif /* H5_HAVE_GETTIMEOFDAY */
+
+ } /* end if */
+
+ /* Check for non-default FAPL */
+ if(H5P_FILE_ACCESS_DEFAULT != fapl_id) {
+ /* This step is for h5repart tool only. If user wants to change file driver from
+ * family to sec2 while using h5repart, this private property should be set so that
+ * in the later step, the library can ignore the family driver information saved
+ * in the superblock.
+ */
+ if(H5P_exist_plist(plist, H5F_ACS_FAMILY_TO_SEC2_NAME) > 0)
+ if(H5P_get(plist, H5F_ACS_FAMILY_TO_SEC2_NAME, &file->fam_to_sec2) < 0)
+ HGOTO_ERROR(H5E_VFL, H5E_CANTGET, NULL, "can't get property of changing family to sec2")
} /* end if */
/* Set return value */
@@ -621,7 +639,8 @@ done:
if(NULL == ret_value) {
if(fd >= 0)
HDclose(fd);
- file = (H5FD_log_t *)H5MM_xfree(file);
+ if(file)
+ file = H5FL_FREE(H5FD_log_t, file);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -644,23 +663,27 @@ done:
static herr_t
H5FD_log_close(H5FD_t *_file)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
+ H5FD_log_t *file = (H5FD_log_t *)_file;
#ifdef H5_HAVE_GETTIMEOFDAY
- struct timeval timeval_start,timeval_stop;
+ struct timeval timeval_start, timeval_stop;
#endif /* H5_HAVE_GETTIMEOFDAY */
- herr_t ret_value = SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_close)
- FUNC_ENTER_NOAPI(H5FD_log_close, FAIL)
+ /* Sanity check */
+ HDassert(file);
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
- HDgettimeofday(&timeval_start,NULL);
+ HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
+ /* Close the underlying file */
if(HDclose(file->fd) < 0)
- HGOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
+ HSYS_GOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
- HDgettimeofday(&timeval_stop,NULL);
+ HDgettimeofday(&timeval_stop, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Dump I/O information */
@@ -684,6 +707,16 @@ H5FD_log_close(H5FD_t *_file)
} /* end if */
#endif /* H5_HAVE_GETTIMEOFDAY */
+ /* Dump the total number of seek/read/write operations */
+ if(file->fa.flags & H5FD_LOG_NUM_READ)
+ HDfprintf(file->logfp, "Total number of read operations: %llu\n", file->total_read_ops);
+ if(file->fa.flags & H5FD_LOG_NUM_WRITE)
+ HDfprintf(file->logfp, "Total number of write operations: %llu\n", file->total_write_ops);
+ if(file->fa.flags & H5FD_LOG_NUM_SEEK)
+ HDfprintf(file->logfp, "Total number of seek operations: %llu\n", file->total_seek_ops);
+ if(file->fa.flags & H5FD_LOG_NUM_TRUNCATE)
+ HDfprintf(file->logfp, "Total number of truncate operations: %llu\n", file->total_truncate_ops);
+
/* Dump the total time in seek/read/write */
if(file->fa.flags & H5FD_LOG_TIME_READ)
HDfprintf(file->logfp, "Total time in read operations: %f s\n", file->total_read_time);
@@ -754,7 +787,8 @@ H5FD_log_close(H5FD_t *_file)
fclose(file->logfp);
} /* end if */
- H5MM_xfree(file);
+ /* Release the file info */
+ file = H5FL_FREE(H5FD_log_t, file);
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -768,53 +802,56 @@ done:
* arbitrary (but consistent) ordering.
*
* Return: Success: A value like strcmp()
- *
* Failure: never fails (arguments were checked by the
* caller).
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
H5FD_log_cmp(const H5FD_t *_f1, const H5FD_t *_f2)
{
- const H5FD_log_t *f1 = (const H5FD_log_t*)_f1;
- const H5FD_log_t *f2 = (const H5FD_log_t*)_f2;
- int ret_value=0;
+ const H5FD_log_t *f1 = (const H5FD_log_t *)_f1;
+ const H5FD_log_t *f2 = (const H5FD_log_t *)_f2;
+ int ret_value = 0;
- FUNC_ENTER_NOAPI(H5FD_log_cmp, H5FD_VFD_DEFAULT)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_cmp)
#ifdef _WIN32
- if (f1->fileindexhi < f2->fileindexhi) HGOTO_DONE(-1)
- if (f1->fileindexhi > f2->fileindexhi) HGOTO_DONE(1)
+ if(f1->fileindexhi < f2->fileindexhi) HGOTO_DONE(-1)
+ if(f1->fileindexhi > f2->fileindexhi) HGOTO_DONE(1)
- if (f1->fileindexlo < f2->fileindexlo) HGOTO_DONE(-1)
- if (f1->fileindexlo > f2->fileindexlo) HGOTO_DONE(1)
+ if(f1->fileindexlo < f2->fileindexlo) HGOTO_DONE(-1)
+ if(f1->fileindexlo > f2->fileindexlo) HGOTO_DONE(1)
#else
#ifdef H5_DEV_T_IS_SCALAR
- if (f1->device < f2->device) HGOTO_DONE(-1)
- if (f1->device > f2->device) HGOTO_DONE(1)
+ if(f1->device < f2->device) HGOTO_DONE(-1)
+ if(f1->device > f2->device) HGOTO_DONE(1)
#else /* H5_DEV_T_IS_SCALAR */
/* If dev_t isn't a scalar value on this system, just use memcmp to
* determine if the values are the same or not. The actual return value
* shouldn't really matter...
*/
- if(HDmemcmp(&(f1->device),&(f2->device),sizeof(dev_t))<0) HGOTO_DONE(-1)
- if(HDmemcmp(&(f1->device),&(f2->device),sizeof(dev_t))>0) HGOTO_DONE(1)
+ if(HDmemcmp(&(f1->device),&(f2->device),sizeof(dev_t)) < 0) HGOTO_DONE(-1)
+ if(HDmemcmp(&(f1->device),&(f2->device),sizeof(dev_t)) > 0) HGOTO_DONE(1)
#endif /* H5_DEV_T_IS_SCALAR */
- if (f1->inode < f2->inode) HGOTO_DONE(-1)
- if (f1->inode > f2->inode) HGOTO_DONE(1)
+#ifndef H5_VMS
+ if(f1->inode < f2->inode) HGOTO_DONE(-1)
+ if(f1->inode > f2->inode) HGOTO_DONE(1)
+#else
+ if(HDmemcmp(&(f1->inode), &(f2->inode), 3 * sizeof(ino_t)) < 0) HGOTO_DONE(-1)
+ if(HDmemcmp(&(f1->inode), &(f2->inode), 3 * sizeof(ino_t)) > 0) HGOTO_DONE(1)
+#endif /*H5_VMS*/
+
#endif
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_log_cmp() */
/*-------------------------------------------------------------------------
@@ -824,20 +861,18 @@ done:
* (listed in H5FDpublic.h)
*
* Return: Success: non-negative
- *
* Failure: negative
*
* Programmer: Quincey Koziol
* Friday, August 25, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
-/* ARGSUSED */
static herr_t
-H5FD_log_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
+H5FD_log_query(const H5FD_t *_file, unsigned long *flags /* out */)
{
+ const H5FD_log_t *file = (const H5FD_log_t *)_file;
+
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_query)
/* Set the VFL feature flags that this driver supports */
@@ -848,6 +883,10 @@ H5FD_log_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
*flags |= H5FD_FEAT_DATA_SIEVE; /* OK to perform data sieving for faster raw data reads & writes */
*flags |= H5FD_FEAT_AGGREGATE_SMALLDATA; /* OK to aggregate "small" raw data allocations */
*flags |= H5FD_FEAT_POSIX_COMPAT_HANDLE; /* VFD handle is POSIX I/O call compatible */
+
+ /* Check for flags that are set by h5repart */
+ if(file->fam_to_sec2)
+ *flags |= H5FD_FEAT_IGNORE_DRVRINFO; /* Ignore the driver info when file is opened (which eliminates it) */
} /* end if */
FUNC_LEAVE_NOAPI(SUCCEED)
@@ -860,56 +899,52 @@ H5FD_log_query(const H5FD_t UNUSED * _f, unsigned long *flags /* out */)
* Purpose: Allocate file memory.
*
* Return: Success: Address of new memory
- *
* Failure: HADDR_UNDEF
*
* Programmer: Quincey Koziol
* Monday, April 17, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
/* ARGSUSED */
static haddr_t
H5FD_log_alloc(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, hsize_t size)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
- haddr_t addr;
+ H5FD_log_t *file = (H5FD_log_t *)_file;
+ haddr_t addr;
haddr_t ret_value; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_alloc, HADDR_UNDEF)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_alloc)
/* Compute the address for the block to allocate */
addr = file->eoa;
/* Check if we need to align this block */
- if(size>=file->pub.threshold) {
+ if(size >= file->pub.threshold) {
/* Check for an already aligned block */
- if(addr%file->pub.alignment!=0)
- addr=((addr/file->pub.alignment)+1)*file->pub.alignment;
+ if(addr % file->pub.alignment != 0)
+ addr = ((addr / file->pub.alignment) + 1) * file->pub.alignment;
} /* end if */
- file->eoa = addr+size;
+ file->eoa = addr + size;
/* Retain the (first) flavor of the information written to the file */
- if(file->fa.flags!=0) {
- if(file->fa.flags&H5FD_LOG_FLAVOR) {
- assert(addr<file->iosize);
- H5_CHECK_OVERFLOW(size,hsize_t,size_t);
- HDmemset(&file->flavor[addr],(int)type,(size_t)size);
+ if(file->fa.flags != 0) {
+ if(file->fa.flags & H5FD_LOG_FLAVOR) {
+ HDassert(addr < file->iosize);
+ H5_CHECK_OVERFLOW(size, hsize_t, size_t);
+ HDmemset(&file->flavor[addr], (int)type, (size_t)size);
} /* end if */
- if(file->fa.flags&H5FD_LOG_ALLOC)
- HDfprintf(file->logfp,"%10a-%10a (%10Hu bytes) (%s) Allocated\n",addr,addr+size-1,size,flavors[type]);
+ if(file->fa.flags & H5FD_LOG_ALLOC)
+ HDfprintf(file->logfp, "%10a-%10a (%10Hu bytes) (%s) Allocated\n", addr, (addr + size) - 1, size, flavors[type]);
} /* end if */
/* Set return value */
- ret_value=addr;
+ ret_value = addr;
-done:
FUNC_LEAVE_NOAPI(ret_value)
-} /* H5FD_log_alloc() */
+} /* end H5FD_log_alloc() */
/*-------------------------------------------------------------------------
@@ -920,33 +955,22 @@ done:
* format address space.
*
* Return: Success: The end-of-address marker.
- *
* Failure: HADDR_UNDEF
*
* Programmer: Robb Matzke
* Monday, August 2, 1999
*
- * Modifications:
- * Raymond Lu
- * 21 Dec. 2006
- * Added the parameter TYPE. It's only used for MULTI driver.
- *
*-------------------------------------------------------------------------
*/
static haddr_t
H5FD_log_get_eoa(const H5FD_t *_file, H5FD_mem_t UNUSED type)
{
- const H5FD_log_t *file = (const H5FD_log_t*)_file;
- haddr_t ret_value; /* Return value */
-
- FUNC_ENTER_NOAPI(H5FD_log_get_eoa, HADDR_UNDEF)
+ const H5FD_log_t *file = (const H5FD_log_t *)_file;
- /* Set return value */
- ret_value=file->eoa;
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_get_eoa)
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-}
+ FUNC_LEAVE_NOAPI(file->eoa)
+} /* end H5FD_log_get_eoa() */
/*-------------------------------------------------------------------------
@@ -957,32 +981,24 @@ done:
* to tell the driver where the end of the HDF5 data is located.
*
* Return: Success: 0
- *
* Failure: -1
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- * Raymond Lu
- * 21 Dec. 2006
- * Added the parameter TYPE. It's only used for MULTI driver.
- *
*-------------------------------------------------------------------------
*/
static herr_t
H5FD_log_set_eoa(H5FD_t *_file, H5FD_mem_t UNUSED type, haddr_t addr)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5FD_log_t *file = (H5FD_log_t *)_file;
- FUNC_ENTER_NOAPI(H5FD_log_set_eoa, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_set_eoa)
file->eoa = addr;
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-}
+ FUNC_LEAVE_NOAPI(SUCCEED)
+} /* end H5FD_log_set_eoa() */
/*-------------------------------------------------------------------------
@@ -995,30 +1011,22 @@ done:
* Return: Success: End of file address, the first address past
* the end of the "file", either the Unix file
* or the HDF5 file.
- *
* Failure: HADDR_UNDEF
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static haddr_t
H5FD_log_get_eof(const H5FD_t *_file)
{
- const H5FD_log_t *file = (const H5FD_log_t*)_file;
- haddr_t ret_value; /* Return value */
+ const H5FD_log_t *file = (const H5FD_log_t *)_file;
- FUNC_ENTER_NOAPI(H5FD_log_get_eof, HADDR_UNDEF)
+ FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5FD_log_get_eof)
- /* Set return value */
- ret_value=MAX(file->eof, file->eoa);
-
-done:
- FUNC_LEAVE_NOAPI(ret_value)
-}
+ FUNC_LEAVE_NOAPI(MAX(file->eof, file->eoa))
+} /* end H5FD_log_get_eof() */
/*-------------------------------------------------------------------------
@@ -1031,18 +1039,16 @@ done:
* Programmer: Raymond Lu
* Sept. 16, 2002
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
/* ARGSUSED */
static herr_t
-H5FD_log_get_handle(H5FD_t *_file, hid_t UNUSED fapl, void** file_handle)
+H5FD_log_get_handle(H5FD_t *_file, hid_t UNUSED fapl, void **file_handle)
{
H5FD_log_t *file = (H5FD_log_t *)_file;
herr_t ret_value = SUCCEED;
- FUNC_ENTER_NOAPI(H5FD_log_get_handle, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_get_handle)
if(!file_handle)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "file handle not valid")
@@ -1051,7 +1057,7 @@ H5FD_log_get_handle(H5FD_t *_file, hid_t UNUSED fapl, void** file_handle)
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_log_get_handle() */
/*-------------------------------------------------------------------------
@@ -1063,7 +1069,6 @@ done:
*
* Return: Success: Zero. Result is stored in caller-supplied
* buffer BUF.
- *
* Failure: -1, Contents of buffer BUF are undefined.
*
* Programmer: Robb Matzke
@@ -1076,7 +1081,7 @@ static herr_t
H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr,
size_t size, void *buf/*out*/)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
+ H5FD_log_t *file = (H5FD_log_t *)_file;
ssize_t nbytes;
size_t orig_size = size; /* Save the original size for later */
haddr_t orig_addr = addr;
@@ -1085,18 +1090,18 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
#endif /* H5_HAVE_GETTIMEOFDAY */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_read, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_read)
HDassert(file && file->pub.cls);
HDassert(buf);
/* Check for overflow conditions */
- if(HADDR_UNDEF == addr)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined")
+ if(!H5F_addr_defined(addr))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr)
if(REGION_OVERFLOW(addr, size))
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow")
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr)
if((addr + size) > file->eoa)
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow")
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr)
/* Log the I/O information about the read */
if(file->fa.flags != 0) {
@@ -1117,17 +1122,16 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
if(file->fa.flags & H5FD_LOG_TIME_SEEK)
HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
- if(file_seek(file->fd, (file_offset_t)addr, SEEK_SET) < 0) {
- file->pos = HADDR_UNDEF;
- file->op = OP_UNKNOWN;
- HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
- } /* end if */
+ if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0)
+ HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags & H5FD_LOG_TIME_SEEK)
HDgettimeofday(&timeval_stop, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Log information about the seek */
+ if(file->fa.flags & H5FD_LOG_NUM_SEEK)
+ file->total_seek_ops++;
if(file->fa.flags & H5FD_LOG_LOC_SEEK) {
HDfprintf(file->logfp, "Seek: From %10a To %10a", file->pos, addr);
#ifdef H5_HAVE_GETTIMEOFDAY
@@ -1168,16 +1172,20 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
do {
nbytes = HDread(file->fd, buf, size);
} while(-1 == nbytes && EINTR == errno);
- if(-1 == nbytes) {
- /* error */
- file->pos = HADDR_UNDEF;
- file->op = OP_UNKNOWN;
- HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed")
+ if(-1 == nbytes) { /* error */
+ int myerrno = errno;
+ time_t mytime = HDtime(NULL);
+ HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+
+ if(file->fa.flags & H5FD_LOG_LOC_READ)
+ HDfprintf(file->logfp, "Error! Reading: %10a-%10a (%10Zu bytes)\n", orig_addr, (orig_addr + orig_size) - 1, orig_size);
+
+ HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, size = %lu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long)size, (unsigned long long)myoffset);
} /* end if */
if(0 == nbytes) {
/* end of file but not end of format address space */
HDmemset(buf, 0, size);
- size = 0;
+ break;
} /* end if */
HDassert(nbytes >= 0);
HDassert((size_t)nbytes <= size);
@@ -1185,7 +1193,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
size -= (size_t)nbytes;
H5_CHECK_OVERFLOW(nbytes, ssize_t, haddr_t);
addr += (haddr_t)nbytes;
- buf = (char*)buf + nbytes;
+ buf = (char *)buf + nbytes;
} /* end while */
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags & H5FD_LOG_TIME_READ)
@@ -1193,6 +1201,8 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Log information about the read */
+ if(file->fa.flags & H5FD_LOG_NUM_READ)
+ file->total_read_ops++;
if(file->fa.flags & H5FD_LOG_LOC_READ) {
HDfprintf(file->logfp, "%10a-%10a (%10Zu bytes) (%s) Read", orig_addr, (orig_addr + orig_size) - 1, orig_size, flavors[type]);
@@ -1228,6 +1238,12 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr
file->op = OP_READ;
done:
+ if(ret_value < 0) {
+ /* Reset last file I/O information */
+ file->pos = HADDR_UNDEF;
+ file->op = OP_UNKNOWN;
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_read() */
@@ -1240,14 +1256,11 @@ done:
* DXPL_ID.
*
* Return: Success: Zero
- *
* Failure: -1
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
/* ARGSUSED */
@@ -1255,7 +1268,7 @@ static herr_t
H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t addr,
size_t size, const void *buf)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
+ H5FD_log_t *file = (H5FD_log_t *)_file;
ssize_t nbytes;
size_t orig_size = size; /* Save the original size for later */
haddr_t orig_addr = addr;
@@ -1264,7 +1277,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
#endif /* H5_HAVE_GETTIMEOFDAY */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_write, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_write)
HDassert(file && file->pub.cls);
HDassert(size > 0);
@@ -1277,12 +1290,12 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
} /* end if */
/* Check for overflow conditions */
- if(HADDR_UNDEF == addr)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined")
+ if(!H5F_addr_defined(addr))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr)
if(REGION_OVERFLOW(addr, size))
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow")
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size)
if((addr + size) > file->eoa)
- HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow")
+ HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu, eoa = %llu", (unsigned long long)addr, (unsigned long long)size, (unsigned long long)file->eoa)
/* Log the I/O information about the write */
if(file->fa.flags & H5FD_LOG_FILE_WRITE) {
@@ -1301,17 +1314,16 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
if(file->fa.flags & H5FD_LOG_TIME_SEEK)
HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
- if(file_seek(file->fd, (file_offset_t)addr, SEEK_SET) < 0) {
- file->pos = HADDR_UNDEF;
- file->op = OP_UNKNOWN;
- HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
- } /* end if */
+ if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0)
+ HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags & H5FD_LOG_TIME_SEEK)
HDgettimeofday(&timeval_stop, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Log information about the seek */
+ if(file->fa.flags & H5FD_LOG_NUM_SEEK)
+ file->total_seek_ops++;
if(file->fa.flags & H5FD_LOG_LOC_SEEK) {
HDfprintf(file->logfp, "Seek: From %10a To %10a", file->pos, addr);
#ifdef H5_HAVE_GETTIMEOFDAY
@@ -1346,19 +1358,21 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
*/
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_WRITE)
- HDgettimeofday(&timeval_start,NULL);
+ HDgettimeofday(&timeval_start, NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
while(size > 0) {
do {
nbytes = HDwrite(file->fd, buf, size);
} while(-1 == nbytes && EINTR == errno);
- if(-1 == nbytes) {
- /* error */
- file->pos = HADDR_UNDEF;
- file->op = OP_UNKNOWN;
+ if(-1 == nbytes) { /* error */
+ int myerrno = errno;
+ time_t mytime = HDtime(NULL);
+ HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+
if(file->fa.flags & H5FD_LOG_LOC_WRITE)
HDfprintf(file->logfp, "Error! Writing: %10a-%10a (%10Zu bytes)\n", orig_addr, (orig_addr + orig_size) - 1, orig_size);
- HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed")
+
+ HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, size = %lu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long)size, (unsigned long long)myoffset);
} /* end if */
HDassert(nbytes > 0);
HDassert((size_t)nbytes <= size);
@@ -1366,7 +1380,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
size -= (size_t)nbytes;
H5_CHECK_OVERFLOW(nbytes, ssize_t, haddr_t);
addr += (haddr_t)nbytes;
- buf = (const char*)buf + nbytes;
+ buf = (const char *)buf + nbytes;
} /* end while */
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags & H5FD_LOG_TIME_WRITE)
@@ -1374,6 +1388,8 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Log information about the write */
+ if(file->fa.flags & H5FD_LOG_NUM_WRITE)
+ file->total_write_ops++;
if(file->fa.flags & H5FD_LOG_LOC_WRITE) {
HDfprintf(file->logfp, "%10a-%10a (%10Zu bytes) (%s) Written", orig_addr, (orig_addr + orig_size) - 1, orig_size, flavors[type]);
@@ -1415,6 +1431,12 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t UNUSED dxpl_id, haddr_t add
file->eof = file->pos;
done:
+ if(ret_value < 0) {
+ /* Reset last file I/O information */
+ file->pos = HADDR_UNDEF;
+ file->op = OP_UNKNOWN;
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_write() */
@@ -1435,22 +1457,53 @@ done:
*/
/* ARGSUSED */
static herr_t
-H5FD_log_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, unsigned UNUSED closing)
+H5FD_log_truncate(H5FD_t *_file, hid_t UNUSED dxpl_id, hbool_t UNUSED closing)
{
- H5FD_log_t *file = (H5FD_log_t*)_file;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5FD_log_t *file = (H5FD_log_t *)_file;
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI(H5FD_log_truncate, FAIL)
+ FUNC_ENTER_NOAPI_NOINIT(H5FD_log_truncate)
- if(file->eoa>file->eof) {
- if(-1 == file_seek(file->fd, (file_offset_t)(file->eoa - 1), SEEK_SET))
- HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
- if(HDwrite(file->fd, "", (size_t)1) != 1)
- HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed")
+ HDassert(file);
+
+ /* Extend the file to make sure it's large enough */
+ if(!H5F_addr_eq(file->eoa, file->eof)) {
+#ifdef _WIN32
+ HFILE filehandle; /* Windows file handle */
+ LARGE_INTEGER li; /* 64-bit integer for SetFilePointer() call */
+
+ /* Map the posix file handle to a Windows file handle */
+ filehandle = _get_osfhandle(file->fd);
+
+ /* Translate 64-bit integers into form Windows wants */
+ /* [This algorithm is from the Windows documentation for SetFilePointer()] */
+ li.QuadPart = (LONGLONG)file->eoa;
+ (void)SetFilePointer((HANDLE)filehandle, li.LowPart, &li.HighPart, FILE_BEGIN);
+ if(SetEndOfFile((HANDLE)filehandle) == 0)
+ HGOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly")
+#else /* _WIN32 */
+#ifdef H5_VMS
+ /* Reset seek offset to the beginning of the file, so that the file isn't
+ * re-extended later. This may happen on Open VMS. */
+ if(-1 == HDlseek(file->fd, (HDoff_t)0, SEEK_SET))
+ HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position")
+#endif
+
+ if(-1 == HDftruncate(file->fd, (HDoff_t)file->eoa))
+ HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to extend file properly")
+#endif /* _WIN32 */
+
+ /* Log information about the truncate */
+ if(file->fa.flags & H5FD_LOG_NUM_TRUNCATE)
+ file->total_truncate_ops++;
+
+ /* Update the eof value */
file->eof = file->eoa;
- file->pos = file->eoa;
- file->op = OP_WRITE;
- }
+
+ /* Reset last file I/O information */
+ file->pos = HADDR_UNDEF;
+ file->op = OP_UNKNOWN;
+ } /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)