summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@koziol.gov>2020-03-29 02:53:43 (GMT)
committerQuincey Koziol <koziol@koziol.gov>2020-03-29 02:53:43 (GMT)
commit9e5a68214a5e40bb8e43c5ec2a928dc70e8a6017 (patch)
treee369e399e7f5b5715a19093c125042200be0e183
parente9e3e2f1d67ccf71cc5af711065d1f85761ab5b7 (diff)
downloadhdf5-9e5a68214a5e40bb8e43c5ec2a928dc70e8a6017.zip
hdf5-9e5a68214a5e40bb8e43c5ec2a928dc70e8a6017.tar.gz
hdf5-9e5a68214a5e40bb8e43c5ec2a928dc70e8a6017.tar.bz2
Don't track file offset position when using pread / pwrite.
-rw-r--r--src/H5FDcore.c42
-rw-r--r--src/H5FDlog.c29
-rw-r--r--src/H5FDprivate.h2
-rw-r--r--src/H5FDsec2.c39
4 files changed, 80 insertions, 32 deletions
diff --git a/src/H5FDcore.c b/src/H5FDcore.c
index 552b7ca..91338d7 100644
--- a/src/H5FDcore.c
+++ b/src/H5FDcore.c
@@ -82,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? */
@@ -382,7 +382,9 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size)
int myerrno = errno;
time_t mytime = HDtime(NULL);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
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 */
@@ -405,7 +407,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
*
*-------------------------------------------------------------------------
*/
@@ -757,9 +759,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) {
@@ -856,14 +858,14 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
/* 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 */
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.
*/
@@ -871,7 +873,7 @@ 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);
@@ -881,19 +883,21 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr
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);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
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 */
@@ -1467,24 +1471,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
*
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index 60255e5..c9aa44d 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -78,8 +78,10 @@ typedef struct H5FD_log_t {
int fd; /* the unix file */
haddr_t eoa; /* end of allocated region */
haddr_t eof; /* end of file; current file size */
+#ifndef H5_HAVE_PREADWRITE
haddr_t pos; /* current file I/O position */
H5FD_file_op_t op; /* last operation */
+#endif /* H5_HAVE_PREADWRITE */
char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */
#ifndef H5_HAVE_WIN32_API
/* On most systems the combination of device and i-node number uniquely
@@ -108,7 +110,7 @@ typedef struct H5FD_log_t {
DWORD nFileIndexLow;
DWORD nFileIndexHigh;
DWORD dwVolumeSerialNumber;
-
+
HANDLE hFile; /* Native windows file handle */
#endif /* H5_HAVE_WIN32_API */
@@ -578,8 +580,10 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
file->fd = fd;
H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t);
+#ifndef H5_HAVE_PREADWRITE
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
#ifdef H5_HAVE_WIN32_API
file->hFile = (HANDLE)_get_osfhandle(fd);
if(INVALID_HANDLE_VALUE == file->hFile)
@@ -1255,7 +1259,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd
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 */
+ 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.
@@ -1279,7 +1283,9 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd
int myerrno = errno;
time_t mytime = HDtime(NULL);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
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);
@@ -1295,7 +1301,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd
HDassert(bytes_read >= 0);
HDassert((size_t)bytes_read <= size);
-
+
size -= (size_t)bytes_read;
addr += (haddr_t)bytes_read;
buf = (char *)buf + bytes_read;
@@ -1344,15 +1350,19 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd
#endif /* H5_HAVE_GETTIMEOFDAY */
} /* end if */
+#ifndef H5_HAVE_PREADWRITE
/* Update current position */
file->pos = addr;
file->op = OP_READ;
+#endif /* H5_HAVE_PREADWRITE */
done:
if(ret_value < 0) {
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -1472,7 +1482,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
while(size > 0) {
h5_posix_io_t bytes_in = 0; /* # of bytes to write */
- h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* Trying to write more bytes than the return type can handle is
* undefined behavior in POSIX.
@@ -1496,7 +1506,9 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
int myerrno = errno;
time_t mytime = HDtime(NULL);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
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);
@@ -1555,17 +1567,24 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
#endif /* H5_HAVE_GETTIMEOFDAY */
} /* end if */
+#ifndef H5_HAVE_PREADWRITE
/* Update current position and eof */
file->pos = addr;
file->op = OP_WRITE;
if(file->pos > file->eof)
file->eof = file->pos;
+#else /* H5_HAVE_PREADWRITE */
+ if(addr > file->eof)
+ file->eof = addr;
+#endif /* H5_HAVE_PREADWRITE */
done:
if(ret_value < 0) {
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -1674,9 +1693,11 @@ H5FD_log_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATTR_U
/* Update the eof value */
file->eof = file->eoa;
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
done:
diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h
index 2e3d3ce..0f014bf 100644
--- a/src/H5FDprivate.h
+++ b/src/H5FDprivate.h
@@ -59,12 +59,14 @@ typedef struct H5FD_class_mpi_t {
/* Library Private Typedefs */
/****************************/
+#ifndef H5_HAVE_PREADWRITE
/* File operations */
typedef enum {
OP_UNKNOWN = 0, /* Unknown last file operation */
OP_READ = 1, /* Last file I/O operation was a read */
OP_WRITE = 2 /* Last file I/O operation was a write */
} H5FD_file_op_t;
+#endif /* H5_HAVE_PREADWRITE */
/* Define structure to hold initial file image and other relevant information */
diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c
index a393490..98021ca 100644
--- a/src/H5FDsec2.c
+++ b/src/H5FDsec2.c
@@ -55,8 +55,10 @@ typedef struct H5FD_sec2_t {
int fd; /* the filesystem file descriptor */
haddr_t eoa; /* end of allocated region */
haddr_t eof; /* end of file; current file size */
+#ifndef H5_HAVE_PREADWRITE
haddr_t pos; /* current file I/O position */
H5FD_file_op_t op; /* last operation */
+#endif /* H5_HAVE_PREADWRITE */
char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */
#ifndef H5_HAVE_WIN32_API
/* On most systems the combination of device and i-node number uniquely
@@ -85,7 +87,7 @@ typedef struct H5FD_sec2_t {
DWORD nFileIndexLow;
DWORD nFileIndexHigh;
DWORD dwVolumeSerialNumber;
-
+
HANDLE hFile; /* Native windows file handle */
#endif /* H5_HAVE_WIN32_API */
@@ -355,8 +357,10 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
file->fd = fd;
H5_CHECKED_ASSIGN(file->eof, haddr_t, sb.st_size, h5_stat_size_t);
+#ifndef H5_HAVE_PREADWRITE
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
#ifdef H5_HAVE_WIN32_API
file->hFile = (HANDLE)_get_osfhandle(fd);
if(INVALID_HANDLE_VALUE == file->hFile)
@@ -599,7 +603,7 @@ H5FD_sec2_set_eoa(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, haddr_t addr)
* either the filesystem end-of-file or the HDF5 end-of-address
* markers.
*
- * Return: End of file address, the first address past the end of the
+ * Return: End of file address, the first address past the end of the
* "file", either the filesystem file or the HDF5 file.
*
* Programmer: Robb Matzke
@@ -716,39 +720,45 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS
bytes_read = HDread(file->fd, buf, 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);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file read failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total read size = %llu, bytes this sub-read = %llu, bytes actually read = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_read, (unsigned long long)offset);
} /* end if */
-
+
if(0 == bytes_read) {
/* end of file but not end of format address space */
HDmemset(buf, 0, size);
break;
} /* end if */
-
+
HDassert(bytes_read >= 0);
HDassert((size_t)bytes_read <= size);
-
+
size -= (size_t)bytes_read;
addr += (haddr_t)bytes_read;
buf = (char *)buf + bytes_read;
} /* end while */
+#ifndef H5_HAVE_PREADWRITE
/* Update current position */
file->pos = addr;
file->op = OP_READ;
+#endif /* H5_HAVE_PREADWRITE */
done:
if(ret_value < 0) {
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -802,7 +812,7 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
while(size > 0) {
h5_posix_io_t bytes_in = 0; /* # of bytes to write */
- h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
+ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */
/* Trying to write more bytes than the return type can handle is
* undefined behavior in POSIX.
@@ -821,16 +831,18 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
bytes_wrote = HDwrite(file->fd, buf, 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);
+#ifndef H5_HAVE_PREADWRITE
offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR);
+#endif /* H5_HAVE_PREADWRITE */
HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "file write failed: time = %s, filename = '%s', file descriptor = %d, errno = %d, error message = '%s', buf = %p, total write size = %llu, bytes this sub-write = %llu, bytes actually written = %llu, offset = %llu", HDctime(&mytime), file->filename, file->fd, myerrno, HDstrerror(myerrno), buf, (unsigned long long)size, (unsigned long long)bytes_in, (unsigned long long)bytes_wrote, (unsigned long long)offset);
} /* end if */
-
+
HDassert(bytes_wrote > 0);
HDassert((size_t)bytes_wrote <= size);
@@ -839,17 +851,24 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
buf = (const char *)buf + bytes_wrote;
} /* end while */
+#ifndef H5_HAVE_PREADWRITE
/* Update current position and eof */
file->pos = addr;
file->op = OP_WRITE;
if(file->pos > file->eof)
file->eof = file->pos;
+#else /* H5_HAVE_PREADWRITE */
+ if(addr > file->eof)
+ file->eof = addr;
+#endif /* H5_HAVE_PREADWRITE */
done:
if(ret_value < 0) {
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -915,9 +934,11 @@ H5FD_sec2_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_ATTR_
/* Update the eof value */
file->eof = file->eoa;
+#ifndef H5_HAVE_PREADWRITE
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
+#endif /* H5_HAVE_PREADWRITE */
} /* end if */
done: