Genode fixes

This commit is contained in:
Ehmry - 2018-09-07 16:38:34 +02:00
parent 02c6fddad6
commit 167d45f1e9
26 changed files with 66 additions and 560 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
nimcache
ipldrepl
/dagfs_repl
/genode/dagfs_genode/dagfs_fs
/genode/dagfs_genode/dagfs_fs_store
/genode/dagfs_genode/dagfs_rom

View File

@ -11,8 +11,11 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _DAGFS_CLIENT_H_
#define _DAGFS_CLIENT_H_
/* Genode includes */
#include <dagfs_session/connection.h>
#include "../../include/dagfs_session/connection.h"
#include <base/heap.h>
struct DagfsClientBase
@ -26,3 +29,5 @@ struct DagfsClientBase
conn(*env, tx_packet_alloc, label, tx_buf_size)
{ }
};
#endif /* _DAGFS_CLIENT_H_ */

View File

@ -3,12 +3,12 @@ when not defined(genode):
import cbor, genode, std/tables, std/strutils
import dagfs, dagfs/stores, dagfs/genode/dagfs_session
import dagfs, dagfs/stores, ./dagfs_session
const
currentPath = currentSourcePath.rsplit("/", 1)[0]
dagfsClientH = currentPath & "/dagfs_client.h"
{.passC: "-I" & currentPath & "/../../../genode/include".}
{.passC: "-I" & currentPath & "/../../include".}
type
DagfsClientBase {.importcpp, header: dagfsClientH.} = object
@ -44,7 +44,7 @@ proc releasePacket(cpp: DagfsClientCpp; pkt: DagfsPacket) {.
type
DagfsClient* = ref DagfsClientObj
DagfsClientObj = object of DagfsStoreObj
## IPLD session client
## Dagfs session client
cpp: DagfsClientCpp
proc icClose(s: DagfsStore) =

View File

@ -1,5 +1,5 @@
/*
* \brief IPLD C++ session component
* \brief Dagfs C++ session component
* \author Emery Hemingway
* \date 2017-11-07
*/
@ -11,10 +11,10 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__NIM__IPLDSERVER_H_
#define _INCLUDE__NIM__IPLDSERVER_H_
#ifndef _INCLUDE__NIM__DAGFS_SERVER_H_
#define _INCLUDE__NIM__DAGFS_SERVER_H_
#include <ipld_session/rpc_object.h>
#include <dagfs_session/rpc_object.h>
#include <base/heap.h>
#include <base/attached_ram_dataspace.h>
@ -28,8 +28,8 @@ struct Communication_buffer
: _tx_ds(pd, rm, tx_buf_size) { }
};
struct IpldSessionComponentBase : Communication_buffer,
Ipld::Session_rpc_object
struct DagfsSessionComponentBase : Communication_buffer,
Dagfs::Session_rpc_object
{
static Genode::size_t tx_buf_size(char const *args)
{
@ -40,7 +40,7 @@ struct IpldSessionComponentBase : Communication_buffer,
return buf_size;
}
IpldSessionComponentBase(Genode::Env *env, char const *args)
DagfsSessionComponentBase(Genode::Env *env, char const *args)
:
Communication_buffer(env->pd(), env->rm(), tx_buf_size(args)),
Session_rpc_object(env->rm(), env->ep().rpc_ep(), _tx_ds.cap())
@ -53,4 +53,4 @@ struct IpldSessionComponentBase : Communication_buffer,
}
};
#endif /* _INCLUDE__NIM__IPLDSERVER_H_ */
#endif /* _INCLUDE__NIM__DAGFS_SERVER_H_ */

View File

