Skip to content

Commit

Permalink
Merge pull request #496 from gjelu/issue-1227
Browse files Browse the repository at this point in the history
fix fadvise - issue 1227
  • Loading branch information
arogge committed May 11, 2020
2 parents 345b723 + ea66639 commit 8a1e696
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/src/findlib/bfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,10 @@ int bopen(BareosWinFilePacket* bfd,
bfd->win32DecompContext.liNextHeader = 0;

#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
if (bfd->fid != -1 && flags & O_RDONLY) {
/* If not RDWR or WRONLY must be Read Only */
if (bfd->fid != -1 && !(flags & (O_RDWR|O_WRONLY))) {
int status = posix_fadvise(bfd->fid, 0, 0, POSIX_FADV_WILLNEED);
Dmsg2(400, "Did posix_fadvise on %s status=%d\n", fname, status);
Dmsg3(400, "Did posix_fadvise WILLNEED on %s fid=%d status=%d\n", fname, bfd->fid, status);
}
#endif

Expand Down Expand Up @@ -1185,10 +1186,11 @@ int bclose(BareosWinFilePacket* bfd)
bfd->cmd_plugin = false;
} else {
#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
if (bfd->flags_ & O_RDONLY) {
fdatasync(bfd->fid); /* sync the file */
/* If not RDWR or WRONLY must be Read Only */
if (!(bfd->flags_ & (O_RDWR|O_WRONLY))) {
/* Tell OS we don't need it any more */
posix_fadvise(bfd->fid, 0, 0, POSIX_FADV_DONTNEED);
Dmsg1(400, "Did posix_fadvise DONTNEED on fid=%d\n", bfd->fid);
}
#endif

Expand Down

0 comments on commit 8a1e696

Please sign in to comment.