# HG changeset patch # User Paul Boddie # Date 1618777974 -7200 # Node ID e944e1a088b5a336f500a2290757eeebea535f46 # Parent 3c6563ec63d4d17709f517307f275439e1b224cf Added a file implementation using the filesystem client interface as a basis of further development. diff -r 3c6563ec63d4 -r e944e1a088b5 conf/dstest_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_client.cfg Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,34 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local blocksvr = l:new_channel(); + +l:startv({ + caps = { + server = blocksvr:svr(), + }, + log = { "blocksvr", "r" }, + }, + "rom/dstest_block_server", "10"); + +local clientsvr = l:new_channel(); + +l:startv({ + caps = { + server = blocksvr, + clientsvr = clientsvr:svr(), + }, + log = { "clientsvr", "r" }, + }, + "rom/dstest_client_server", "10", "clientsvr"); + +l:startv({ + caps = { + server = clientsvr, + }, + log = { "client", "g" }, + }, + "rom/dstest_block_client_simple", "rom/dstest_client.cfg"); diff -r 3c6563ec63d4 -r e944e1a088b5 conf/dstest_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_client.list Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,26 @@ +entry dstest_client +roottask moe rom/dstest_client.cfg +module dstest_client.cfg +module l4re +module ned +module dstest_block_client_simple +module dstest_block_server +module dstest_client_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/Control --- a/libfsserver/Control Sun Apr 18 22:31:55 2021 +0200 +++ b/libfsserver/Control Sun Apr 18 22:32:54 2021 +0200 @@ -1,3 +1,3 @@ -requires: libstdc++ libc libipc libmem +requires: libstdc++ libc libipc libmem libfsclient provides: libfsserver maintainer: paul@boddie.org.uk diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/include/fsserver/client_file_accessor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/client_file_accessor.h Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,58 @@ +/* + * A file accessor employing a file provided via the filesystem client + * interface. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + +#include + + + +/* A filesystem client file accessor, providing flexpages corresponding to file + regions. */ + +class ClientFileAccessor : public Accessor +{ +protected: + const char *_path; + file_t *_file; + + /* Data transfer helper methods. */ + + virtual void fill_populated(Flexpage *flexpage); + + virtual void flush_populated(Flexpage *flexpage); + +public: + explicit ClientFileAccessor(const char *path, fileid_t fileid); + + virtual void close(); + + virtual void open(); + + virtual offset_t get_size(); + + virtual void set_size(offset_t size); +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/include/fsserver/client_file_opener.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/client_file_opener.h Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,49 @@ +/* + * An opener for a file provided via the filesystem client interface. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + + + +/* Support for providing access to files. */ + +class ClientFileOpener : public HostFileOpener +{ +protected: + //const char *_filename; + fileid_t _counter = 1; // NOTE: Temporary measure. + + /* Configurable methods. */ + + virtual fileid_t get_fileid(const char *path); + + virtual Accessor *make_accessor(fileid_t fileid); + +public: + explicit ClientFileOpener(Pages *pages) + : HostFileOpener(pages) + { + } +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Sun Apr 18 22:31:55 2021 +0200 +++ b/libfsserver/lib/Makefile Sun Apr 18 22:32:54 2021 +0200 @@ -37,6 +37,8 @@ PLAIN_SRC_CC = \ files/block_file_accessor.cc \ files/block_file_opener.cc \ + files/client_file_accessor.cc \ + files/client_file_opener.cc \ files/file_pager.cc \ files/file_paging.cc \ files/host_file_accessor.cc \ @@ -67,7 +69,7 @@ $(SERVER_INTERFACES_SRC_CC) \ $(PLAIN_SRC_CC) -REQUIRES_LIBS = l4re_c-util libmem libipc libstdc++ libsystypes +REQUIRES_LIBS = l4re_c-util libmem libipc libstdc++ libsystypes libfsclient PRIVATE_INCDIR = $(PKGDIR)/include $(PKGDIR)/include/fsserver \ $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/lib/files/client_file_accessor.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/client_file_accessor.cc Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,108 @@ +/* + * A file accessor using the filesystem client interface. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include +#include + +#include + +#include +#include + +#include "client_file_accessor.h" + + + +ClientFileAccessor::ClientFileAccessor(const char *path, fileid_t fileid) +: Accessor(fileid), _path(path) +{ +} + +/* Return the size of the file. */ + +offset_t ClientFileAccessor::get_size() +{ + return _file->size; +} + +/* Update the size of the file. */ + +void ClientFileAccessor::set_size(offset_t size) +{ + file_resize(_file, size); +} + +/* Perform any closing operation on the file. */ + +void ClientFileAccessor::close() +{ + client_close(_file); +} + +/* Perform any opening operation on the file. */ + +void ClientFileAccessor::open() +{ + _file = client_open(_path, O_RDWR); +} + +/* Data transfer helper methods. */ + +/* Fill the populated portion of a flexpage. */ + +void ClientFileAccessor::fill_populated(Flexpage *flexpage) +{ + offset_t filepos = flexpage->base_offset; + offset_t addr = flexpage->base_addr; + + /* Tag the region with file state. */ + + flexpage->region->fill(fileid, filepos); + + /* Fill the region with file content. */ + + client_seek(_file, filepos, SEEK_SET); + offset_t nread = client_read(_file, (char *) addr, flexpage->size); + + /* Pad the flexpage with zero. */ + + memset((void *) (addr + nread), 0, flexpage->size - nread); +} + +/* Flush the populated portion of a flexpage. */ + +void ClientFileAccessor::flush_populated(Flexpage *flexpage) +{ + offset_t filepos = flexpage->base_offset; + offset_t addr = flexpage->base_addr; + offset_t populated_size = std::min(flexpage->size, get_size() - filepos); + + /* Remove the file state tag from the region. */ + + flexpage->region->flush(); + + /* Copy the populated region to the file. */ + + client_seek(_file, filepos, SEEK_SET); + client_write(_file, (char *) addr, populated_size); +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 3c6563ec63d4 -r e944e1a088b5 libfsserver/lib/files/client_file_opener.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/client_file_opener.cc Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,46 @@ +/* + * An opener for a file provided via the filesystem client interface. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include "client_file_accessor.h" +#include "client_file_opener.h" + +/* Return a file identifier for the given 'path'. */ + +fileid_t ClientFileOpener::get_fileid(const char *path) +{ + _paths.insert(FilePathEntry(_counter, path)); + + return _counter++; +} + +/* Return a new accessor for 'fileid'. */ + +Accessor *ClientFileOpener::make_accessor(fileid_t fileid) +{ + FilePaths::iterator found = _paths.find(fileid); + + if (found != _paths.end()) + return new ClientFileAccessor(found->second, fileid); + else + return NULL; +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 3c6563ec63d4 -r e944e1a088b5 servers/Makefile --- a/servers/Makefile Sun Apr 18 22:31:55 2021 +0200 +++ b/servers/Makefile Sun Apr 18 22:32:54 2021 +0200 @@ -3,6 +3,7 @@ TARGET = \ dstest_block_server \ + dstest_client_server \ dstest_host_server \ dstest_pipe_server \ dstest_test_server @@ -11,6 +12,8 @@ SRC_CC_dstest_block_server = block_file_server.cc +SRC_CC_dstest_client_server = client_file_server.cc + SRC_CC_dstest_host_server = host_file_server.cc SRC_CC_dstest_pipe_server = pipe_server.cc diff -r 3c6563ec63d4 -r e944e1a088b5 servers/client_file_server.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servers/client_file_server.cc Sun Apr 18 22:32:54 2021 +0200 @@ -0,0 +1,88 @@ +/* + * A dataspace server exposing file contents accessed via the filesystem client + * interface. + * + * Copyright (C) 2020, 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include + + + +/* Default number of pages for files. */ + +const unsigned int MEMORY_PAGES = 20; + + + +/* Server program. */ + +int main(int argc, char *argv[]) +{ + long err; + + /* Introduce concurrency control. */ + + err = ipc_thread_init(); + + if (err) + { + printf("Initialisation error: %s\n", l4sys_errtostr(err)); + return 1; + } + + unsigned int memory_pages = MEMORY_PAGES; + + if (argc > 1) + memory_pages = atoi(argv[1]); + + /* Some memory plus infrastructure. */ + + MemoryIncremental mem(memory_pages); + PageQueueShared queue; + Pages pages(&mem, &queue); + ClientFileOpener opener(&pages); + + /* Register a server associating it with the given object. */ + + const char *server_name = (argc > 2) ? argv[2] : "server"; + + ResourceServer server(&opener); + err = server.bind(server_name); + + if (err) + { + printf("Could not bind server: %s\n", l4sys_errtostr(err)); + return 1; + } + + printf("Starting server using %d pages...\n", memory_pages); + server.start(); + return 0; +}