Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update 'pos' and 'op' fields when using pread/pwrite #4492

Merged
merged 10 commits into from
May 23, 2024
32 changes: 23 additions & 9 deletions src/H5FDlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ static const char *flavors[] = {
* occurs), and `op' will be set to H5F_OP_UNKNOWN.
*/
typedef struct H5FD_log_t {
H5FD_t pub; /* public stuff, must be first */
int fd; /* the unix file */
haddr_t eoa; /* end of allocated region */
haddr_t eof; /* end of file; current file size */
H5FD_t pub; /* public stuff, must be first */
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 */
bool ignore_disabled_file_locks;
char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */
#endif /* H5_HAVE_PREADWRITE */
bool ignore_disabled_file_locks;
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
* identify a file. Note that Cygwin, MinGW and other Windows POSIX
Expand Down Expand Up @@ -526,8 +528,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)
Expand Down Expand Up @@ -1296,16 +1300,20 @@ H5FD__log_read(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, had
fprintf(file->logfp, "\n");
}

#ifndef H5_HAVE_PREADWRITE
/* Update current position */
file->pos = addr;
file->op = OP_READ;
#endif /* H5_HAVE_PREADWRITE */

done:
#ifndef H5_HAVE_PREADWRITE
if (ret_value < 0) {
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
}
#endif /* H5_HAVE_PREADWRITE */

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__log_read() */
Expand Down Expand Up @@ -1510,17 +1518,21 @@ H5FD__log_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, ha
}

/* Update current position and eof */
#ifndef H5_HAVE_PREADWRITE
file->pos = addr;
file->op = OP_WRITE;
if (file->pos > file->eof)
file->eof = file->pos;
#endif /* H5_HAVE_PREADWRITE */
if (addr > file->eof)
file->eof = addr;

done:
#ifndef H5_HAVE_PREADWRITE
if (ret_value < 0) {
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
}
#endif /* H5_HAVE_PREADWRITE */

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__log_write() */
Expand Down Expand Up @@ -1621,10 +1633,12 @@ H5FD__log_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, bool H5_ATTR_UNU
/* 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;
} /* end if */
#endif /* H5_HAVE_PREADWRITE */
} /* end if */

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down
36 changes: 25 additions & 11 deletions src/H5FDsec2.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ static htri_t ignore_disabled_file_locks_s = FAIL;
* occurs), and 'op' will be set to H5F_OP_UNKNOWN.
*/
typedef struct H5FD_sec2_t {
H5FD_t pub; /* public stuff, must be first */
int fd; /* the filesystem file descriptor */
haddr_t eoa; /* end of allocated region */
haddr_t eof; /* end of file; current file size */
H5FD_t pub; /* public stuff, must be first */
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 */
bool ignore_disabled_file_locks;
char filename[H5FD_MAX_FILENAME_LEN]; /* Copy of file name from open operation */
#endif /* H5_HAVE_PREADWRITE */
bool ignore_disabled_file_locks;
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
* identify a file. Note that Cygwin, MinGW and other Windows POSIX
Expand Down Expand Up @@ -334,8 +336,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)
Expand Down Expand Up @@ -721,16 +725,20 @@ H5FD__sec2_read(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNU
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:
#ifndef H5_HAVE_PREADWRITE
if (ret_value < 0) {
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
} /* end if */
} /* end if */
#endif /* H5_HAVE_PREADWRITE */

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__sec2_read() */
Expand Down Expand Up @@ -822,17 +830,21 @@ H5FD__sec2_write(H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UN
} /* end while */

/* Update current position and eof */
#ifndef H5_HAVE_PREADWRITE
file->pos = addr;
file->op = OP_WRITE;
if (file->pos > file->eof)
file->eof = file->pos;
#endif /* H5_HAVE_PREADWRITE */
if (addr > file->eof)
file->eof = addr;

done:
#ifndef H5_HAVE_PREADWRITE
if (ret_value < 0) {
/* Reset last file I/O information */
file->pos = HADDR_UNDEF;
file->op = OP_UNKNOWN;
} /* end if */
} /* end if */
#endif /* H5_HAVE_PREADWRITE */

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__sec2_write() */
Expand Down Expand Up @@ -893,10 +905,12 @@ H5FD__sec2_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, bool H5_ATTR_UN
/* 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;
} /* end if */
#endif /* H5_HAVE_PREADWRITE */
} /* end if */

done:
FUNC_LEAVE_NOAPI(ret_value)
Expand Down
Loading