block_session: turn 'Connection' into template

As a preparatory step for introducing the new block-client API, we have
to turn the 'Block::Connection' into a class template. The template
argument will be used to tie an application-defined job type to the
block connection.

Issue #3283
This commit is contained in:
Norman Feske 2019-04-10 20:11:18 +02:00 committed by Christian Helmuth
parent 6c0dd9fe3b
commit e5f27b44b5
22 changed files with 61 additions and 59 deletions

View File

@ -30,7 +30,7 @@ class Backend
private:
Genode::Allocator_avl _alloc { &Rump::env().heap() };
Block::Connection _session { Rump::env().env(), &_alloc };
Block::Connection<> _session { Rump::env().env(), &_alloc };
Block::Session::Info _info { _session.info() };
Genode::Lock _session_lock;

View File

@ -34,7 +34,7 @@ struct Gpt::Writer
using sector_t = Block::sector_t;
Block::Connection &_block;
Block::Connection<> &_block;
Block::Session::Info const _info { _block.info() };
size_t const _block_size { _info.block_size };
@ -652,7 +652,7 @@ struct Gpt::Writer
*
* \throw Io_error
*/
Writer(Block::Connection &block, Genode::Xml_node config) : _block(block)
Writer(Block::Connection<> &block, Genode::Xml_node config) : _block(block)
{
if (!_info.writeable) {
Genode::error("cannot write to Block session");
@ -736,7 +736,7 @@ struct Main
enum { TX_BUF_SIZE = 128u << 10, };
Genode::Allocator_avl _block_alloc { &_heap };
Block::Connection _block { _env, &_block_alloc, TX_BUF_SIZE };
Block::Connection<> _block { _env, &_block_alloc, TX_BUF_SIZE };
Genode::Constructible<Gpt::Writer> _writer { };

View File

@ -113,8 +113,8 @@ struct Util::Block_io
using Packet_descriptor = Block::Packet_descriptor;
Block::Connection &_block;
Packet_descriptor _p;
Block::Connection<> &_block;
Packet_descriptor _p;
/**
* Constructor
@ -128,7 +128,7 @@ struct Util::Block_io
*
* \throw Io_error
*/
Block_io(Block::Connection &block, size_t block_size,
Block_io(Block::Connection<> &block, size_t block_size,
sector_t lba, size_t count,
bool write = false, void const *data = nullptr, size_t len = 0)
:

View File

@ -110,7 +110,7 @@ struct Test::Main
Heap heap(_env.ram(), _env.rm());
Allocator_avl packet_alloc(&heap);
Block::Connection block(_env, &packet_alloc, 128*1024, label.string());
Block::Connection<> block(_env, &packet_alloc, 128*1024, label.string());
});
log("all expected devices present and accessible");

View File

@ -56,12 +56,12 @@ extern "C" {
void block_init(Genode::Env &env, Genode::Allocator &alloc) {
_platform.construct(env, alloc); }
struct Drive : private Block::Connection
struct Drive : private Block::Connection<>
{
Info const info = Block::Connection::info();
Info const info = Block::Connection<>::info();
using Block::Connection::tx;
using Block::Connection::alloc_packet;
using Block::Connection<>::tx;
using Block::Connection<>::alloc_packet;
void sync()
{
@ -75,7 +75,7 @@ extern "C" {
}
Drive(Platform &platform, char const *label)
: Block::Connection(platform.env, &platform.tx_alloc, 128*1024, label)
: Block::Connection<>(platform.env, &platform.tx_alloc, 128*1024, label)
{ }
};
}

View File

@ -18,8 +18,10 @@
#include <base/connection.h>
#include <base/allocator.h>
namespace Block { struct Connection; }
namespace Block { template <typename> struct Connection; }
template <typename JOB = void>
struct Block::Connection : Genode::Connection<Session>, Session_client
{
/**

View File

@ -36,7 +36,7 @@ struct Test::Ping_pong : Test_base
/* block session infos */
enum { TX_BUF_SIZE = 4 * 1024 * 1024, };
Genode::Allocator_avl _block_alloc { &_alloc };
Genode::Constructible<Block::Connection> _block { };
Genode::Constructible<Block::Connection<>> _block { };
Genode::Constructible<Timer::Connection> _timer { };

View File

@ -89,7 +89,7 @@ struct Test::Random : Test_base
/* block session infos */
enum { TX_BUF_SIZE = 4 * 1024 * 1024, };
Genode::Allocator_avl _block_alloc { &_alloc };
Genode::Constructible<Block::Connection> _block { };
Genode::Constructible<Block::Connection<>> _block { };
Genode::Constructible<Timer::Connection> _timer { };

View File

@ -51,7 +51,7 @@ struct Test::Replay : Test_base
enum { TX_BUF_SIZE = 4 * 1024 * 1024, };
Genode::Allocator_avl _block_alloc { &alloc };
Genode::Constructible<Block::Connection> _block { };
Genode::Constructible<Block::Connection<>> _block { };
Genode::Signal_handler<Replay> _ack_sigh {
env.ep(), *this, &Replay::_handle_ack };

View File

@ -44,7 +44,7 @@ struct Test::Sequential : Test_base
/* block session infos */
enum { TX_BUF_SIZE = 4 * 1024 * 1024, };
Genode::Allocator_avl _block_alloc { &_alloc };
Genode::Constructible<Block::Connection> _block { };
Genode::Constructible<Block::Connection<>> _block { };
Genode::Constructible<Timer::Connection> _timer { };

View File

@ -41,7 +41,7 @@ class Vfs::Block_file_system : public Single_file_system
Genode::Allocator_avl _tx_block_alloc { &_env.alloc() };
Block::Connection _block {
Block::Connection<> _block {
_env.env(), &_tx_block_alloc, 128*1024, _label.string() };
Block::Session::Info const _info { _block.info() };
@ -70,7 +70,7 @@ class Vfs::Block_file_system : public Single_file_system
char *_block_buffer;
unsigned &_block_buffer_count;
Genode::Allocator_avl &_tx_block_alloc;
Block::Connection &_block;
Block::Connection<> &_block;
Genode::size_t const _block_size;
Block::sector_t const _block_count;
Block::Session::Tx::Source *_tx_source;
@ -152,7 +152,7 @@ class Vfs::Block_file_system : public Single_file_system
char *block_buffer,
unsigned &block_buffer_count,
Genode::Allocator_avl &tx_block_alloc,
Block::Connection &block,
Block::Connection<> &block,
Genode::size_t block_size,
Block::sector_t block_count,
Block::Session::Tx::Source *tx_source,

View File

@ -118,7 +118,7 @@ class Driver : public Block::Driver
Genode::Tslab<Request, SLAB_SZ> _r_slab; /* slab for requests */
Genode::List<Request> _r_list; /* list of requests */
Genode::Packet_allocator _alloc; /* packet allocator */
Block::Connection _blk; /* backend device */
Block::Connection<> _blk; /* backend device */
Block::Session::Info const _info; /* block-device info */
Chunk_level_0 _cache; /* chunk hierarchy */
Genode::Io_signal_handler<Driver> _source_ack;

View File

@ -50,7 +50,7 @@ class Iso::Sector {
public:
Sector(Block::Connection &block,
Sector(Block::Connection<> &block,
unsigned long blk_nr, unsigned long count)
: _source(*block.tx())
{
@ -327,7 +327,7 @@ class Volume_descriptor : public Iso::Iso_base
* Locate the root-directory record in the primary volume descriptor
*/
static Directory_record *locate_root(Genode::Allocator &alloc,
Block::Connection &block)
Block::Connection<> &block)
{
/* volume descriptors in ISO9660 start at block 16 */
for (unsigned long blk_nr = 16;; blk_nr++) {
@ -347,7 +347,7 @@ static Directory_record *locate_root(Genode::Allocator &alloc,
* Return root directory record
*/
static Directory_record *root_dir(Genode::Allocator &alloc,
Block::Connection &block)
Block::Connection<> &block)
{
Directory_record *root = locate_root(alloc, block);
@ -364,8 +364,8 @@ static Directory_record *root_dir(Genode::Allocator &alloc,
static Directory_record *_root_dir;
Iso::File_info *Iso::file_info(Genode::Allocator &alloc, Block::Connection &block,
char const *path)
Iso::File_info *Iso::file_info(Genode::Allocator &alloc,
Block::Connection<> &block, char const *path)
{
char level[PATH_LENGTH];
@ -441,7 +441,7 @@ Iso::File_info *Iso::file_info(Genode::Allocator &alloc, Block::Connection &bloc
}
unsigned long Iso::read_file(Block::Connection &block, File_info *info,
unsigned long Iso::read_file(Block::Connection<> &block, File_info *info,
off_t file_offset, uint32_t length, void *buf_ptr)
{
uint8_t *buf = (uint8_t *)buf_ptr;

View File

@ -69,7 +69,7 @@ namespace Iso {
*
* \return Pointer to File_info class
*/
File_info *file_info(Genode::Allocator &alloc, Block::Connection &block, char const *path);
File_info *file_info(Genode::Allocator &alloc, Block::Connection<> &block, char const *path);
/**
* Read data from ISO
@ -84,6 +84,6 @@ namespace Iso {
*
* \return Number of bytes read
*/
unsigned long read_file(Block::Connection &block, File_info *info, Genode::off_t file_offset,
unsigned long read_file(Block::Connection<> &block, File_info *info, Genode::off_t file_offset,
Genode::uint32_t length, void *buf);
} /* namespace Iso */

View File

@ -70,7 +70,7 @@ class Iso::File : public File_base
public:
File(Genode::Env &env, Genode::Allocator &alloc,
Block::Connection &block, char const *path)
Block::Connection<> &block, char const *path)
:
File_base(path), _alloc(alloc),
_info(Iso::file_info(_alloc, block, path)),
@ -112,7 +112,7 @@ class Iso::Rom_component : public Genode::Rpc_object<Rom_session>
void sigh(Signal_context_capability) override { }
Rom_component(Genode::Env &env, Genode::Allocator &alloc,
File_cache &cache, Block::Connection &block,
File_cache &cache, Block::Connection<> &block,
char const *path)
{
if ((_file = _lookup(cache, path))) {
@ -135,8 +135,8 @@ class Iso::Root : public Iso::Root_component
Genode::Env &_env;
Genode::Allocator &_alloc;
Allocator_avl _block_alloc { &_alloc };
Block::Connection _block { _env, &_block_alloc };
Allocator_avl _block_alloc { &_alloc };
Block::Connection<> _block { _env, &_block_alloc };
/*
* Entries in the cache are never freed, even if the ROM session

View File

@ -78,7 +78,7 @@ class Block::Driver
Genode::Tslab<Request, BLK_SZ> _r_slab;
Genode::List<Request> _r_list { };
Genode::Allocator_avl _block_alloc;
Block::Connection _session;
Block::Connection<> _session;
Block::Session::Info const _info { _session.info() };
Genode::Signal_handler<Driver> _source_ack;
Genode::Signal_handler<Driver> _source_submit;

View File

@ -82,7 +82,7 @@ class Genode::Block_driver
Name const _name;
unsigned const _irq;
Signal_handler<Device> _irq_handler;
Block::Connection _session;
Block::Connection<> _session;
Id_space<Device>::Element _id_space_elem;
Block::Session::Info const _info { _session.info() };
@ -103,13 +103,13 @@ class Genode::Block_driver
void start_irq_handling();
Request_cache &cache() { return _cache; }
Block::Connection &session() { return _session; }
size_t block_size() const { return _info.block_size; }
size_t block_count() const { return _info.block_count; }
bool writeable() const { return _info.writeable; }
Name const &name() const { return _name; }
unsigned irq() const { return _irq; }
Request_cache &cache() { return _cache; }
Block::Connection<> &session() { return _session; }
size_t block_size() const { return _info.block_size; }
size_t block_count() const { return _info.block_count; }
bool writeable() const { return _info.writeable; }
Name const &name() const { return _name; }
unsigned irq() const { return _irq; }
};
void *_buf = nullptr;

View File

@ -35,11 +35,11 @@ class Throughput
typedef Genode::size_t size_t;
Env & _env;
Heap _heap { _env.ram(), _env.rm() };
Allocator_avl _alloc { &_heap };
Block::Connection _session { _env, &_alloc, TX_BUFFER };
Timer::Connection _timer { _env };
Env & _env;
Heap _heap { _env.ram(), _env.rm() };
Allocator_avl _alloc { &_heap };
Block::Connection<> _session { _env, &_alloc, TX_BUFFER };
Timer::Connection _timer { _env };
Signal_handler<Throughput> _disp_ack { _env.ep(), *this,
&Throughput::_ack };

View File

@ -65,9 +65,9 @@ class Test : Genode::Interface
protected:
Genode::Entrypoint &_ep;
Genode::Allocator_avl _alloc;
Block::Connection _session;
Genode::Entrypoint &_ep;
Genode::Allocator_avl _alloc;
Block::Connection<> _session;
Genode::Io_signal_handler<Test> _disp_ack;
Genode::Io_signal_handler<Test> _disp_submit;
@ -401,8 +401,8 @@ void Component::construct(Genode::Env &env)
* whether closing and opening again works for the driver
*/
{
Allocator_avl alloc(&heap);
Block::Connection blk(env, &alloc);
Allocator_avl alloc(&heap);
Block::Connection<> blk(env, &alloc);
Block::Session::Info const info { blk.info() };

View File

@ -39,7 +39,7 @@ struct Main
File_name file_name { config.xml().attribute_value("file", File_name()) };
Heap heap { env.ram(), env.rm() };
Allocator_avl block_alloc { &heap };
Block::Connection block { env, &block_alloc };
Block::Connection<> block { env, &block_alloc };
Attached_rom_dataspace rom { env, file_name.string() };
Main(Env &env) : env(env)

View File

@ -175,9 +175,9 @@ bool Seoul::Disk::receive(MessageDisk &msg)
new (disk_heap()) Genode::Allocator_avl(disk_heap());
disk.blk_con =
new (disk_heap()) Block::Connection(_env, block_alloc,
4*512*1024,
label.string());
new (disk_heap()) Block::Connection<>(_env, block_alloc,
4*512*1024,
label.string());
disk.signal =
new (disk_heap()) Seoul::Disk_signal(_env.ep(), *this,
*disk.blk_con, msg.disknr);

View File

@ -53,7 +53,7 @@ class Seoul::Disk_signal
Genode::Signal_handler<Disk_signal> const sigh;
Disk_signal(Genode::Entrypoint &ep, Disk &obj,
Block::Connection &block, unsigned disk_nr)
Block::Connection<> &block, unsigned disk_nr)
:
_obj(obj), _id(disk_nr),
sigh(ep, *this, &Disk_signal::_signal)
@ -105,7 +105,7 @@ class Seoul::Disk : public StaticReceiver<Seoul::Disk>
/* block session used by disk models of VMM */
enum { MAX_DISKS = 4 };
struct disk_session {
Block::Connection *blk_con;
Block::Connection<> *blk_con;
Block::Session::Info info;
Disk_signal *signal;
} _diskcon[MAX_DISKS] { };