Skip to content

Commit

Permalink
Don't update 'pos' and 'op' fields when using pread/pwrite (#4492)
Browse files Browse the repository at this point in the history
Instead of reading the absolute minimal possible, use the likely value of
a v2+ superblock w/8-byte addresses & lengths.
  • Loading branch information
qkoziol authored May 23, 2024
1 parent 4fa004e commit fcfab6f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
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

0 comments on commit fcfab6f

Please sign in to comment.