mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 06:28:55 +02:00
ircd::fs::aio: Improve handling of return and error behaviors of io_submit.
This commit is contained in:
parent
1f3dbe3948
commit
c8d5543c11
78
ircd/aio.cc
78
ircd/aio.cc
|
@ -579,8 +579,10 @@ ircd::fs::aio::system::submit(request &request)
|
|||
|| qcount >= queue.size()
|
||||
};
|
||||
|
||||
if(flush_now)
|
||||
return flush();
|
||||
const size_t flushed
|
||||
{
|
||||
flush_now? flush() : 0
|
||||
};
|
||||
|
||||
if(qcount == 1)
|
||||
ircd::post(std::bind(&system::chase, this));
|
||||
|
@ -591,38 +593,70 @@ ircd::fs::aio::system::submit(request &request)
|
|||
/// the chaser is executed.
|
||||
void
|
||||
ircd::fs::aio::system::chase()
|
||||
noexcept
|
||||
{
|
||||
if(qcount)
|
||||
flush();
|
||||
}
|
||||
|
||||
/// The flusher submits all queued requests and resets the count.
|
||||
void
|
||||
ircd::fs::aio::system::flush()
|
||||
noexcept try
|
||||
{
|
||||
assert(qcount > 0);
|
||||
assert(in_flight + qcount < MAX_EVENTS);
|
||||
assert(in_flight + qcount <= size_t(max_events));
|
||||
if(!qcount)
|
||||
return;
|
||||
|
||||
syscall<SYS_io_submit>(idp, qcount, queue.data());
|
||||
const auto submitted
|
||||
{
|
||||
flush()
|
||||
};
|
||||
|
||||
stats.cur_submits += qcount;
|
||||
stats.cur_queued -= qcount;
|
||||
stats.submits++;
|
||||
|
||||
in_flight += qcount;
|
||||
qcount = 0;
|
||||
assert(!qcount);
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
throw assertive
|
||||
{
|
||||
"AIO(%p) flush(%zu): %s", this, qcount, e.what()
|
||||
"AIO(%p) system::chase() qcount:%zu :%s", this, qcount, e.what()
|
||||
};
|
||||
}
|
||||
|
||||
/// The flusher submits all queued requests and resets the count.
|
||||
size_t
|
||||
ircd::fs::aio::system::flush()
|
||||
try
|
||||
{
|
||||
assert(qcount > 0);
|
||||
assert(in_flight + qcount < MAX_EVENTS);
|
||||
assert(in_flight + qcount <= size_t(max_events));
|
||||
|
||||
const auto submitted
|
||||
{
|
||||
syscall<SYS_io_submit>(idp, qcount, queue.data())
|
||||
};
|
||||
|
||||
stats.cur_submits += submitted;
|
||||
stats.cur_queued -= submitted;
|
||||
stats.submits++;
|
||||
|
||||
in_flight += submitted;
|
||||
qcount -= submitted;
|
||||
return submitted;
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
using std::errc;
|
||||
switch(e.code().value())
|
||||
{
|
||||
// EAGAIN may be thrown to prevent blocking. TODO: handle
|
||||
case int(errc::resource_unavailable_try_again):
|
||||
//throw;
|
||||
|
||||
// Manpages sez that EBADF is thrown if the fd in the FIRST iocb has
|
||||
// an issue. TODO: handle this by tossing the first iocb and continue.
|
||||
case int(errc::bad_file_descriptor):
|
||||
//throw;
|
||||
|
||||
// All other errors unexpected.
|
||||
default: ircd::terminate{ircd::error
|
||||
{
|
||||
"AIO(%p) system::flush() qcount:%zu :%s", this, qcount, e.what()
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ircd::fs::aio::system::set_handle()
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ struct ircd::fs::aio::system
|
|||
void handle(const boost::system::error_code &, const size_t) noexcept;
|
||||
void set_handle();
|
||||
|
||||
void flush() noexcept;
|
||||
size_t flush();
|
||||
void chase() noexcept;
|
||||
|
||||
void submit(request &);
|
||||
|
|
Loading…
Reference in a new issue