mirror of
https://github.com/matrix-construct/construct
synced 2025-02-16 16:50:12 +01:00
ircd::fs: Eliminate user-defined ctors on various opts for designated inits.
This commit is contained in:
parent
0300a29f9c
commit
b815ac8bec
14 changed files with 170 additions and 138 deletions
|
@ -327,7 +327,10 @@ construct::console::handle_line_bymodule()
|
|||
{
|
||||
const fs::fd fd
|
||||
{
|
||||
record_path, std::ios::out | std::ios::app
|
||||
record_path, fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::out | std::ios::app,
|
||||
},
|
||||
};
|
||||
|
||||
// Generate a copy of the command line to give some context
|
||||
|
|
|
@ -24,6 +24,7 @@ class ircd::beep
|
|||
{
|
||||
struct ctrl;
|
||||
|
||||
static const fs::fd::opts fd_opts;
|
||||
static ctx::mutex mutex;
|
||||
static conf::item<std::string> path;
|
||||
static conf::item<bool> debug;
|
||||
|
|
|
@ -93,10 +93,6 @@ struct ircd::fs::fd::opts
|
|||
|
||||
/// 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;
|
||||
};
|
||||
|
||||
inline bool
|
||||
|
|
|
@ -54,10 +54,6 @@ struct ircd::fs::map::opts
|
|||
bool locked {false};
|
||||
bool huge2mb {false};
|
||||
bool huge1gb {false};
|
||||
|
||||
opts(const fd::opts &opts = {std::ios::in})
|
||||
:fd::opts(opts)
|
||||
{}
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
|
@ -27,6 +27,13 @@ struct ircd::fs::opts
|
|||
/// at the end of the file (RWF_APPEND or legacy non-atomic lseek()).
|
||||
off_t offset {0};
|
||||
|
||||
/// The enumerated operation code to identify the type of request being
|
||||
/// made at runtime from any abstract list of requests. This is set by
|
||||
/// the fs:: interface call and not the user in most cases. The user
|
||||
/// should not rely on this value being preserved if, e.g. they set a read
|
||||
/// opcode and then pass the opts structure to write().
|
||||
enum op op {op::NOOP};
|
||||
|
||||
/// Request priority. Lower value takes priority over higher. The lowest
|
||||
/// possible priority value is special, on supporting platforms (RWF_HIPRI).
|
||||
/// One can either simply set the integer minimum or use the extern value.
|
||||
|
@ -53,24 +60,7 @@ struct ircd::fs::opts
|
|||
/// not used simultaneously).
|
||||
bool aio {true};
|
||||
|
||||
/// The enumerated operation code to identify the type of request being
|
||||
/// made at runtime from any abstract list of requests. This is set by
|
||||
/// the fs:: interface call and not the user in most cases. The user
|
||||
/// should not rely on this value being preserved if, e.g. they set a read
|
||||
/// opcode and then pass the opts structure to write().
|
||||
enum op op {op::NOOP};
|
||||
|
||||
/// Suppress logging of some expected/tolerated failures. Set to false
|
||||
/// if the call should just silently rethrow.
|
||||
bool errlog {true};
|
||||
|
||||
opts(const off_t &, const enum op & = op::NOOP);
|
||||
opts() = default;
|
||||
};
|
||||
|
||||
inline
|
||||
ircd::fs::opts::opts(const off_t &offset,
|
||||
const enum op &op)
|
||||
:offset{offset}
|
||||
,op{op}
|
||||
{}
|
||||
|
|
|
@ -29,6 +29,12 @@ struct ircd::beep::ctrl
|
|||
int32_t tone {0};
|
||||
};
|
||||
|
||||
decltype(ircd::beep::fd_opts)
|
||||
ircd::beep::fd_opts
|
||||
{
|
||||
.mode = std::ios::out
|
||||
};
|
||||
|
||||
decltype(ircd::beep::mutex)
|
||||
ircd::beep::mutex;
|
||||
|
||||
|
@ -87,7 +93,7 @@ try
|
|||
,fd
|
||||
{
|
||||
tone > 0.0f?
|
||||
fs::fd{string_view{path}, std::ios::out}:
|
||||
fs::fd{string_view{path}, fd_opts}:
|
||||
fs::fd{-1}
|
||||
}
|
||||
{
|
||||
|
|
|
@ -1254,19 +1254,13 @@ try
|
|||
{
|
||||
env_opts
|
||||
}
|
||||
,opts{[this, &trunc]
|
||||
,opts
|
||||
{
|
||||
fs::fd::opts ret
|
||||
{
|
||||
std::ios::out |
|
||||
(trunc? std::ios::trunc : std::ios::openmode(0))
|
||||
};
|
||||
|
||||
ret.dontneed = true;
|
||||
ret.direct = this->env_opts.use_direct_writes;
|
||||
ret.cloexec = this->env_opts.set_fd_cloexec;
|
||||
return ret;
|
||||
}()}
|
||||
.mode = std::ios::out | (trunc? std::ios::trunc : std::ios::openmode(0)),
|
||||
.direct = this->env_opts.use_direct_writes,
|
||||
.cloexec = this->env_opts.set_fd_cloexec,
|
||||
.dontneed = true,
|
||||
}
|
||||
,ionice
|
||||
{
|
||||
ctx::ionice(ctx::cur())
|
||||
|
@ -1677,7 +1671,7 @@ noexcept try
|
|||
if(opts.direct)
|
||||
return Status::OK();
|
||||
|
||||
fs::evict(fd, length, fs::opts(offset));
|
||||
fs::evict(fd, length, offset);
|
||||
return Status::OK();
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
|
@ -2842,12 +2836,11 @@ const
|
|||
//
|
||||
|
||||
decltype(ircd::db::database::env::sequential_file::default_opts)
|
||||
ircd::db::database::env::sequential_file::default_opts{[]
|
||||
ircd::db::database::env::sequential_file::default_opts
|
||||
{
|
||||
ircd::fs::fd::opts ret{std::ios_base::in};
|
||||
ret.sequential = true;
|
||||
return ret;
|
||||
}()};
|
||||
.mode = std::ios_base::in,
|
||||
.sequential = true,
|
||||
};
|
||||
|
||||
ircd::db::database::env::sequential_file::sequential_file(database *const &d,
|
||||
const std::string &name,
|
||||
|
@ -3190,7 +3183,7 @@ noexcept try
|
|||
if(opts.direct)
|
||||
return Status::OK();
|
||||
|
||||
fs::evict(fd, length, fs::opts(offset));
|
||||
fs::evict(fd, length, offset);
|
||||
return Status::OK();
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
|
@ -3246,12 +3239,11 @@ const noexcept
|
|||
//
|
||||
|
||||
decltype(ircd::db::database::env::random_access_file::default_opts)
|
||||
ircd::db::database::env::random_access_file::default_opts{[]
|
||||
ircd::db::database::env::random_access_file::default_opts
|
||||
{
|
||||
ircd::fs::fd::opts ret{std::ios_base::in};
|
||||
ret.random = true;
|
||||
return ret;
|
||||
}()};
|
||||
.mode = std::ios_base::in,
|
||||
.random = true,
|
||||
};
|
||||
|
||||
ircd::db::database::env::random_access_file::random_access_file(database *const &d,
|
||||
const std::string &name,
|
||||
|
@ -3585,7 +3577,7 @@ noexcept
|
|||
if(opts.direct)
|
||||
return Status::OK();
|
||||
|
||||
fs::evict(fd, length, fs::opts(offset));
|
||||
fs::evict(fd, length, offset);
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
|
@ -3671,16 +3663,11 @@ const noexcept
|
|||
//
|
||||
|
||||
decltype(ircd::db::database::env::random_rw_file::default_opts)
|
||||
ircd::db::database::env::random_rw_file::default_opts{[]
|
||||
ircd::db::database::env::random_rw_file::default_opts
|
||||
{
|
||||
ircd::fs::fd::opts ret
|
||||
{
|
||||
std::ios_base::in | std::ios_base::out
|
||||
};
|
||||
|
||||
ret.random = true;
|
||||
return ret;
|
||||
}()};
|
||||
.mode = std::ios_base::in | std::ios_base::out,
|
||||
.random = true,
|
||||
};
|
||||
|
||||
ircd::db::database::env::random_rw_file::random_rw_file(database *const &d,
|
||||
const std::string &name,
|
||||
|
|
125
ircd/fs.cc
125
ircd/fs.cc
|
@ -294,14 +294,12 @@ ircd::fs::support::fallocate(const string_view &path,
|
|||
const write_opts &wopts)
|
||||
try
|
||||
{
|
||||
const fd::opts opts
|
||||
const fs::fd fd
|
||||
{
|
||||
std::ios::out
|
||||
};
|
||||
|
||||
fs::fd fd
|
||||
{
|
||||
path, opts
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out,
|
||||
},
|
||||
};
|
||||
|
||||
fs::allocate(fd, info::page_size, wopts);
|
||||
|
@ -327,9 +325,15 @@ bool
|
|||
ircd::fs::support::direct_io(const string_view &path)
|
||||
try
|
||||
{
|
||||
fd::opts opts{std::ios::out};
|
||||
opts.direct = true;
|
||||
fd{path, opts};
|
||||
fs::fd
|
||||
{
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out,
|
||||
.direct = true,
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
|
@ -615,10 +619,13 @@ ircd::fs::stdin::tty::tty()
|
|||
:fd{[]
|
||||
{
|
||||
char buf[256];
|
||||
syscall(::ttyname_r, STDIN_FILENO, buf, sizeof(buf));
|
||||
return fd
|
||||
sys::call(::ttyname_r, STDIN_FILENO, buf, sizeof(buf));
|
||||
return fs::fd
|
||||
{
|
||||
string_view{buf}, std::ios_base::out
|
||||
string_view{buf}, fd::opts
|
||||
{
|
||||
.mode = std::ios_base::out
|
||||
}
|
||||
};
|
||||
}()}
|
||||
{
|
||||
|
@ -829,9 +836,15 @@ ircd::fs::incore(const fd &fd,
|
|||
const size_t &count,
|
||||
const read_opts &opts)
|
||||
{
|
||||
fs::map::opts map_opts;
|
||||
map_opts.offset = align(opts.offset, info::page_size);
|
||||
map_opts.blocking = false;
|
||||
const fs::map::opts map_opts
|
||||
{
|
||||
fs::opts
|
||||
{
|
||||
.offset = off_t(align(opts.offset, info::page_size)),
|
||||
.blocking = false,
|
||||
},
|
||||
};
|
||||
|
||||
const size_t &map_size
|
||||
{
|
||||
count?: size(fd)
|
||||
|
@ -1157,9 +1170,12 @@ ircd::fs::truncate(const string_view &path,
|
|||
const size_t &size,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const fd fd
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::out | std::ios::trunc
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out | std::ios::trunc,
|
||||
},
|
||||
};
|
||||
|
||||
return truncate(fd, size, opts);
|
||||
|
@ -1211,9 +1227,12 @@ ircd::fs::overwrite(const string_view &path,
|
|||
const const_buffers &bufs,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const fd fd
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::out | std::ios::trunc
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out | std::ios::trunc,
|
||||
},
|
||||
};
|
||||
|
||||
return overwrite(fd, bufs, opts);
|
||||
|
@ -1268,9 +1287,12 @@ ircd::fs::append(const string_view &path,
|
|||
const const_buffers &bufs,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const fd fd
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::out | std::ios::app
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out | std::ios::app
|
||||
},
|
||||
};
|
||||
|
||||
return append(fd, bufs, opts);
|
||||
|
@ -1331,9 +1353,12 @@ ircd::fs::write(const string_view &path,
|
|||
const const_buffers &bufs,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const fd fd
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::out
|
||||
path, fd::opts
|
||||
{
|
||||
.mode = std::ios::out
|
||||
},
|
||||
};
|
||||
|
||||
return write(fd, bufs, opts);
|
||||
|
@ -2239,6 +2264,7 @@ namespace ircd::fs
|
|||
{
|
||||
static uint flags(const fd::opts &);
|
||||
static uint flags(const std::ios::openmode &);
|
||||
static fd::opts make(const fd::opts &);
|
||||
static long pathconf(const fd &, const int &arg);
|
||||
}
|
||||
|
||||
|
@ -2438,32 +2464,6 @@ ircd::fs::size(const fd &fd)
|
|||
return end;
|
||||
}
|
||||
|
||||
//
|
||||
// fd::opts
|
||||
//
|
||||
|
||||
ircd::fs::fd::opts::opts(const std::ios::openmode &mode)
|
||||
:mode
|
||||
{
|
||||
mode
|
||||
}
|
||||
,flags
|
||||
{
|
||||
fs::flags(mode)
|
||||
}
|
||||
,mask
|
||||
{
|
||||
flags & O_CREAT?
|
||||
S_IRUSR | S_IWUSR:
|
||||
0U
|
||||
}
|
||||
,ate
|
||||
{
|
||||
bool(mode & std::ios::ate)
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// fd::fd
|
||||
//
|
||||
|
@ -2495,7 +2495,7 @@ ircd::fs::fd::fd(const string_view &path,
|
|||
|
||||
ircd::fs::fd::fd(const int &dirfd,
|
||||
const string_view &path,
|
||||
const opts &opts)
|
||||
const opts &opts_)
|
||||
try
|
||||
:fdno
|
||||
{
|
||||
|
@ -2507,6 +2507,11 @@ try
|
|||
[this] { this->~fd(); }
|
||||
};
|
||||
|
||||
const auto opts
|
||||
{
|
||||
make(opts_)
|
||||
};
|
||||
|
||||
const mode_t mode
|
||||
{
|
||||
mode_t(opts.mask)
|
||||
|
@ -2548,7 +2553,7 @@ try
|
|||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
if(opts.errlog)
|
||||
if(opts_.errlog)
|
||||
log::derror
|
||||
{
|
||||
log, "`%s' :%s",
|
||||
|
@ -2633,6 +2638,22 @@ const
|
|||
return ret;
|
||||
}
|
||||
|
||||
ircd::fs::fd::opts
|
||||
ircd::fs::make(const fd::opts &opts)
|
||||
{
|
||||
fd::opts ret(opts);
|
||||
if(!ret.flags)
|
||||
ret.flags = fs::flags(ret);
|
||||
|
||||
if(!ret.mask && (ret.flags & O_CREAT))
|
||||
ret.mask = S_IRUSR | S_IWUSR;
|
||||
|
||||
if(!ret.ate)
|
||||
ret.ate = bool(ret.mode & std::ios::ate);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint
|
||||
ircd::fs::flags(const fd::opts &opts)
|
||||
{
|
||||
|
|
|
@ -140,7 +140,10 @@ ircd::gpt::pipe::code::set_cache(const string_view &path)
|
|||
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::out
|
||||
path, fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::out
|
||||
},
|
||||
};
|
||||
|
||||
const auto written
|
||||
|
|
|
@ -94,7 +94,7 @@ try
|
|||
|
||||
const fs::fd::opts opts
|
||||
{
|
||||
std::ios::in | std::ios::out
|
||||
.mode = std::ios::in | std::ios::out
|
||||
};
|
||||
|
||||
// Open the fd's; if triggers were given we don't open files that were
|
||||
|
|
|
@ -92,17 +92,16 @@ ircd::m::events::dump__file(const string_view &filename)
|
|||
db::get::NO_CACHE, db::get::NO_CHECKSUM
|
||||
};
|
||||
|
||||
static const fs::fd::opts fileopts
|
||||
const fs::fd::opts fileopts
|
||||
{
|
||||
std::ios::out
|
||||
.mode = std::ios::out,
|
||||
.exclusive = true, // error if exists
|
||||
.dontneed = true, // fadvise
|
||||
};
|
||||
|
||||
auto _fileopts(fileopts);
|
||||
_fileopts.exclusive = true; // error if exists
|
||||
_fileopts.dontneed = true; // fadvise
|
||||
const fs::fd file
|
||||
{
|
||||
filename, _fileopts
|
||||
filename, fileopts
|
||||
};
|
||||
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
|
|
|
@ -193,19 +193,27 @@ try
|
|||
has(string_view(ircd::diagnostic), "valid-json")
|
||||
};
|
||||
|
||||
fs::fd::opts fileopts(std::ios::in);
|
||||
const fs::fd file
|
||||
{
|
||||
path, fileopts
|
||||
path, fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::in
|
||||
},
|
||||
};
|
||||
|
||||
fs::map::opts map_opts(fileopts);
|
||||
map_opts.sequential = true;
|
||||
map_opts.huge2mb = true;
|
||||
map_opts.huge1gb = true;
|
||||
const fs::map map
|
||||
{
|
||||
file, map_opts
|
||||
file, fs::map::opts
|
||||
{
|
||||
fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::in,
|
||||
.sequential = true,
|
||||
},
|
||||
|
||||
.huge2mb = true,
|
||||
.huge1gb = true,
|
||||
},
|
||||
};
|
||||
|
||||
// This array is backed by the mmap
|
||||
|
@ -330,7 +338,14 @@ try
|
|||
|
||||
// advise dontneed
|
||||
if(likely(!validate_json_only))
|
||||
ebytes[0] += evict(map, incore, ebytes[0]);
|
||||
{
|
||||
const fs::opts opts
|
||||
{
|
||||
.offset = off_t(ebytes[0]),
|
||||
};
|
||||
|
||||
ebytes[0] += evict(map, incore, opts);
|
||||
}
|
||||
|
||||
if(count % (batch_max * 256) != 0)
|
||||
continue;
|
||||
|
|
|
@ -17,7 +17,10 @@ ircd::m::rooms::dump__file(const opts &opts,
|
|||
{
|
||||
const fs::fd file
|
||||
{
|
||||
filename, std::ios::out | std::ios::app
|
||||
filename, fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::out | std::ios::app,
|
||||
},
|
||||
};
|
||||
|
||||
// POSIX_FADV_DONTNEED
|
||||
|
|
|
@ -1093,9 +1093,12 @@ console_cmd__proc(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
fs::fd fd
|
||||
const fs::fd fd
|
||||
{
|
||||
path, std::ios::in
|
||||
path, fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::in,
|
||||
},
|
||||
};
|
||||
|
||||
fs::read_opts opts;
|
||||
|
@ -1124,7 +1127,10 @@ console_cmd__proc__smaps(opt &out, const string_view &line)
|
|||
{
|
||||
fs::fd fd
|
||||
{
|
||||
"/proc/self/smaps", std::ios::in //TODO: XXX windows
|
||||
"/proc/self/smaps", fs::fd::opts
|
||||
{
|
||||
.mode = std::ios::in,
|
||||
},
|
||||
};
|
||||
|
||||
fs::read_opts opts;
|
||||
|
@ -8763,16 +8769,22 @@ console_cmd__eval__file(opt &out, const string_view &line)
|
|||
param.at<size_t>("limit", -1UL)
|
||||
};
|
||||
|
||||
fs::fd::opts file_opts(std::ios::in);
|
||||
const fs::fd file
|
||||
const fs::fd::opts opts
|
||||
{
|
||||
path, file_opts
|
||||
.mode = std::ios::in,
|
||||
};
|
||||
|
||||
const fs::fd file
|
||||
{
|
||||
path, opts
|
||||
};
|
||||
|
||||
fs::map::opts map_opts(file_opts);
|
||||
const fs::map map
|
||||
{
|
||||
file, map_opts
|
||||
file, fs::map::opts
|
||||
{
|
||||
opts
|
||||
},
|
||||
};
|
||||
|
||||
// This array is backed by the mmap
|
||||
|
|
Loading…
Add table
Reference in a new issue