0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd::fs: Add options to fadvise() on fd open().

This commit is contained in:
Jason Volk 2020-05-09 18:34:50 -07:00
parent 7dc740e387
commit 8c15247efc
2 changed files with 25 additions and 0 deletions

View file

@ -81,6 +81,15 @@ struct ircd::fs::fd::opts
/// (O_NONBLOCK) Non-blocking behavior.
bool blocking {true};
/// Advise for random access (ignored when direct=true)
bool random {false};
/// Advise for sequential access (ignored when direct=true)
bool sequential {false};
/// Advise for dontneed access (ignored when direct=true)
bool dontneed {false};
/// Construct options from an std::ios::open_mode bitmask.
opts(const std::ios::openmode &);
opts() = default;

View file

@ -2028,6 +2028,22 @@ try
return syscall(::open, path_cstr(path), flags, mode);
}()}
{
const int advise
{
opts.direct?
0:
opts.random?
POSIX_FADV_RANDOM:
opts.sequential?
POSIX_FADV_SEQUENTIAL:
opts.dontneed?
POSIX_FADV_DONTNEED:
0
};
if(advise)
fs::advise(*this, advise);
if(opts.ate)
syscall(::lseek, fdno, 0, SEEK_END);
}