@ -1,5 +1,5 @@
#
# \brief IPLD server factory
# \brief Dagfs server factory
# \author Emery Hemingway
# \date 2017-11-11
#
@ -13,24 +13,26 @@
import std/strtabs, std/tables, std/xmltree, std/strutils
import cbor, genode, genode/signals, genode/servers, ipld, ipld/store, ipldsession
import cbor, genode, genode/signals, genode/servers, genode/parents,
dagfs, dagfs/stores, ./dagfs_session
const
currentPath = currentSourcePath.rsplit("/", 1)[0]
ipldserverH = currentPath & "/ipldserver.h"
dagfsserverH = currentPath & "/dagfs_server.h"
{.passC: "-I" & currentPath & "/../../include".}
type
IpldSessionComponentBase {.importcpp, header: ipldserverH.} = object
SessionCpp = Constructible[IpldSessionComponentBase]
DagfsSessionComponentBase {.importcpp, header: dagfsserverH.} = object
SessionCpp = Constructible[DagfsSessionComponentBase]
Session = ref object
cpp: SessionCpp
sig: SignalHandler
store: IpldStore
id: SessionId
store: DagfsStore
id: ServerId
label: string
proc processPacket(session: Session; pkt: var IpldPacket) =
proc packetContent(cpp: SessionCpp; pkt: IpldPacket): pointer {.
proc processPacket(session: Session; pkt: var DagfsPacket) =
proc packetContent(cpp: SessionCpp; pkt: DagfsPacket): pointer {.
importcpp: "#->sink().packet_content(@)".}
let cid = pkt.cid
case pkt.operation
@ -40,7 +42,7 @@ proc processPacket(session: Session; pkt: var IpldPacket) =
pktBuf = session.cpp.packetContent pkt
heapBuf = newString pkt.len
copyMem(heapBuf[0].addr, pktBuf, heapBuf.len)
let putCid = session.store.put(heapBuf, cid.hash)
let putCid = session.store.put(heapBuf)
assert(putCid.isValid, "server packet returned invalid CID from put")
pkt.setCid putCid
except:
@ -63,7 +65,7 @@ proc processPacket(session: Session; pkt: var IpldPacket) =
echo "invalid packet operation"
pkt.setError ERROR
proc newSession(env: GenodeEnv; store: IpldStore; id: SessionId; label, args: string): Session =
proc newSession(env: GenodeEnv; store: DagfsStore; id: ServerId; label, args: string): Session =
## Create a new session and packet handling procedure
let session = new Session
assert(not session.isNil)
@ -78,11 +80,11 @@ proc newSession(env: GenodeEnv; store: IpldStore; id: SessionId; label, args: st
proc readyToAck(cpp: SessionCpp): bool {.
importcpp: "#->sink().ready_to_ack()".}
while session.cpp.packetAvail and session.cpp.readyToAck:
proc getPacket(cpp: SessionCpp): IpldPacket {.
proc getPacket(cpp: SessionCpp): DagfsPacket {.
importcpp: "#->sink().get_packet()".}
var pkt = session.cpp.getPacket()
session.processPacket pkt
proc acknowledgePacket(cpp: SessionCpp; pkt: IpldPacket) {.
proc acknowledgePacket(cpp: SessionCpp; pkt: DagfsPacket) {.
importcpp: "#->sink().acknowledge_packet(@)".}
session.cpp.acknowledgePacket(pkt)
@ -91,9 +93,9 @@ proc newSession(env: GenodeEnv; store: IpldStore; id: SessionId; label, args: st
session.cpp.packetHandler(session.sig.cap)
result = session
proc manage(ep: Entrypoint; s: Session): IpldSessionCapability =
proc manage(ep: Entrypoint; s: Session): DagfsSessionCapability =
## Manage a session from the default entrypoint.
proc manage(ep: Entrypoint; cpp: SessionCpp): IpldSessionCapability {.
proc manage(ep: Entrypoint; cpp: SessionCpp): DagfsSessionCapability {.
importcpp: "#.manage(*#)".}
result = ep.manage(s.cpp)
GC_ref s
@ -108,35 +110,35 @@ proc dissolve(ep: Entrypoint; s: Session) =
GC_unref s
type
IpldServer* = ref object
DagfsServer* = ref object
env: GenodeEnv
store*: IpldStore
sessions*: Table[SessionId, Session]
store*: DagfsStore
sessions*: Table[ServerId, Session]
proc newIpldServer*(env: GenodeEnv; store: IpldStore): IpldServer =
IpldServer(
proc newDagfsServer*(env: GenodeEnv; store: DagfsStore): DagfsServer =
DagfsServer(
env: env, store: store,
sessions: initTable[SessionId, Session]())
sessions: initTable[ServerId, Session]())
proc create*(server: IpldServer; id: SessionId; label, args: string) =
proc create*(server: DagfsServer; id: ServerId; label, args: string) =
if not server.sessions.contains id:
try:
let
session = newSession(server.env, server.store, id, label, args)
cap = server.env.ep.manage(session)
server.sessions[id] = session
proc deliverSession(env: GenodeEnv; id: SessionId; cap: IpldSessionCapability) {.
proc deliverSession(env: GenodeEnv; id: ServerId; cap: DagfsSessionCapability) {.
importcpp: "#->parent().deliver_session_cap(Genode::Parent::Server::Id{#}, #)".}
server.env.deliverSession(id, cap)
echo "session opened for ", label
except:
echo "failed to create session for '", label, "', ", getCurrentExceptionMsg()
server.env.sessionResponseDeny id
server.env.parent.sessionResponseDeny id
proc close*(server: IpldServer; id: SessionId) =
## Close a session at the IPLD server.
proc close*(server: DagfsServer; id: ServerId) =
## Close a session at the Dagfs server.
if server.sessions.contains id:
let session = server.sessions[id]
server.env.ep.dissolve(session)
server.sessions.del id
server.env.sessionResponseClose id
server.env.parent.sessionResponseClose id

View File

@ -1,3 +1,16 @@
#
# \brief Dagfs session definitions
# \author Emery Hemingway
# \date 2017-11-11
#
#
# Copyright (C) 2017 Genode Labs GmbH
#
# This file is part of the Genode OS framework, which is distributed
# under the terms of the GNU Affero General Public License version 3.
#
import dagfs
const MaxPacketSize* = 1 shl 18;

View File

@ -1,47 +0,0 @@
#
# \brief IPLD session definitions
# \author Emery Hemingway
# \date 2017-11-11
#
#
# Copyright (C) 2017 Genode Labs GmbH
#
# This file is part of the Genode OS framework, which is distributed
# under the terms of the GNU Affero General Public License version 3.
#
import ipld
const MaxPacketSize* = 1 shl 18;
type
IpldSessionCapability* {.final, pure,
importcpp: "Ipld::Session_capability",
header: "<ipld_session/capability.h>".} = object
IpldPacket* {.
importcpp: "Ipld::Packet",
header: "<ipld_session/ipld_session.h>".} = object
IpldOpcode* {.importcpp: "Ipld::Packet::Opcode".} = enum
PUT, GET, INVALID
IpldError* {.importcpp: "Ipld::Packet::Error".} = enum
OK, MISSING, OVERSIZE, FULL, ERROR
proc size*(pkt: IpldPacket): csize {.importcpp.}
## Physical packet size.
proc cidStr(p: IpldPacket): cstring {.importcpp: "#.cid().string()".}
proc cid*(p: IpldPacket): Cid = parseCid $p.cidStr
proc setCid*(p: var IpldPacket; cid: cstring) {.importcpp: "#.cid(@)".}
proc setCid*(p: var IpldPacket; cid: Cid) = p.setCid(cid.toHex())
proc operation*(pkt: IpldPacket): IpldOpcode {.importcpp.}
proc len*(pkt: IpldPacket): csize {.importcpp: "length".}
## Logical packet length.
proc setLen*(pkt: var IpldPacket; len: int) {.importcpp: "length".}
## Set logical packet length.
proc error*(pkt: IpldPacket): IpldError {.importcpp.}
proc setError*(pkt: var IpldPacket; err: IpldError) {.importcpp: "error".}

View File

@ -1,28 +0,0 @@
/*
* \brief C++ base of Dagfs client
* \author Emery Hemingway
* \date 2017-11-08
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* Genode includes */
#include <dagfs_session/connection.h>
#include <base/heap.h>
struct DagfsClientBase
{
Genode::Heap heap;
Genode::Allocator_avl tx_packet_alloc { &heap };
Dagfs::Connection conn;
DagfsClientBase(Genode::Env *env, char const *label, Genode::size_t tx_buf_size)
: heap(env->pd(), env->rm()),
conn(*env, tx_packet_alloc, label, tx_buf_size)
{ }
};

View File

@ -1,136 +0,0 @@
when not defined(genode):
{.error: "Genode only Dagfs client".}
import cbor, genode, std/tables, std/strutils
import dagfs, dagfs/stores, ./dagfs_session
const
currentPath = currentSourcePath.rsplit("/", 1)[0]
dagfsClientH = currentPath & "/dagfs_client.h"
{.passC: "-I" & currentPath & "/../../../genode/include".}
type
DagfsClientBase {.importcpp, header: dagfsClientH.} = object
DagfsClientCpp = Constructible[DagfsClientBase]
proc sigh_ack_avail(cpp: DagfsClientCpp; sig: SignalContextCapability) {.
importcpp: "#->conn.channel().sigh_ack_avail(@)", tags: [RpcEffect].}
proc readyToSubmit(cpp: DagfsClientCpp): bool {.
importcpp: "#->conn.source().ready_to_submit()".}
proc readyToAck(cpp: DagfsClientCpp): bool {.
importcpp: "#->conn.source().ready_to_ack()".}
proc ackAvail(cpp: DagfsClientCpp): bool {.
importcpp: "#->conn.source().ack_avail()".}
proc allocPacket(cpp: DagfsClientCpp; size = MaxPacketSize): DagfsPacket {.
importcpp: "#->conn.source().alloc_packet(@)".}
proc packetContent(cpp: DagfsClientCpp; pkt: DagfsPacket): pointer {.
importcpp: "#->conn.source().packet_content(@)".}
proc submitPacket(cpp: DagfsClientCpp; pkt: DagfsPacket; cid: cstring; op: DagfsOpcode) {.
importcpp: "#->conn.source().submit_packet(Dagfs::Packet(#, (char const *)#, #))".}
proc getAckedPacket(cpp: DagfsClientCpp): DagfsPacket {.
importcpp: "#->conn.source().get_acked_packet()".}
proc releasePacket(cpp: DagfsClientCpp; pkt: DagfsPacket) {.
importcpp: "#->conn.source().release_packet(@)".}
type
DagfsClient* = ref DagfsClientObj
DagfsClientObj = object of DagfsStoreObj
## Dagfs session client
cpp: DagfsClientCpp
proc icClose(s: DagfsStore) =
var ic = DagfsClient(s)
destruct ic.cpp
proc icPut(s: DagfsStore; blk: string): Cid =
## Put block to Dagfs server, blocks for two packet round-trip.
let ic = DagfsClient(s)
var
blk = blk
pktCid = dagHash blk
if pktCid == zeroBlock:
return pktCid
assert(ic.cpp.readyToSubmit, "Dagfs client packet queue congested")
var pkt = ic.cpp.allocPacket(blk.len)
let pktBuf = ic.cpp.packetContent pkt
defer: ic.cpp.releasePacket pkt
assert(not pktBuf.isNil, "allocated packet has nil content")
assert(pkt.size >= blk.len)
pkt.setLen blk.len
copyMem(pktBuf, blk[0].addr, blk.len)
assert(ic.cpp.readyToSubmit, "Dagfs client packet queue congested")
ic.cpp.submitPacket(pkt, pktCid.toHex, PUT)
let ack = ic.cpp.getAckedPacket()
doAssert(ack.error == OK)
result = ack.cid()
assert(result.isValid, "server returned a packet with and invalid CID")
proc icGetBuffer(s: DagfsStore; cid: Cid; buf: pointer; len: Natural): int =
## Get from Dagfs server, blocks for packet round-trip.
let ic = DagfsClient(s)
assert(ic.cpp.readyToSubmit, "Dagfs client packet queue congested")
let pkt = ic.cpp.allocPacket len
ic.cpp.submitPacket(pkt, cid.toHex, GET)
let ack = ic.cpp.getAckedPacket
doAssert(ack.cid == cid)
if ack.error == OK:
let pktBuf = ic.cpp.packetContent ack
assert(not pktBuf.isNil, "ack packet has nil content")
assert(ack.len <= len)
assert(ack.len > 0)
result = ack.len
copyMem(buf, pktBuf, result)
if pkt.size > 0:
ic.cpp.releasePacket pkt
# free the original packet that was allocated
case ack.error:
of OK: discard
of MISSING:
raise cid.newMissingObject
else:
raise newException(CatchableError, "Dagfs packet error " & $ack.error)
proc icGet(s: DagfsStore; cid: Cid; result: var string) =
## Get from Dagfs server, blocks for packet round-trip.
let ic = DagfsClient(s)
assert(ic.cpp.readyToSubmit, "Dagfs client packet queue congested")
let pkt = ic.cpp.allocPacket()
defer: ic.cpp.releasePacket pkt
ic.cpp.submitPacket(pkt, cid.toHex, GET)
let ack = ic.cpp.getAckedPacket()
doAssert(ack.cid == cid)
case ack.error:
of OK:
let ackBuf = ic.cpp.packetContent ack
assert(not ackBuf.isNil)
assert(ack.len > 0)
result.setLen ack.len
copyMem(result[0].addr, ackBuf, result.len)
assert(cid.verify(result), "Dagfs client packet failed verification")
of MISSING:
raise cid.newMissingObject
else:
raise newException(CatchableError, "Dagfs packet error " & $ack.error)
const
DefaultDagfsBufferSize* = 1 shl 20
proc newDagfsClient*(env: GenodeEnv; label = ""; bufferSize = DefaultDagfsBufferSize): DagfsClient =
## Blocks retrieved by `get` are not verified.
proc construct(cpp: DagfsClientCpp; env: GenodeEnv; label: cstring; txBufSize: int) {.
importcpp.}
new result
construct(result.cpp, env, label, bufferSize)
result.closeImpl = icClose
result.putImpl = icPut
result.getBufferImpl = icGetBuffer
result.getImpl = icGet

View File

@ -1,60 +0,0 @@
/*
* \brief Connection to Dagfs service
* \author Emery Hemingway
* \date 2017-11-07
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__DAGFS_SESSION__CONNECTION_H_
#define _INCLUDE__DAGFS_SESSION__CONNECTION_H_
#include <dagfs_session/client.h>
#include <base/connection.h>
#include <base/allocator.h>
namespace Dagfs {
struct Connection;
enum { DEFAULT_GET_BUF_SIZE = 1 << 20 };
}
struct Dagfs::Connection : Genode::Connection<Session>, Session_client
{
/**
* Issue session request
*
* \noapi
*/
Session_capability _session(Genode::Parent &parent,
char const *label,
Genode::size_t get_buf_size)
{
return session(parent,
"ram_quota=%ld, cap_quota=%ld, tx_buf_size=%ld, label=\"%s\"",
32*1024*sizeof(long) + get_buf_size,
CAP_QUOTA, get_buf_size, label);
}
/**
* Constructor
*
* \param tx_buf_size size of reception buffer in bytes
*/
Connection(Genode::Env &env,
Genode::Range_allocator &tx_buffer_alloc,
char const *label = "",
Genode::size_t get_buf_size = DEFAULT_GET_BUF_SIZE)
:
Genode::Connection<Session>(
env, _session(env.parent(), label, get_buf_size)),
Session_client(cap(), env.rm(), tx_buffer_alloc)
{ }
};
#endif /* _INCLUDE__DAGFS_SESSION__CONNECTION_H_ */

View File

@ -1,56 +0,0 @@
/*
* \brief Dagfs C++ session component
* \author Emery Hemingway
* \date 2017-11-07
*/
/*
* Copyright (C) 2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__NIM__DAGFS_SERVER_H_
#define _INCLUDE__NIM__DAGFS_SERVER_H_
#include <dagfs_session/rpc_object.h>
#include <base/heap.h>
#include <base/attached_ram_dataspace.h>
struct Communication_buffer
{
Genode::Attached_ram_dataspace _tx_ds;
Communication_buffer(Genode::Pd_session &pd,
Genode::Region_map &rm,
Genode::size_t tx_buf_size)
: _tx_ds(pd, rm, tx_buf_size) { }
};
struct DagfsSessionComponentBase : Communication_buffer,
Dagfs::Session_rpc_object
{
static Genode::size_t tx_buf_size(char const *args)
{
Genode::size_t const buf_size = Genode::Arg_string::find_arg(
args, "tx_buf_size").aligned_size();
if (!buf_size)
throw Genode::Service_denied();
return buf_size;
}
DagfsSessionComponentBase(Genode::Env *env, char const *args)
:
Communication_buffer(env->pd(), env->rm(), tx_buf_size(args)),
Session_rpc_object(env->rm(), env->ep().rpc_ep(), _tx_ds.cap())
{ }
void packetHandler(Genode::Signal_context_capability cap)
{
_tx.sigh_ready_to_ack(cap);
_tx.sigh_packet_avail(cap);
}
};
#endif /* _INCLUDE__NIM__DAGFS_SERVER_H_ */

View File

@ -1,143 +0,0 @@
#
# \brief Dagfs server factory
# \author Emery Hemingway
# \date 2017-11-11
#
#
# Copyright (C) 2017 Genode Labs GmbH
#
# This file is part of the Genode OS framework, which is distributed
# under the terms of the GNU Affero General Public License version 3.
#
import std/strtabs, std/tables, std/xmltree, std/strutils
import cbor, genode, genode/signals, genode/servers, genode/parents,
dagfs, dagfs/stores, ./dagfs_session
const
currentPath = currentSourcePath.rsplit("/", 1)[0]
dagfsserverH = currentPath & "/dagfs_server.h"
type
DagfsSessionComponentBase {.importcpp, header: dagfsserverH.} = object
SessionCpp = Constructible[DagfsSessionComponentBase]
Session = ref object
cpp: SessionCpp
sig: SignalHandler
store: DagfsStore
id: ServerId
label: string
proc processPacket(session: Session; pkt: var DagfsPacket) =
proc packetContent(cpp: SessionCpp; pkt: DagfsPacket): pointer {.
importcpp: "#->sink().packet_content(@)".}
let cid = pkt.cid
case pkt.operation
of PUT:
try:
var
pktBuf = session.cpp.packetContent pkt
heapBuf = newString pkt.len
copyMem(heapBuf[0].addr, pktBuf, heapBuf.len)
let putCid = session.store.put(heapBuf)
assert(putCid.isValid, "server packet returned invalid CID from put")
pkt.setCid putCid
except:
echo "unhandled PUT error ", getCurrentExceptionMsg()
pkt.setError ERROR
of GET:
try:
let
pktBuf = session.cpp.packetContent pkt
n = session.store.getBuffer(cid, pktBuf, pkt.size)
pkt.setLen n
except BufferTooSmall:
pkt.setError OVERSIZE
except MissingObject:
pkt.setError MISSING
except:
echo "unhandled GET error ", getCurrentExceptionMsg()
pkt.setError ERROR
else:
echo "invalid packet operation"
pkt.setError ERROR
proc newSession(env: GenodeEnv; store: DagfsStore; id: ServerId; label, args: string): Session =
## Create a new session and packet handling procedure
let session = new Session
assert(not session.isNil)
proc construct(cpp: SessionCpp; env: GenodeEnv; args: cstring) {.importcpp.}
session.cpp.construct(env, args)
session.store = store
session.id = id
session.label = label
session.sig = env.ep.newSignalHandler do ():
proc packetAvail(cpp: SessionCpp): bool {.
importcpp: "#->sink().packet_avail()".}
proc readyToAck(cpp: SessionCpp): bool {.
importcpp: "#->sink().ready_to_ack()".}
while session.cpp.packetAvail and session.cpp.readyToAck:
proc getPacket(cpp: SessionCpp): DagfsPacket {.
importcpp: "#->sink().get_packet()".}
var pkt = session.cpp.getPacket()
session.processPacket pkt
proc acknowledgePacket(cpp: SessionCpp; pkt: DagfsPacket) {.
importcpp: "#->sink().acknowledge_packet(@)".}
session.cpp.acknowledgePacket(pkt)
proc packetHandler(cpp: SessionCpp; cap: SignalContextCapability) {.
importcpp: "#->packetHandler(@)".}
session.cpp.packetHandler(session.sig.cap)
result = session
proc manage(ep: Entrypoint; s: Session): DagfsSessionCapability =
## Manage a session from the default entrypoint.
proc manage(ep: Entrypoint; cpp: SessionCpp): DagfsSessionCapability {.
importcpp: "#.manage(*#)".}
result = ep.manage(s.cpp)
GC_ref s
proc dissolve(ep: Entrypoint; s: Session) =
## Dissolve a session from the entrypoint so that it can be freed.
proc dissolve(ep: Entrypoint; cpp: SessionCpp) {.
importcpp: "#.dissolve(*#)".}
ep.dissolve(s.cpp)
destruct(s.cpp)
dissolve(s.sig)
GC_unref s
type
DagfsServer* = ref object
env: GenodeEnv
store*: DagfsStore
sessions*: Table[ServerId, Session]
proc newDagfsServer*(env: GenodeEnv; store: DagfsStore): DagfsServer =
DagfsServer(
env: env, store: store,
sessions: initTable[ServerId, Session]())
proc create*(server: DagfsServer; id: ServerId; label, args: string) =
if not server.sessions.contains id:
try:
let
session = newSession(server.env, server.store, id, label, args)
cap = server.env.ep.manage(session)
server.sessions[id] = session
proc deliverSession(env: GenodeEnv; id: ServerId; cap: DagfsSessionCapability) {.
importcpp: "#->parent().deliver_session_cap(Genode::Parent::Server::Id{#}, #)".}
server.env.deliverSession(id, cap)
echo "session opened for ", label
except:
echo "failed to create session for '", label, "', ", getCurrentExceptionMsg()
server.env.parent.sessionResponseDeny id
proc close*(server: DagfsServer; id: ServerId) =
## Close a session at the Dagfs server.
if server.sessions.contains id:
let session = server.sessions[id]
server.env.ep.dissolve(session)
server.sessions.del id
server.env.parent.sessionResponseClose id

View File

@ -1,47 +0,0 @@
#
# \brief Dagfs session definitions
# \author Emery Hemingway
# \date 2017-11-11
#
#
# Copyright (C) 2017 Genode Labs GmbH
#
# This file is part of the Genode OS framework, which is distributed
# under the terms of the GNU Affero General Public License version 3.
#
import dagfs
const MaxPacketSize* = 1 shl 18;
type
DagfsSessionCapability* {.final, pure,
importcpp: "Dagfs::Session_capability",
header: "<dagfs_session/capability.h>".} = object
DagfsPacket* {.
importcpp: "Dagfs::Packet",
header: "<dagfs_session/dagfs_session.h>".} = object
DagfsOpcode* {.importcpp: "Dagfs::Packet::Opcode".} = enum
PUT, GET, INVALID
DagfsError* {.importcpp: "Dagfs::Packet::Error".} = enum
OK, MISSING, OVERSIZE, FULL, ERROR
proc size*(pkt: DagfsPacket): csize {.importcpp.}
## Physical packet size.
proc cidStr(p: DagfsPacket): cstring {.importcpp: "#.cid().string()".}
proc cid*(p: DagfsPacket): Cid = parseCid $p.cidStr
proc setCid*(p: var DagfsPacket; cid: cstring) {.importcpp: "#.cid(@)".}
proc setCid*(p: var DagfsPacket; cid: Cid) = p.setCid(cid.toHex())
proc operation*(pkt: DagfsPacket): DagfsOpcode {.importcpp.}
proc len*(pkt: DagfsPacket): csize {.importcpp: "length".}
## Logical packet length.
proc setLen*(pkt: var DagfsPacket; len: int) {.importcpp: "length".}
## Set logical packet length.
proc error*(pkt: DagfsPacket): DagfsError {.importcpp.}
proc setError*(pkt: var DagfsPacket; err: DagfsError) {.importcpp: "error".}

View File

@ -1 +0,0 @@
--cincludes:"../../../include"

View File

@ -11,8 +11,8 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__DAGFS_SESSION__DAGFS_SESSION_H_
#define _INCLUDE__DAGFS_SESSION__DAGFS_SESSION_H_
#ifndef _DAGFS_SESSION_H_
#define _DAGFS_SESSION_H_
#include <packet_stream_tx/packet_stream_tx.h>
#include <session/session.h>
@ -119,4 +119,4 @@ struct Dagfs::Session : Genode::Session
GENODE_RPC_INTERFACE(Rpc_tx_cap);
};
#endif /* _INCLUDE__DAGFS_SESSION__DAGFS_SESSION_H_ */
#endif /* _DAGFS_SESSION_H_ */