2013-12-05 15:02:44 +01:00
|
|
|
/*
|
|
|
|
* \brief Block-session component for partition server
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-12-04
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-13 20:04:17 +01:00
|
|
|
* Copyright (C) 2013-2017 Genode Labs GmbH
|
2013-12-05 15:02:44 +01:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-12-05 15:02:44 +01:00
|
|
|
*/
|
|
|
|
|
2019-01-06 21:17:07 +01:00
|
|
|
#ifndef _PART_BLOCK__COMPONENT_H_
|
|
|
|
#define _PART_BLOCK__COMPONENT_H_
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
#include <base/exception.h>
|
2016-08-03 10:35:32 +02:00
|
|
|
#include <base/component.h>
|
|
|
|
#include <os/session_policy.h>
|
2013-12-05 15:02:44 +01:00
|
|
|
#include <root/component.h>
|
|
|
|
#include <block_session/rpc_object.h>
|
|
|
|
|
2014-09-20 22:12:26 +02:00
|
|
|
#include "gpt.h"
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
namespace Block {
|
|
|
|
|
|
|
|
using namespace Genode;
|
|
|
|
|
|
|
|
class Session_component;
|
|
|
|
class Root;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
class Block::Session_component : public Block::Session_rpc_object,
|
|
|
|
private List<Block::Session_component>::Element,
|
|
|
|
public Block_dispatcher
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
friend class List<Block::Session_component>;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Session_component(Session_component const &);
|
|
|
|
Session_component &operator = (Session_component const &);
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
Ram_dataspace_capability _rq_ds;
|
|
|
|
addr_t _rq_phys;
|
|
|
|
Partition *_partition;
|
|
|
|
Signal_handler<Session_component> _sink_ack;
|
|
|
|
Signal_handler<Session_component> _sink_submit;
|
|
|
|
bool _req_queue_full;
|
|
|
|
bool _ack_queue_full;
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Packet_descriptor _p_to_handle { };
|
2016-08-03 10:35:32 +02:00
|
|
|
unsigned _p_in_fly;
|
|
|
|
Block::Driver &_driver;
|
2017-07-31 19:53:34 +02:00
|
|
|
bool _writeable;
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Acknowledge a packet already handled
|
|
|
|
*/
|
|
|
|
inline void _ack_packet(Packet_descriptor &packet)
|
|
|
|
{
|
|
|
|
if (!tx_sink()->ready_to_ack())
|
2016-08-03 10:35:32 +02:00
|
|
|
error("Not ready to ack!");
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
tx_sink()->acknowledge_packet(packet);
|
|
|
|
_p_in_fly--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Range check packet request
|
|
|
|
*/
|
|
|
|
inline bool _range_check(Packet_descriptor &p) {
|
|
|
|
return p.block_number() + p.block_count() <= _partition->sectors; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a single request
|
|
|
|
*/
|
|
|
|
void _handle_packet(Packet_descriptor packet)
|
|
|
|
{
|
|
|
|
_p_to_handle = packet;
|
|
|
|
_p_to_handle.succeeded(false);
|
|
|
|
|
|
|
|
/* ignore invalid packets */
|
2016-05-31 18:53:57 +02:00
|
|
|
if (!packet.size() || !_range_check(_p_to_handle)) {
|
2013-12-05 15:02:44 +01:00
|
|
|
_ack_packet(_p_to_handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool write = _p_to_handle.operation() == Packet_descriptor::WRITE;
|
|
|
|
sector_t off = _p_to_handle.block_number() + _partition->lba;
|
|
|
|
size_t cnt = _p_to_handle.block_count();
|
2017-07-31 19:53:34 +02:00
|
|
|
|
|
|
|
if (write && !_writeable) {
|
|
|
|
_ack_packet(_p_to_handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
try {
|
2018-11-25 11:58:58 +01:00
|
|
|
_driver.io(write, off, cnt,
|
|
|
|
tx_sink()->packet_content(_p_to_handle),
|
|
|
|
*this, _p_to_handle);
|
2013-12-05 15:02:44 +01:00
|
|
|
} catch (Block::Session::Tx::Source::Packet_alloc_failed) {
|
2016-10-24 22:07:35 +02:00
|
|
|
if (!_req_queue_full) {
|
|
|
|
_req_queue_full = true;
|
|
|
|
Session_component::wait_queue().insert(this);
|
|
|
|
}
|
2018-11-25 11:58:58 +01:00
|
|
|
} catch (Genode::Packet_descriptor::Invalid_packet) {
|
|
|
|
Genode::error("dropping invalid Block packet");
|
|
|
|
_p_to_handle = Packet_descriptor();
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered when a packet was placed into the empty submit queue
|
|
|
|
*/
|
2016-08-03 10:35:32 +02:00
|
|
|
void _packet_avail()
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
|
|
|
_ack_queue_full = _p_in_fly >= tx_sink()->ack_slots_free();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* as long as more packets are available, and we're able to ack
|
|
|
|
* them, and the driver's request queue isn't full,
|
|
|
|
* direct the packet request to the driver backend
|
|
|
|
*/
|
|
|
|
for (; !_req_queue_full && tx_sink()->packet_avail() &&
|
|
|
|
!_ack_queue_full; _p_in_fly++,
|
|
|
|
_ack_queue_full = _p_in_fly >= tx_sink()->ack_slots_free())
|
|
|
|
_handle_packet(tx_sink()->get_packet());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered when an ack got removed from the full ack queue
|
|
|
|
*/
|
2016-08-03 10:35:32 +02:00
|
|
|
void _ready_to_ack() { _packet_avail(); }
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Session_component(Ram_dataspace_capability rq_ds,
|
|
|
|
Partition *partition,
|
2016-08-03 10:35:32 +02:00
|
|
|
Genode::Entrypoint &ep,
|
2017-01-13 20:04:17 +01:00
|
|
|
Genode::Region_map &rm,
|
2017-07-31 19:53:34 +02:00
|
|
|
Block::Driver &driver,
|
|
|
|
bool writeable)
|
2017-01-13 20:04:17 +01:00
|
|
|
: Session_rpc_object(rm, rq_ds, ep.rpc_ep()),
|
2013-12-05 15:02:44 +01:00
|
|
|
_rq_ds(rq_ds),
|
|
|
|
_rq_phys(Dataspace_client(_rq_ds).phys_addr()),
|
|
|
|
_partition(partition),
|
2016-08-03 10:35:32 +02:00
|
|
|
_sink_ack(ep, *this, &Session_component::_ready_to_ack),
|
|
|
|
_sink_submit(ep, *this, &Session_component::_packet_avail),
|
2013-12-05 15:02:44 +01:00
|
|
|
_req_queue_full(false),
|
|
|
|
_ack_queue_full(false),
|
2016-08-03 10:35:32 +02:00
|
|
|
_p_in_fly(0),
|
2017-07-31 19:53:34 +02:00
|
|
|
_driver(driver),
|
|
|
|
_writeable(writeable)
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
|
|
|
_tx.sigh_ready_to_ack(_sink_ack);
|
|
|
|
_tx.sigh_packet_avail(_sink_submit);
|
|
|
|
}
|
|
|
|
|
2016-10-24 22:07:35 +02:00
|
|
|
~Session_component()
|
|
|
|
{
|
|
|
|
_driver.remove_dispatcher(*this);
|
|
|
|
|
|
|
|
if (_req_queue_full)
|
|
|
|
wait_queue().remove(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ram_dataspace_capability const rq_ds() const { return _rq_ds; }
|
2013-12-05 15:02:44 +01:00
|
|
|
Partition *partition() { return _partition; }
|
|
|
|
|
|
|
|
void dispatch(Packet_descriptor &request, Packet_descriptor &reply)
|
|
|
|
{
|
2018-11-25 11:58:58 +01:00
|
|
|
request.succeeded(reply.succeeded());
|
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
if (request.operation() == Block::Packet_descriptor::READ) {
|
|
|
|
void *src =
|
2016-08-03 10:35:32 +02:00
|
|
|
_driver.session().tx()->packet_content(reply);
|
2013-12-05 15:02:44 +01:00
|
|
|
Genode::size_t sz =
|
2016-08-03 10:35:32 +02:00
|
|
|
request.block_count() * _driver.blk_size();
|
2018-11-25 11:58:58 +01:00
|
|
|
try { Genode::memcpy(tx_sink()->packet_content(request), src, sz); }
|
|
|
|
catch (Genode::Packet_descriptor::Invalid_packet) {
|
|
|
|
request.succeeded(false);
|
|
|
|
}
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
2018-11-25 11:58:58 +01:00
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
_ack_packet(request);
|
|
|
|
|
|
|
|
if (_ack_queue_full)
|
2016-08-03 10:35:32 +02:00
|
|
|
_packet_avail();
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static List<Session_component>& wait_queue()
|
|
|
|
{
|
|
|
|
static List<Session_component> l;
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wake_up()
|
|
|
|
{
|
2016-10-24 22:07:35 +02:00
|
|
|
for (; Session_component *c = wait_queue().first();)
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
|
|
|
wait_queue().remove(c);
|
|
|
|
c->_req_queue_full = false;
|
|
|
|
c->_handle_packet(c->_p_to_handle);
|
2016-08-03 10:35:32 +02:00
|
|
|
c->_packet_avail();
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************
|
|
|
|
** Block session interface **
|
|
|
|
*******************************/
|
|
|
|
|
|
|
|
void info(sector_t *blk_count, size_t *blk_size,
|
|
|
|
Operations *ops)
|
|
|
|
{
|
2017-07-31 19:53:34 +02:00
|
|
|
Operations driver_ops = _driver.ops();
|
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
*blk_count = _partition->sectors;
|
2016-08-03 10:35:32 +02:00
|
|
|
*blk_size = _driver.blk_size();
|
2017-07-31 19:53:34 +02:00
|
|
|
*ops = Operations();
|
|
|
|
|
|
|
|
typedef Block::Packet_descriptor::Opcode Opcode;
|
|
|
|
|
|
|
|
if (driver_ops.supported(Opcode::READ))
|
|
|
|
ops->set_operation(Opcode::READ);
|
|
|
|
if (_writeable && driver_ops.supported(Opcode::WRITE))
|
|
|
|
ops->set_operation(Opcode::WRITE);
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
void sync() { _driver.session().sync(); }
|
2013-12-05 15:02:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Root component, handling new session requests
|
|
|
|
*/
|
|
|
|
class Block::Root :
|
|
|
|
public Genode::Root_component<Block::Session_component>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
Genode::Env &_env;
|
2017-05-23 11:22:42 +02:00
|
|
|
Genode::Xml_node _config;
|
2016-08-03 10:35:32 +02:00
|
|
|
Block::Driver &_driver;
|
2014-09-20 22:12:26 +02:00
|
|
|
Block::Partition_table &_table;
|
2013-12-05 15:02:44 +01:00
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
protected:
|
|
|
|
|
2016-10-24 22:07:35 +02:00
|
|
|
void _destroy_session(Session_component *session) override
|
|
|
|
{
|
|
|
|
Ram_dataspace_capability rq_ds = session->rq_ds();
|
|
|
|
Genode::Root_component<Session_component>::_destroy_session(session);
|
|
|
|
_env.ram().free(rq_ds);
|
|
|
|
}
|
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
/**
|
|
|
|
* Always returns the singleton block-session component
|
|
|
|
*/
|
2016-10-24 22:07:35 +02:00
|
|
|
Session_component *_create_session(const char *args) override
|
2013-12-05 15:02:44 +01:00
|
|
|
{
|
|
|
|
long num = -1;
|
2017-07-31 19:53:34 +02:00
|
|
|
bool writeable = false;
|
2013-12-05 15:02:44 +01:00
|
|
|
|
2016-01-12 14:11:58 +01:00
|
|
|
Session_label const label = label_from_args(args);
|
2015-09-23 14:48:27 +02:00
|
|
|
char const *label_str = label.string();
|
2013-12-05 15:02:44 +01:00
|
|
|
try {
|
2017-05-23 11:22:42 +02:00
|
|
|
Session_policy policy(label, _config);
|
2013-12-05 15:02:44 +01:00
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
/* read partition attribute */
|
2019-01-21 10:48:39 +01:00
|
|
|
num = policy.attribute_value("partition", -1L);
|
2013-12-05 15:02:44 +01:00
|
|
|
|
2017-07-31 19:53:34 +02:00
|
|
|
/* sessions are not writeable by default */
|
|
|
|
writeable = policy.attribute_value("writeable", false);
|
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
} catch (Xml_node::Nonexistent_attribute) {
|
2016-08-03 10:35:32 +02:00
|
|
|
error("policy does not define partition number for for '",
|
|
|
|
label_str, "'");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-09-23 14:48:27 +02:00
|
|
|
} catch (Session_policy::No_policy_defined) {
|
2016-08-03 10:35:32 +02:00
|
|
|
error("rejecting session request, no matching policy for '",
|
|
|
|
label_str, "'");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-09-23 14:48:27 +02:00
|
|
|
}
|
2013-12-05 15:02:44 +01:00
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
if (!_table.partition(num)) {
|
2016-08-03 10:35:32 +02:00
|
|
|
error("Partition ", num, " unavailable for '", label_str, "'");
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-09-23 14:48:27 +02:00
|
|
|
}
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
size_t ram_quota =
|
|
|
|
Arg_string::find_arg(args, "ram_quota" ).ulong_value(0);
|
|
|
|
size_t tx_buf_size =
|
|
|
|
Arg_string::find_arg(args, "tx_buf_size").ulong_value(0);
|
|
|
|
|
2015-09-23 14:48:27 +02:00
|
|
|
if (!tx_buf_size)
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 22:03:22 +02:00
|
|
|
throw Service_denied();
|
2015-09-23 14:48:27 +02:00
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
/* delete ram quota by the memory needed for the session */
|
|
|
|
size_t session_size = max((size_t)4096,
|
|
|
|
sizeof(Session_component)
|
|
|
|
+ sizeof(Allocator_avl));
|
|
|
|
if (ram_quota < session_size)
|
2017-05-08 14:32:03 +02:00
|
|
|
throw Insufficient_ram_quota();
|
2013-12-05 15:02:44 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if donated ram quota suffices for both
|
|
|
|
* communication buffers. Also check both sizes separately
|
|
|
|
* to handle a possible overflow of the sum of both sizes.
|
|
|
|
*/
|
|
|
|
if (tx_buf_size > ram_quota - session_size) {
|
2016-08-03 10:35:32 +02:00
|
|
|
error("insufficient 'ram_quota', got ", ram_quota, ", need ",
|
|
|
|
tx_buf_size + session_size);
|
2017-05-08 14:32:03 +02:00
|
|
|
throw Insufficient_ram_quota();
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
|
2017-07-31 19:53:34 +02:00
|
|
|
if (writeable)
|
|
|
|
writeable = Arg_string::find_arg(args, "writeable").bool_value(true);
|
|
|
|
|
2013-12-05 15:02:44 +01:00
|
|
|
Ram_dataspace_capability ds_cap;
|
2016-08-03 10:35:32 +02:00
|
|
|
ds_cap = _env.ram().alloc(tx_buf_size);
|
2015-09-23 14:48:27 +02:00
|
|
|
Session_component *session = new (md_alloc())
|
2016-08-03 10:35:32 +02:00
|
|
|
Session_component(ds_cap, _table.partition(num),
|
2017-07-31 19:53:34 +02:00
|
|
|
_env.ep(), _env.rm(), _driver,
|
|
|
|
writeable);
|
2015-09-23 14:48:27 +02:00
|
|
|
|
2016-08-03 10:35:32 +02:00
|
|
|
log("session opened at partition ", num, " for '", label_str, "'");
|
2015-09-23 14:48:27 +02:00
|
|
|
return session;
|
2013-12-05 15:02:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-05-23 11:22:42 +02:00
|
|
|
Root(Genode::Env &env, Genode::Xml_node config, Genode::Heap &heap,
|
2016-08-03 10:35:32 +02:00
|
|
|
Block::Driver &driver, Block::Partition_table &table)
|
2017-05-23 11:22:42 +02:00
|
|
|
: Root_component(env.ep(), heap), _env(env), _config(config),
|
2016-08-03 10:35:32 +02:00
|
|
|
_driver(driver), _table(table) { }
|
2013-12-05 15:02:44 +01:00
|
|
|
};
|
|
|
|
|
2019-01-06 21:17:07 +01:00
|
|
|
#endif /* _PART_BLOCK__COMPONENT_H_ */
|