From fcaa0b9b5c454143e121c2937b5529f7b405cbd7 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 18 Aug 2020 11:11:26 -0700 Subject: Revert "Don't track file offset position when using pread / pwrite." This reverts commit 9e5a68214a5e40bb8e43c5ec2a928dc70e8a6017. --- src/H5FDcore.c | 42 +++++++++++++++++++----------------------- src/H5FDlog.c | 29 ++++------------------------- src/H5FDprivate.h | 2 -- src/H5FDsec2.c | 39 +++++++++------------------------------ 4 files changed, 32 insertions(+), 80 deletions(-) diff --git a/src/H5FDcore.c b/src/H5FDcore.c index 14c896a..9252481 100644 --- a/src/H5FDcore.c +++ b/src/H5FDcore.c @@ -85,7 +85,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? */ @@ -381,9 +381,7 @@ 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 */ @@ -406,7 +404,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 * *------------------------------------------------------------------------- */ @@ -666,9 +664,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) { @@ -775,14 +773,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. */ @@ -790,7 +788,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); @@ -800,21 +798,19 @@ 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 */ @@ -1395,24 +1391,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 cbd475f..f5572e4 100644 --- a/src/H5FDlog.c +++ b/src/H5FDlog.c @@ -81,10 +81,8 @@ 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 */ hbool_t ignore_disabled_file_locks; char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */ #ifndef H5_HAVE_WIN32_API @@ -114,7 +112,7 @@ typedef struct H5FD_log_t { DWORD nFileIndexLow; DWORD nFileIndexHigh; DWORD dwVolumeSerialNumber; - + HANDLE hFile; /* Native windows file handle */ #endif /* H5_HAVE_WIN32_API */ @@ -573,10 +571,8 @@ 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) @@ -1260,7 +1256,7 @@ H5FD__log_read(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 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. @@ -1284,9 +1280,7 @@ H5FD__log_read(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_READ) HDfprintf(file->logfp, "Error! Reading: %10a-%10a (%10Zu bytes)\n", orig_addr, (orig_addr + orig_size) - 1, orig_size); @@ -1302,7 +1296,7 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had 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; @@ -1343,19 +1337,15 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had HDfprintf(file->logfp, "\n"); } /* 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) @@ -1475,7 +1465,7 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha */ 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. @@ -1499,9 +1489,7 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha 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); @@ -1553,24 +1541,17 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha HDfprintf(file->logfp, "\n"); } /* 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) @@ -1675,11 +1656,9 @@ H5FD__log_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: diff --git a/src/H5FDprivate.h b/src/H5FDprivate.h index c7994ac..c5bc043 100644 --- a/src/H5FDprivate.h +++ b/src/H5FDprivate.h @@ -59,14 +59,12 @@ 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 6a16838..06eb822 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -58,10 +58,8 @@ 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 */ hbool_t ignore_disabled_file_locks; char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */ #ifndef H5_HAVE_WIN32_API @@ -91,7 +89,7 @@ typedef struct H5FD_sec2_t { DWORD nFileIndexLow; DWORD nFileIndexHigh; DWORD dwVolumeSerialNumber; - + HANDLE hFile; /* Native windows file handle */ #endif /* H5_HAVE_WIN32_API */ @@ -371,10 +369,8 @@ 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) @@ -632,7 +628,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 @@ -747,45 +743,39 @@ H5FD__sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU 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) @@ -837,7 +827,7 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN */ 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. @@ -856,18 +846,16 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN 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); @@ -876,24 +864,17 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN 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) @@ -959,11 +940,9 @@ 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: -- cgit v0.12