block_session: use types from block/request.h

Issue #3283
This commit is contained in:
Norman Feske 2019-04-09 17:43:30 +02:00 committed by Christian Helmuth
parent 7a45867841
commit 6c0dd9fe3b
2 changed files with 65 additions and 47 deletions

View File

@ -190,29 +190,17 @@ class Block::Request_stream : Genode::Noncopyable
Packet_descriptor const packet = tx_sink.peek_packet();
auto type = [] (Packet_descriptor::Opcode op)
{
switch (op) {
case Packet_descriptor::READ: return Operation::Type::READ;
case Packet_descriptor::WRITE: return Operation::Type::WRITE;
case Packet_descriptor::SYNC: return Operation::Type::SYNC;
case Packet_descriptor::TRIM: return Operation::Type::TRIM;
case Packet_descriptor::END: return Operation::Type::INVALID;
};
return Operation::Type::INVALID;
};
bool const packet_valid = tx_sink.packet_valid(packet)
&& (packet.offset() >= 0);
Operation operation { .type = type(packet.operation()),
Operation operation { .type = packet.operation_type(),
.block_number = packet.block_number(),
.count = packet.block_count() };
Request request { .operation = operation,
.success = false,
.offset = packet.offset(),
.tag = { packet.tag().value } };
.tag = packet.tag() };
Response const response = packet_valid
? fn(request)
@ -278,27 +266,11 @@ class Block::Request_stream : Genode::Noncopyable
}
typedef Block::Packet_descriptor Packet_descriptor;
Packet_descriptor
packet { (Genode::off_t)request.offset,
request.operation.count * _block_size };
Packet_descriptor::Payload
payload { .offset = request.offset,
.bytes = request.operation.count * _block_size };
auto opcode = [] (Operation::Type type)
{
switch (type) {
case Operation::Type::READ: return Packet_descriptor::READ;
case Operation::Type::WRITE: return Packet_descriptor::WRITE;
case Operation::Type::SYNC: return Packet_descriptor::END;
case Operation::Type::TRIM: return Packet_descriptor::TRIM;
case Operation::Type::INVALID: return Packet_descriptor::END;
};
return Packet_descriptor::END;
};
packet = Packet_descriptor(packet,
opcode(request.operation.type),
request.operation.block_number,
request.operation.count,
Session::Tag{request.tag.value});
Packet_descriptor packet(request.operation, payload, request.tag);
packet.succeeded(request.success);

View File

@ -17,11 +17,14 @@
#include <os/packet_stream.h>
#include <packet_stream_tx/packet_stream_tx.h>
#include <session/session.h>
#include <block/request.h>
namespace Block {
/**
/*
* Sector type for block session
*
* \deprecated use block_number_t instead
*/
typedef Genode::uint64_t sector_t;
@ -52,18 +55,36 @@ class Block::Packet_descriptor : public Genode::Packet_descriptor
*/
enum Alignment { PACKET_ALIGNMENT = 11 };
typedef Request::Tag Tag;
/**
* Client-defined value for correlating acknowledgements with requests
* Payload location within the packet stream
*/
struct Tag { unsigned long value; };
struct Payload
{
Genode::off_t offset;
Genode::size_t bytes;
};
private:
Opcode _op; /* requested operation */
Tag _tag; /* client-defined request identifier */
sector_t _block_number; /* requested block number */
Genode::size_t _block_count; /* number of blocks of operation */
bool _success; /* indicates success of operation */
Opcode _op; /* requested operation */
Tag _tag; /* client-defined request identifier */
block_number_t _block_number; /* requested block number */
block_count_t _block_count; /* number of blocks of operation */
bool _success; /* indicates success of operation */
static Opcode _opcode(Operation::Type type)
{
switch (type) {
case Operation::Type::READ: return READ;
case Operation::Type::WRITE: return WRITE;
case Operation::Type::SYNC: return SYNC;
case Operation::Type::TRIM: return TRIM;
case Operation::Type::INVALID: return END;
};
return END;
}
public:
@ -80,7 +101,8 @@ class Block::Packet_descriptor : public Genode::Packet_descriptor
* Constructor
*/
Packet_descriptor(Packet_descriptor p, Opcode op,
sector_t block_number, Genode::size_t block_count = 1,
block_number_t block_number,
block_count_t block_count = 1,
Tag tag = { ~0U })
:
Genode::Packet_descriptor(p.offset(), p.size()),
@ -88,13 +110,37 @@ class Block::Packet_descriptor : public Genode::Packet_descriptor
_block_count(block_count), _success(false)
{ }
/**
* Constructor
*/
Packet_descriptor(Operation operation, Payload payload, Tag tag)
:
Genode::Packet_descriptor(payload.offset, payload.bytes),
_op(_opcode(operation.type)), _tag(tag),
_block_number(operation.block_number),
_block_count(operation.count),
_success(false)
{ }
Opcode operation() const { return _op; }
sector_t block_number() const { return _block_number; }
Genode::size_t block_count() const { return _block_count; }
block_number_t block_number() const { return _block_number; }
block_count_t block_count() const { return _block_count; }
bool succeeded() const { return _success; }
Tag tag() const { return _tag; }
void succeeded(bool b) { _success = b; }
Operation::Type operation_type() const
{
switch (_op) {
case READ: return Operation::Type::READ;
case WRITE: return Operation::Type::WRITE;
case SYNC: return Operation::Type::SYNC;
case TRIM: return Operation::Type::TRIM;
case END: return Operation::Type::INVALID;
};
return Operation::Type::INVALID;
}
};
@ -121,12 +167,12 @@ struct Block::Session : public Genode::Session
typedef Packet_stream_tx::Channel<Tx_policy> Tx;
typedef Packet_descriptor::Tag Tag;
typedef Request::Tag Tag;
struct Info
{
Genode::size_t block_size; /* size of one block in bytes */
sector_t block_count; /* number of blocks */
block_number_t block_count; /* number of blocks */
Genode::size_t align_log2; /* packet alignment within payload buffer */
bool writeable;
};