From f833001e3948c1088e09697c1b1820313e0d65e4 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 30 Jan 2019 17:32:40 -0800 Subject: Updated sec2, log, and core VFDs to use pread/pwrite when available (can be controlled via a configure/CMake option) --- CMakeLists.txt | 9 ++++++ config/cmake/H5pubconf.h.in | 3 ++ config/cmake_ext_mod/ConfigureChecks.cmake | 8 ++++-- configure.ac | 46 ++++++++++++++++++++++++++++-- src/H5FDcore.c | 28 ++++++++++++++---- src/H5FDlog.c | 30 +++++++++++++++---- src/H5FDsec2.c | 32 ++++++++++++++++----- src/H5private.h | 6 ++++ 8 files changed, 139 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a16cb08..cb9839b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -482,6 +482,15 @@ if (HDF5_MEMORY_ALLOC_SANITY_CHECK) endif () #----------------------------------------------------------------------------- +# Option to enable/disable using pread/pwrite for VFDs +#----------------------------------------------------------------------------- +option (HDF5_ENABLE_PREADWRITE "Use pread/pwrite in sec2/log/core VFDs in place of read/write (when available)" ON) +mark_as_advanced (HDF5_ENABLE_PREADWRITE) +if (HDF5_ENABLE_PREADWRITE AND ${HDF_PREFIX}_HAVE_PREAD AND ${HDF_PREFIX}_HAVE_PWRITE) + set (H5_HAVE_PREADWRITE 1) +endif () + +#----------------------------------------------------------------------------- # Option to use deprecated public API symbols #----------------------------------------------------------------------------- option (HDF5_ENABLE_DEPRECATED_SYMBOLS "Enable deprecated public API symbols" ON) diff --git a/config/cmake/H5pubconf.h.in b/config/cmake/H5pubconf.h.in index a740df2..273adb5 100644 --- a/config/cmake/H5pubconf.h.in +++ b/config/cmake/H5pubconf.h.in @@ -267,6 +267,9 @@ /* Define if we have parallel support */ #cmakedefine H5_HAVE_PARALLEL @H5_HAVE_PARALLEL@ +/* Define if both pread and pwrite exist. */ +#cmakedefine H5_HAVE_PREADWRITE @H5_HAVE_PREADWRITE@ + /* Define to 1 if you have the header file. */ #cmakedefine H5_HAVE_PTHREAD_H @H5_HAVE_PTHREAD_H@ diff --git a/config/cmake_ext_mod/ConfigureChecks.cmake b/config/cmake_ext_mod/ConfigureChecks.cmake index c24c1f8..986280f 100644 --- a/config/cmake_ext_mod/ConfigureChecks.cmake +++ b/config/cmake_ext_mod/ConfigureChecks.cmake @@ -274,10 +274,12 @@ if (NOT WINDOWS) # functionality so clock_gettime and CLOCK_MONOTONIC are defined # correctly. This was later updated to 200112L so that # posix_memalign() is visible for the direct VFD code on Linux - # systems. + # systems. Even later, this was changed to 200809L to support + # pread/pwrite in VFDs. + # # POSIX feature information can be found in the gcc manual at: # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html - set (HDF_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=200112L) + set (HDF_EXTRA_C_FLAGS -D_POSIX_C_SOURCE=200809L) # Need to add this so that O_DIRECT is visible for the direct # VFD on Linux systems. @@ -506,6 +508,8 @@ CHECK_FUNCTION_EXISTS (lround ${HDF_PREFIX}_HAVE_LROUND) CHECK_FUNCTION_EXISTS (lroundf ${HDF_PREFIX}_HAVE_LROUNDF) CHECK_FUNCTION_EXISTS (lstat ${HDF_PREFIX}_HAVE_LSTAT) +CHECK_FUNCTION_EXISTS (pread ${HDF_PREFIX}_HAVE_PREAD) +CHECK_FUNCTION_EXISTS (pwrite ${HDF_PREFIX}_HAVE_PWRITE) CHECK_FUNCTION_EXISTS (rand_r ${HDF_PREFIX}_HAVE_RAND_R) CHECK_FUNCTION_EXISTS (random ${HDF_PREFIX}_HAVE_RANDOM) CHECK_FUNCTION_EXISTS (round ${HDF_PREFIX}_HAVE_ROUND) diff --git a/configure.ac b/configure.ac index 25c4b78..30fe725 100644 --- a/configure.ac +++ b/configure.ac @@ -1130,11 +1130,12 @@ case "$host_cpu-$host_vendor-$host_os" in ## functionality so clock_gettime and CLOCK_MONOTONIC are defined ## correctly. This was later updated to 200112L so that ## posix_memalign() is visible for the direct VFD code on Linux - ## systems. + ## systems. Even later, this was changed to 200809L to support + ## pread/pwrite in VFDs. ## ## POSIX feature information can be found in the gcc manual at: ## http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html - H5_CPPFLAGS="-D_POSIX_C_SOURCE=200112L $H5_CPPFLAGS" + H5_CPPFLAGS="-D_POSIX_C_SOURCE=200809L $H5_CPPFLAGS" ## Need to add this so that O_DIRECT is visible for the direct ## VFD on Linux systems. @@ -3266,6 +3267,47 @@ esac ## ---------------------------------------------------------------------- +## Enable use of pread/pwrite instead of read/write in certain VFDs. +## +AC_SUBST([PREADWRITE]) + +## Check these first to avoid interspersed output in the AC_ARG_ENABLE line +## below. (Probably overkill to check for both, but we'll be extra careful) +PREADWRITE_HAVE_BOTH=yes +AC_CHECK_FUNC([pread], [], [PREADWRITE_HAVE_BOTH=no]) +AC_CHECK_FUNC([pwrite], [], [PREADWRITE_HAVE_BOTH=no]) + +AC_MSG_CHECKING([whether to use pread/pwrite instead of read/write in certain VFDs]) +AC_ARG_ENABLE([preadwrite], + [AS_HELP_STRING([--enable-preadwrite], + [Enable using pread/pwrite instead of read/write in sec2/log/core VFDs. + [default=yes if pread/pwrite are present]])], + [PREADWRITE=$enableval]) + +## Set the default level. +if test "X-$PREADWRITE" = X- ; then + PREADWRITE=yes +fi + +case "X-$PREADWRITE" in + X-yes) + if test "X-$PREADWRITE_HAVE_BOTH" = "X-yes"; then + AC_DEFINE([HAVE_PREADWRITE], [1], [Define if both pread and pwrite exist.]) + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + X-no) + AC_MSG_RESULT([no]) + ;; + *) + AC_MSG_ERROR([Unrecognized value: $PREADWRITE]) + ;; +esac + + +## ---------------------------------------------------------------------- ## Enable embedded library information ## AC_MSG_CHECKING([whether to have library information embedded in the executables]) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index ed05e95..d1a17cd 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -348,14 +348,17 @@ H5FD__core_write_to_bstore(H5FD_core_t *file, haddr_t addr, size_t size) 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) { h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -366,15 +369,21 @@ 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); + 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); @@ -852,6 +861,7 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr 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 */ + HDoff_t offset = (HDoff_t)0; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -862,15 +872,21 @@ H5FD__core_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, mem, bytes_in, offset); + 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); diff --git a/src/H5FDlog.c b/src/H5FDlog.c index 97d1b41..655d7d3 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -1191,7 +1191,8 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd } /* end if */ } /* end if */ - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pread) */ if(addr != file->pos || OP_READ != file->op) { #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags & H5FD_LOG_TIME_SEEK) @@ -1234,6 +1235,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* * Read data, being careful of interrupted system calls, partial results, @@ -1247,6 +1249,7 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd h5_posix_io_t bytes_in = 0; /* # of bytes to read */ h5_posix_io_ret_t bytes_read = -1; /* # of bytes actually read */ + HDoff_t offset = (HDoff_t)addr; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -1257,18 +1260,24 @@ H5FD_log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, hadd bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, buf, bytes_in, offset); + offset += bytes_read; +#else 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); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + offset = 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, 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)myoffset); + 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) { @@ -1398,7 +1407,8 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had file->nwrite[tmp_addr++]++; } /* end if */ - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pwrite) */ if(addr != file->pos || OP_WRITE != file->op) { #ifdef H5_HAVE_GETTIMEOFDAY if(file->fa.flags & H5FD_LOG_TIME_SEEK) @@ -1441,6 +1451,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had #endif /* H5_HAVE_GETTIMEOFDAY */ } /* end if */ } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* * Write the data, being careful of interrupted system calls and partial @@ -1454,6 +1465,7 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -1464,18 +1476,24 @@ H5FD_log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_wrote = HDpwrite(file->fd, buf, bytes_in, offset); + offset += bytes_wrote; +#else 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); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + offset = 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: 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)myoffset); + 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); diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index c507387..0054a86 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -682,11 +682,13 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS if(REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pread) */ if(addr != file->pos || OP_READ != file->op) { if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* Read data, being careful of interrupted system calls, partial results, * and the end of the file. @@ -694,7 +696,8 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS 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 */ + HDoff_t offset = (HDoff_t)addr; /* Trying to read more bytes than the return type can handle is * undefined behavior in POSIX. @@ -705,15 +708,21 @@ H5FD_sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUS bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_read = HDpread(file->fd, buf, bytes_in, offset); + offset += bytes_read; +#else 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); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - 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)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + 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) { @@ -777,11 +786,13 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU if(REGION_OVERFLOW(addr, size)) HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size) - /* Seek to the correct location */ +#ifndef H5_HAVE_PREADWRITE + /* Seek to the correct location (if we don't have pwrite) */ if(addr != file->pos || OP_WRITE != file->op) { if(HDlseek(file->fd, (HDoff_t)addr, SEEK_SET) < 0) HSYS_GOTO_ERROR(H5E_IO, H5E_SEEKERROR, FAIL, "unable to seek to proper position") } /* end if */ +#endif /* H5_HAVE_PREADWRITE */ /* Write the data, being careful of interrupted system calls and partial * results @@ -790,6 +801,7 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU h5_posix_io_t bytes_in = 0; /* # of bytes to write */ h5_posix_io_ret_t bytes_wrote = -1; /* # of bytes written */ + HDoff_t offset = (HDoff_t)addr; /* Trying to write more bytes than the return type can handle is * undefined behavior in POSIX. @@ -800,15 +812,21 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU bytes_in = (h5_posix_io_t)size; do { +#ifdef H5_HAVE_PREADWRITE + bytes_wrote = HDpwrite(file->fd, buf, bytes_in, offset); + offset += bytes_wrote; +#else 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); - HDoff_t myoffset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); - 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)myoffset); + offset = HDlseek(file->fd, (HDoff_t)0, SEEK_CUR); + + 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); diff --git a/src/H5private.h b/src/H5private.h index f58faec..8b6253d 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1156,6 +1156,9 @@ typedef off_t h5_stat_size_t; #ifndef HDpowf #define HDpowf(X,Y) powf(X,Y) #endif /* HDpowf */ +#ifndef HDpread + #define HDpread(F,B,C,O) pread(F,B,C,O) +#endif /* HDpread */ #ifndef HDprintf #define HDprintf(...) HDfprintf(stdout, __VA_ARGS__) #endif /* HDprintf */ @@ -1168,6 +1171,9 @@ typedef off_t h5_stat_size_t; #ifndef HDputs #define HDputs(S) puts(S) #endif /* HDputs */ +#ifndef HDpwrite + #define HDpwrite(F,B,C,O) pwrite(F,B,C,O) +#endif /* HDpwrite */ #ifndef HDqsort #define HDqsort(M,N,Z,F) qsort(M,N,Z,F) #endif /* HDqsort*/ -- cgit v0.12