0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-04 21:08:57 +01:00

ircd::fs: Various cleanup / renames.

This commit is contained in:
Jason Volk 2018-12-28 15:02:02 -08:00
parent 9bdb7410d2
commit 30dc2ce7ed
5 changed files with 69 additions and 67 deletions

View file

@ -22,12 +22,13 @@ namespace ircd::fs::aio
{ {
struct init; struct init;
struct stats; struct stats;
struct kernel; struct system;
struct request; struct request;
extern const bool SUPPORT; extern const bool support;
extern const bool SUPPORT_FSYNC; extern const bool support_fsync;
extern const bool SUPPORT_FDSYNC; extern const bool support_fdsync;
extern const size_t MAX_EVENTS; extern const size_t MAX_EVENTS;
extern const size_t MAX_REQPRIO; extern const size_t MAX_REQPRIO;
@ -36,7 +37,7 @@ namespace ircd::fs::aio
extern conf::item<size_t> max_submit; extern conf::item<size_t> max_submit;
extern struct stats stats; extern struct stats stats;
extern kernel *context; extern struct system *system;
} }
/// Statistics structure. /// Statistics structure.

View file

@ -27,24 +27,24 @@ namespace ircd::fs::aio
// non-supporting platforms, or for items not listed here, the definitions in // non-supporting platforms, or for items not listed here, the definitions in
// ircd/fs.cc are the default. // ircd/fs.cc are the default.
decltype(ircd::fs::aio::SUPPORT) decltype(ircd::fs::aio::support)
ircd::fs::aio::SUPPORT ircd::fs::aio::support
{ {
true true
}; };
/// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then /// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored. /// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::SUPPORT_FSYNC) decltype(ircd::fs::aio::support_fsync)
ircd::fs::aio::SUPPORT_FSYNC ircd::fs::aio::support_fsync
{ {
false //TODO: get this info false //TODO: get this info
}; };
/// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then /// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored. /// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::SUPPORT_FDSYNC) decltype(ircd::fs::aio::support_fdsync)
ircd::fs::aio::SUPPORT_FDSYNC ircd::fs::aio::support_fdsync
{ {
false //TODO: get this info false //TODO: get this info
}; };
@ -52,7 +52,7 @@ ircd::fs::aio::SUPPORT_FDSYNC
decltype(ircd::fs::aio::MAX_EVENTS) decltype(ircd::fs::aio::MAX_EVENTS)
ircd::fs::aio::MAX_EVENTS ircd::fs::aio::MAX_EVENTS
{ {
128L 128L //TODO: get this info
}; };
decltype(ircd::fs::aio::MAX_REQPRIO) decltype(ircd::fs::aio::MAX_REQPRIO)
@ -67,18 +67,18 @@ ircd::fs::aio::MAX_REQPRIO
ircd::fs::aio::init::init() ircd::fs::aio::init::init()
{ {
assert(!context); assert(!system);
if(!bool(aio::enable)) if(!bool(aio::enable))
return; return;
context = new kernel{}; system = new struct system;
} }
ircd::fs::aio::init::~init() ircd::fs::aio::init::~init()
noexcept noexcept
{ {
delete context; delete system;
context = nullptr; system = nullptr;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -271,11 +271,11 @@ ircd::fs::aio::prefetch(const fd &fd,
ircd::fs::aio::request::request(const int &fd) ircd::fs::aio::request::request(const int &fd)
:iocb{0} :iocb{0}
{ {
assert(context); assert(system);
assert(ctx::current); assert(ctx::current);
aio_flags = IOCB_FLAG_RESFD; aio_flags = IOCB_FLAG_RESFD;
aio_resfd = context->resfd.native_handle(); aio_resfd = system->resfd.native_handle();
aio_fildes = fd; aio_fildes = fd;
aio_data = uintptr_t(this); aio_data = uintptr_t(this);
} }
@ -291,8 +291,8 @@ noexcept
void void
ircd::fs::aio::request::cancel() ircd::fs::aio::request::cancel()
{ {
assert(context); assert(system);
context->cancel(*this); system->cancel(*this);
stats.bytes_cancel += bytes(iovec()); stats.bytes_cancel += bytes(iovec());
stats.cancel++; stats.cancel++;
} }
@ -302,7 +302,7 @@ ircd::fs::aio::request::cancel()
size_t size_t
ircd::fs::aio::request::operator()() ircd::fs::aio::request::operator()()
{ {
assert(context); assert(system);
assert(ctx::current); assert(ctx::current);
assert(waiter == ctx::current); assert(waiter == ctx::current);
@ -312,14 +312,14 @@ ircd::fs::aio::request::operator()()
}; };
// Wait here until there's room to submit a request // Wait here until there's room to submit a request
context->dock.wait([] system->dock.wait([]
{ {
const size_t count(context->qcount + context->in_flight); const size_t count(system->qcount + system->in_flight);
return count < size_t(max_events); return count < size_t(max_events);
}); });
// Submit to kernel // Submit to system
context->submit(*this); system->submit(*this);
// Update stats for submission phase // Update stats for submission phase
stats.bytes_requests += submitted_bytes; stats.bytes_requests += submitted_bytes;
@ -328,7 +328,8 @@ ircd::fs::aio::request::operator()()
const auto &curcnt(stats.requests - stats.complete); const auto &curcnt(stats.requests - stats.complete);
stats.max_requests = std::max(stats.max_requests, curcnt); stats.max_requests = std::max(stats.max_requests, curcnt);
context->wait(*this); // Wait for completion
system->wait(*this);
assert(retval <= ssize_t(submitted_bytes)); assert(retval <= ssize_t(submitted_bytes));
// Update stats for completion phase. // Update stats for completion phase.
@ -360,14 +361,14 @@ const
} }
// //
// kernel // system
// //
// //
// kernel::kernel // system::system
// //
ircd::fs::aio::kernel::kernel() ircd::fs::aio::system::system()
try try
:event :event
{ {
@ -403,7 +404,7 @@ catch(const std::exception &e)
}; };
} }
ircd::fs::aio::kernel::~kernel() ircd::fs::aio::system::~system()
noexcept try noexcept try
{ {
assert(qcount == 0); assert(qcount == 0);
@ -428,7 +429,7 @@ catch(const std::exception &e)
} }
bool bool
ircd::fs::aio::kernel::interrupt() ircd::fs::aio::system::interrupt()
{ {
if(!resfd.is_open()) if(!resfd.is_open())
return false; return false;
@ -438,7 +439,7 @@ ircd::fs::aio::kernel::interrupt()
} }
bool bool
ircd::fs::aio::kernel::wait() ircd::fs::aio::system::wait()
{ {
if(!resfd.is_open()) if(!resfd.is_open())
return false; return false;
@ -457,7 +458,7 @@ ircd::fs::aio::kernel::wait()
} }
void void
ircd::fs::aio::kernel::wait(request &request) ircd::fs::aio::system::wait(request &request)
try try
{ {
assert(ctx::current == request.waiter); assert(ctx::current == request.waiter);
@ -479,7 +480,7 @@ catch(const ctx::terminated &)
} }
void void
ircd::fs::aio::kernel::cancel(request &request) ircd::fs::aio::system::cancel(request &request)
{ {
const auto &cb const auto &cb
{ {
@ -514,7 +515,7 @@ ircd::fs::aio::kernel::cancel(request &request)
// Setup an io_event result which we will handle as a normal event // Setup an io_event result which we will handle as a normal event
// immediately on this stack. We create our own cancel result if // immediately on this stack. We create our own cancel result if
// the request was not yet submitted to the kernel so the handler // the request was not yet submitted to the system so the handler
// remains agnostic to our userspace queues. // remains agnostic to our userspace queues.
io_event result {0}; io_event result {0};
if(erased_from_queue) if(erased_from_queue)
@ -534,7 +535,7 @@ ircd::fs::aio::kernel::cancel(request &request)
} }
void void
ircd::fs::aio::kernel::submit(request &request) ircd::fs::aio::system::submit(request &request)
{ {
assert(qcount < queue.size()); assert(qcount < queue.size());
assert(qcount + in_flight < max_events); assert(qcount + in_flight < max_events);
@ -576,14 +577,14 @@ ircd::fs::aio::kernel::submit(request &request)
return flush(); return flush();
if(qcount == 1) if(qcount == 1)
ircd::post(std::bind(&kernel::chase, this)); ircd::post(std::bind(&system::chase, this));
} }
/// The chaser is posted to the IRCd event loop after the first /// The chaser is posted to the IRCd event loop after the first
/// request is queued. Ideally more requests will queue up before /// request is queued. Ideally more requests will queue up before
/// the chaser is executed. /// the chaser is executed.
void void
ircd::fs::aio::kernel::chase() ircd::fs::aio::system::chase()
noexcept noexcept
{ {
if(qcount) if(qcount)
@ -595,7 +596,7 @@ noexcept
/// The flusher submits all queued requests and resets the count. /// The flusher submits all queued requests and resets the count.
void void
ircd::fs::aio::kernel::flush() ircd::fs::aio::system::flush()
noexcept try noexcept try
{ {
assert(qcount > 0); assert(qcount > 0);
@ -622,7 +623,7 @@ catch(const std::exception &e)
} }
void void
ircd::fs::aio::kernel::set_handle() ircd::fs::aio::system::set_handle()
{ {
ecount = 0; ecount = 0;
@ -633,7 +634,7 @@ ircd::fs::aio::kernel::set_handle()
auto handler auto handler
{ {
std::bind(&kernel::handle, this, ph::_1, ph::_2) std::bind(&system::handle, this, ph::_1, ph::_2)
}; };
asio::async_read(resfd, bufs, std::move(handler)); asio::async_read(resfd, bufs, std::move(handler));
@ -641,7 +642,7 @@ ircd::fs::aio::kernel::set_handle()
/// Handle notifications that requests are complete. /// Handle notifications that requests are complete.
void void
ircd::fs::aio::kernel::handle(const boost::system::error_code &ec, ircd::fs::aio::system::handle(const boost::system::error_code &ec,
const size_t bytes) const size_t bytes)
noexcept try noexcept try
{ {
@ -677,7 +678,7 @@ catch(const ctx::interrupted &)
} }
void void
ircd::fs::aio::kernel::handle_events() ircd::fs::aio::system::handle_events()
noexcept try noexcept try
{ {
assert(!ctx::current); assert(!ctx::current);
@ -715,7 +716,7 @@ catch(const std::exception &e)
} }
void void
ircd::fs::aio::kernel::handle_event(const io_event &event) ircd::fs::aio::system::handle_event(const io_event &event)
noexcept try noexcept try
{ {
// Our extended control block is passed in event.data // Our extended control block is passed in event.data

View file

@ -14,7 +14,7 @@
namespace ircd::fs::aio namespace ircd::fs::aio
{ {
struct kernel; struct system;
struct request; struct request;
void prefetch(const fd &, const size_t &, const read_opts &); void prefetch(const fd &, const size_t &, const read_opts &);
@ -24,9 +24,9 @@ namespace ircd::fs::aio
void fsync(const fd &, const sync_opts &); void fsync(const fd &, const sync_opts &);
} }
/// AIO context instance from the kernel. Right now this is a singleton with /// AIO context instance from the system. Right now this is a singleton with
/// an extern instance pointer at fs::aio::context maintained by fs::aio::init. /// an extern instance pointer at fs::aio::context maintained by fs::aio::init.
struct ircd::fs::aio::kernel struct ircd::fs::aio::system
{ {
/// io_getevents vector (in) /// io_getevents vector (in)
std::vector<io_event> event; std::vector<io_event> event;
@ -40,13 +40,13 @@ struct ircd::fs::aio::kernel
ctx::dock dock; ctx::dock dock;
size_t in_flight {0}; size_t in_flight {0};
/// An eventfd which will be notified by the kernel; we integrate this with /// An eventfd which will be notified by the system; we integrate this with
/// the ircd io_service core epoll() event loop. The EFD_SEMAPHORE flag is /// the ircd io_service core epoll() event loop. The EFD_SEMAPHORE flag is
/// not used to reduce the number of triggers. The semaphore value is the /// not used to reduce the number of triggers. The semaphore value is the
/// ecount (above) which will reflect a hint for how many AIO's are done. /// ecount (above) which will reflect a hint for how many AIO's are done.
asio::posix::stream_descriptor resfd; asio::posix::stream_descriptor resfd;
/// Handler to the io context we submit requests to the kernel with /// Handler to the io context we submit requests to the system with
aio_context_t idp {0}; aio_context_t idp {0};
// Callback stack invoked when the sigfd is notified of completed events. // Callback stack invoked when the sigfd is notified of completed events.
@ -66,8 +66,8 @@ struct ircd::fs::aio::kernel
bool wait(); bool wait();
bool interrupt(); bool interrupt();
kernel(); system();
~kernel() noexcept; ~system() noexcept;
}; };
/// Generic request control block. /// Generic request control block.

View file

@ -511,16 +511,16 @@ ircd::fs::flush(const fd &fd,
int(fd), int(fd),
opts.metadata, opts.metadata,
opts.aio, opts.aio,
opts.metadata? aio::SUPPORT_FDSYNC : aio::SUPPORT_FSYNC opts.metadata? aio::support_fdsync : aio::support_fsync
}; };
#ifdef IRCD_USE_AIO #ifdef IRCD_USE_AIO
if(aio::context && opts.aio) if(aio::system && opts.aio)
{ {
if(!opts.metadata && aio::SUPPORT_FDSYNC) if(!opts.metadata && aio::support_fdsync)
return aio::fdsync(fd, opts); return aio::fdsync(fd, opts);
if(aio::SUPPORT_FSYNC) if(aio::support_fsync)
return aio::fsync(fd, opts); return aio::fsync(fd, opts);
} }
#endif #endif
@ -568,7 +568,7 @@ ircd::fs::prefetch(const fd &fd,
} }
#ifdef IRCD_USE_AIO #ifdef IRCD_USE_AIO
if(likely(aio::context) && opts.aio) if(likely(aio::system) && opts.aio)
aio::prefetch(fd, count, opts); aio::prefetch(fd, count, opts);
#endif #endif
} }
@ -715,7 +715,7 @@ ircd::fs::read(const fd &fd,
const read_opts &opts) const read_opts &opts)
{ {
#ifdef IRCD_USE_AIO #ifdef IRCD_USE_AIO
if(aio::context && opts.aio) if(aio::system && opts.aio)
return aio::read(fd, iov, opts); return aio::read(fd, iov, opts);
#endif #endif
@ -981,7 +981,7 @@ ircd::fs::write(const fd &fd,
const write_opts &opts) const write_opts &opts)
{ {
#ifdef IRCD_USE_AIO #ifdef IRCD_USE_AIO
if(likely(aio::context) && opts.aio) if(likely(aio::system) && opts.aio)
return aio::write(fd, iov, opts); return aio::write(fd, iov, opts);
#endif #endif
@ -1005,17 +1005,17 @@ ircd::fs::write(const fd &fd,
// otherwise on non-supporting platforms these will be the defaults here. // otherwise on non-supporting platforms these will be the defaults here.
// //
decltype(ircd::fs::aio::SUPPORT) decltype(ircd::fs::aio::support)
extern __attribute__((weak)) extern __attribute__((weak))
ircd::fs::aio::SUPPORT; ircd::fs::aio::support;
decltype(ircd::fs::aio::SUPPORT_FSYNC) decltype(ircd::fs::aio::support_fsync)
extern __attribute__((weak)) extern __attribute__((weak))
ircd::fs::aio::SUPPORT_FSYNC; ircd::fs::aio::support_fsync;
decltype(ircd::fs::aio::SUPPORT_FDSYNC) decltype(ircd::fs::aio::support_fdsync)
extern __attribute__((weak)) extern __attribute__((weak))
ircd::fs::aio::SUPPORT_FDSYNC; ircd::fs::aio::support_fdsync;
decltype(ircd::fs::aio::MAX_REQPRIO) decltype(ircd::fs::aio::MAX_REQPRIO)
extern __attribute__((weak)) extern __attribute__((weak))
@ -1055,8 +1055,8 @@ decltype(ircd::fs::aio::stats)
ircd::fs::aio::stats; ircd::fs::aio::stats;
/// Non-null when aio is available for use /// Non-null when aio is available for use
decltype(ircd::fs::aio::context) decltype(ircd::fs::aio::system)
ircd::fs::aio::context; ircd::fs::aio::system;
// //
// init // init

View file

@ -810,7 +810,7 @@ console_cmd__env(opt &out, const string_view &line)
bool bool
console_cmd__aio(opt &out, const string_view &line) console_cmd__aio(opt &out, const string_view &line)
{ {
if(!fs::aio::context) if(!fs::aio::system)
throw error throw error
{ {
"AIO is not available." "AIO is not available."