0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Simplify interface.

This commit is contained in:
Jason Volk 2018-12-13 17:46:08 -08:00
parent 9d423f84d8
commit 5e8d5562da
3 changed files with 28 additions and 23 deletions

View file

@ -15,8 +15,7 @@ namespace ircd::fs
{
struct sync_opts extern const sync_opts_default;
void fdsync(const fd &, const sync_opts & = sync_opts_default);
void fsync(const fd &, const sync_opts & = sync_opts_default);
void flush(const fd &, const sync_opts & = sync_opts_default);
void sync(const fd &, const sync_opts & = sync_opts_default);
}
@ -25,11 +24,17 @@ struct ircd::fs::sync_opts
{
sync_opts() = default;
/// Set to true to flush metadata; otherwise only data is flushed.
/// This ends up forcing the use of fsync() rather than fdatasync() or
/// sync_file_range() et al.
bool metadata {true};
/// Determines whether this operation is conducted via AIO. If not, a
/// direct syscall is made. Using AIO will only block one ircd::ctx while
/// a direct syscall will block the thread (all contexts). If AIO is not
/// available or enabled setting this has no effect.
bool synchronous {false};
/// available or not enabled, or doesn't support this operation, setting
/// this has no effect.
bool yielding {true};
/// Request priority. This value is ignored by the kernel for the
/// operations provided by this interface. It is still provided for

View file

@ -4755,7 +4755,8 @@ noexcept try
#endif
fs::sync_opts opts;
fs::fdsync(fd, opts);
opts.metadata = false;
fs::flush(fd, opts);
return Status::OK();
}
catch(const std::system_error &e)
@ -4847,7 +4848,7 @@ noexcept try
#endif
fs::sync_opts opts;
fs::fsync(fd, opts);
fs::flush(fd, opts);
return Status::OK();
}
catch(const std::system_error &e)
@ -6984,7 +6985,7 @@ noexcept try
#endif
fs::sync_opts opts;
fs::fsync(fd, opts);
fs::flush(fd, opts);
return Status::OK();
}
catch(const std::system_error &e)
@ -7078,7 +7079,8 @@ noexcept try
#endif
fs::sync_opts opts;
fs::fdsync(fd, opts);
opts.metadata = false;
fs::flush(fd, opts);
return Status::OK();
}
catch(const std::system_error &e)

View file

@ -530,27 +530,25 @@ ircd::fs::sync(const fd &fd,
}
void
ircd::fs::fsync(const fd &fd,
ircd::fs::flush(const fd &fd,
const sync_opts &opts)
{
#ifdef IRCD_USE_AIO
if(aio::context && !opts.synchronous && support::aio_fsync)
return aio::fsync(fd, opts);
if(aio::context && opts.yielding)
{
if(!opts.metadata && support::aio_fdsync)
return aio::fdsync(fd, opts);
if(opts.metadata && support::aio_fsync)
return aio::fsync(fd, opts);
}
#endif
syscall(::fsync, fd);
}
if(!opts.metadata)
return void(syscall(::fdatasync, fd));
void
ircd::fs::fdsync(const fd &fd,
const sync_opts &opts)
{
#ifdef IRCD_USE_AIO
if(aio::context && !opts.synchronous && support::aio_fdsync)
return aio::fdsync(fd, opts);
#endif
syscall(::fdatasync, fd);
if(opts.metadata)
return void(syscall(::fsync, fd));
}
///////////////////////////////////////////////////////////////////////////////