0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-10 20:11:07 +01:00
construct/ircd/fs_aio.h

134 lines
3.4 KiB
C
Raw Normal View History

2018-02-04 03:22:01 +01:00
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
2018-02-04 03:22:01 +01:00
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
2018-02-04 03:22:01 +01:00
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_FS_AIO_H
#include <linux/aio_abi.h>
namespace ircd::fs::aio
2018-08-21 07:45:06 +02:00
{
2018-12-29 00:02:02 +01:00
struct system;
struct request;
void prefetch(const fd &, const size_t &, const read_opts &);
size_t write(const fd &, const const_iovec_view &, const write_opts &);
size_t read(const fd &, const const_iovec_view &, const read_opts &);
void fdsync(const fd &, const sync_opts &);
void fsync(const fd &, const sync_opts &);
2018-08-21 07:45:06 +02:00
}
2018-12-29 00:02:02 +01:00
/// 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.
2018-12-29 00:02:02 +01:00
struct ircd::fs::aio::system
{
static const int eventfd_flags;
/// io_getevents vector (in)
std::vector<io_event> event;
uint64_t ecount {0};
/// io_submit queue (out)
std::vector<iocb *> queue;
size_t qcount {0};
/// other state
ctx::dock dock;
size_t in_flight {0};
bool handle_set {false};
2018-12-29 00:02:02 +01:00
/// 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
/// 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.
2018-02-06 07:42:40 +01:00
asio::posix::stream_descriptor resfd;
2018-12-29 00:02:02 +01:00
/// Handler to the io context we submit requests to the system with
2018-02-06 07:42:40 +01:00
aio_context_t idp {0};
size_t max_events() const;
size_t max_submit() const;
size_t request_count() const; // qcount + in_flight
size_t request_avail() const; // max_events - request_count()
// Callback stack invoked when the sigfd is notified of completed events.
void handle_event(const io_event &) noexcept;
void handle_events() noexcept;
void handle(const boost::system::error_code &, const size_t) noexcept;
void set_handle();
2018-12-30 04:09:52 +01:00
size_t submit();
void chase() noexcept;
void submit(request &);
void cancel(request &);
void wait(request &);
// Control panel
2018-08-19 07:58:43 +02:00
bool wait();
bool interrupt();
system(const size_t &max_events,
const size_t &max_submit);
2018-12-29 00:02:02 +01:00
~system() noexcept;
};
/// Generic request control block.
struct ircd::fs::aio::request
:iocb
{
struct read;
struct write;
2018-08-19 07:58:43 +02:00
struct fdsync;
struct fsync;
ctx::ctx *waiter {ctx::current};
ssize_t retval {std::numeric_limits<ssize_t>::min()};
ssize_t errcode {0};
const struct opts *opts {nullptr};
public:
const_iovec_view iovec() const;
size_t operator()();
void cancel();
request(const int &fd, const struct opts *const &);
~request() noexcept;
};
/// Read request control block
struct ircd::fs::aio::request::read
:request
{
read(const int &fd, const const_iovec_view &, const read_opts &);
};
/// Write request control block
struct ircd::fs::aio::request::write
:request
{
write(const int &fd, const const_iovec_view &, const write_opts &);
};
2018-08-19 07:58:43 +02:00
/// fdsync request control block
struct ircd::fs::aio::request::fdsync
:request
{
fdsync(const int &fd, const sync_opts &);
2018-08-19 07:58:43 +02:00
};
/// fsync request control block
struct ircd::fs::aio::request::fsync
:request
{
fsync(const int &fd, const sync_opts &);
2018-08-19 07:58:43 +02:00
};