From e5039ea45e6ab752c9c57c072c8a58f52a31e603 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 10 Oct 2015 09:51:13 -0700 Subject: [PATCH] Fix fadvise bug found by Robert Heinzmann --- bacula/src/findlib/bfile.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 92d6286145..99b3a5fe50 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -537,9 +537,10 @@ int bopen(BFILE *bfd, const char *fname, uint64_t flags, mode_t mode) 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 stat = posix_fadvise(bfd->fid, 0, 0, POSIX_FADV_WILLNEED); - Dmsg2(400, "Did posix_fadvise on %s stat=%d\n", fname, stat); + Dmsg3(400, "Did posix_fadvise WILLNEED on %s fid=%d stat=%d\n", fname, bfd->fid, stat); } #endif @@ -585,10 +586,12 @@ int bclose(BFILE *bfd) } #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED) - if (bfd->m_flags & O_RDONLY) { + /* If not RDWR or WRONLY must be Read Only */ + if (!(bfd->m_flags & (O_RDWR|O_WRONLY))) { fdatasync(bfd->fid); /* sync the file */ /* 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 @@ -653,4 +656,3 @@ boffset_t blseek(BFILE *bfd, boffset_t offset, int whence) bfd->berrno = errno; return pos; } - -- 2.39.5