1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/conf/dstest_client.cfg Sun Apr 18 22:32:54 2021 +0200
1.3 @@ -0,0 +1,34 @@
1.4 +-- vim:set ft=lua:
1.5 +
1.6 +local L4 = require("L4");
1.7 +
1.8 +local l = L4.default_loader;
1.9 +
1.10 +local blocksvr = l:new_channel();
1.11 +
1.12 +l:startv({
1.13 + caps = {
1.14 + server = blocksvr:svr(),
1.15 + },
1.16 + log = { "blocksvr", "r" },
1.17 + },
1.18 + "rom/dstest_block_server", "10");
1.19 +
1.20 +local clientsvr = l:new_channel();
1.21 +
1.22 +l:startv({
1.23 + caps = {
1.24 + server = blocksvr,
1.25 + clientsvr = clientsvr:svr(),
1.26 + },
1.27 + log = { "clientsvr", "r" },
1.28 + },
1.29 + "rom/dstest_client_server", "10", "clientsvr");
1.30 +
1.31 +l:startv({
1.32 + caps = {
1.33 + server = clientsvr,
1.34 + },
1.35 + log = { "client", "g" },
1.36 + },
1.37 + "rom/dstest_block_client_simple", "rom/dstest_client.cfg");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/conf/dstest_client.list Sun Apr 18 22:32:54 2021 +0200
2.3 @@ -0,0 +1,26 @@
2.4 +entry dstest_client
2.5 +roottask moe rom/dstest_client.cfg
2.6 +module dstest_client.cfg
2.7 +module l4re
2.8 +module ned
2.9 +module dstest_block_client_simple
2.10 +module dstest_block_server
2.11 +module dstest_client_server
2.12 +module lib4re-c.so
2.13 +module lib4re-c-util.so
2.14 +module lib4re.so
2.15 +module lib4re-util.so
2.16 +module libc_be_l4refile.so
2.17 +module libc_be_l4re.so
2.18 +module libc_be_socket_noop.so
2.19 +module libc_support_misc.so
2.20 +module libdl.so
2.21 +module libipc.so
2.22 +module libl4sys-direct.so
2.23 +module libl4sys.so
2.24 +module libl4util.so
2.25 +module libld-l4.so
2.26 +module libpthread.so
2.27 +module libstdc++.so
2.28 +module libsupc++.so
2.29 +module libuc_c.so
3.1 --- a/libfsserver/Control Sun Apr 18 22:31:55 2021 +0200
3.2 +++ b/libfsserver/Control Sun Apr 18 22:32:54 2021 +0200
3.3 @@ -1,3 +1,3 @@
3.4 -requires: libstdc++ libc libipc libmem
3.5 +requires: libstdc++ libc libipc libmem libfsclient
3.6 provides: libfsserver
3.7 maintainer: paul@boddie.org.uk
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/libfsserver/include/fsserver/client_file_accessor.h Sun Apr 18 22:32:54 2021 +0200
4.3 @@ -0,0 +1,58 @@
4.4 +/*
4.5 + * A file accessor employing a file provided via the filesystem client
4.6 + * interface.
4.7 + *
4.8 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
4.9 + *
4.10 + * This program is free software; you can redistribute it and/or
4.11 + * modify it under the terms of the GNU General Public License as
4.12 + * published by the Free Software Foundation; either version 2 of
4.13 + * the License, or (at your option) any later version.
4.14 + *
4.15 + * This program is distributed in the hope that it will be useful,
4.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.18 + * GNU General Public License for more details.
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License
4.21 + * along with this program; if not, write to the Free Software
4.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.23 + * Boston, MA 02110-1301, USA
4.24 + */
4.25 +
4.26 +#pragma once
4.27 +
4.28 +#include <fsserver/accessor.h>
4.29 +
4.30 +#include <fsclient/file.h>
4.31 +
4.32 +
4.33 +
4.34 +/* A filesystem client file accessor, providing flexpages corresponding to file
4.35 + regions. */
4.36 +
4.37 +class ClientFileAccessor : public Accessor
4.38 +{
4.39 +protected:
4.40 + const char *_path;
4.41 + file_t *_file;
4.42 +
4.43 + /* Data transfer helper methods. */
4.44 +
4.45 + virtual void fill_populated(Flexpage *flexpage);
4.46 +
4.47 + virtual void flush_populated(Flexpage *flexpage);
4.48 +
4.49 +public:
4.50 + explicit ClientFileAccessor(const char *path, fileid_t fileid);
4.51 +
4.52 + virtual void close();
4.53 +
4.54 + virtual void open();
4.55 +
4.56 + virtual offset_t get_size();
4.57 +
4.58 + virtual void set_size(offset_t size);
4.59 +};
4.60 +
4.61 +// vim: tabstop=4 expandtab shiftwidth=4
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/libfsserver/include/fsserver/client_file_opener.h Sun Apr 18 22:32:54 2021 +0200
5.3 @@ -0,0 +1,49 @@
5.4 +/*
5.5 + * An opener for a file provided via the filesystem client interface.
5.6 + *
5.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
5.8 + *
5.9 + * This program is free software; you can redistribute it and/or
5.10 + * modify it under the terms of the GNU General Public License as
5.11 + * published by the Free Software Foundation; either version 2 of
5.12 + * the License, or (at your option) any later version.
5.13 + *
5.14 + * This program is distributed in the hope that it will be useful,
5.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 + * GNU General Public License for more details.
5.18 + *
5.19 + * You should have received a copy of the GNU General Public License
5.20 + * along with this program; if not, write to the Free Software
5.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 + * Boston, MA 02110-1301, USA
5.23 + */
5.24 +
5.25 +#pragma once
5.26 +
5.27 +#include <fsserver/host_file_opener.h>
5.28 +
5.29 +
5.30 +
5.31 +/* Support for providing access to files. */
5.32 +
5.33 +class ClientFileOpener : public HostFileOpener
5.34 +{
5.35 +protected:
5.36 + //const char *_filename;
5.37 + fileid_t _counter = 1; // NOTE: Temporary measure.
5.38 +
5.39 + /* Configurable methods. */
5.40 +
5.41 + virtual fileid_t get_fileid(const char *path);
5.42 +
5.43 + virtual Accessor *make_accessor(fileid_t fileid);
5.44 +
5.45 +public:
5.46 + explicit ClientFileOpener(Pages *pages)
5.47 + : HostFileOpener(pages)
5.48 + {
5.49 + }
5.50 +};
5.51 +
5.52 +// vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/libfsserver/lib/Makefile Sun Apr 18 22:31:55 2021 +0200
6.2 +++ b/libfsserver/lib/Makefile Sun Apr 18 22:32:54 2021 +0200
6.3 @@ -37,6 +37,8 @@
6.4 PLAIN_SRC_CC = \
6.5 files/block_file_accessor.cc \
6.6 files/block_file_opener.cc \
6.7 + files/client_file_accessor.cc \
6.8 + files/client_file_opener.cc \
6.9 files/file_pager.cc \
6.10 files/file_paging.cc \
6.11 files/host_file_accessor.cc \
6.12 @@ -67,7 +69,7 @@
6.13 $(SERVER_INTERFACES_SRC_CC) \
6.14 $(PLAIN_SRC_CC)
6.15
6.16 -REQUIRES_LIBS = l4re_c-util libmem libipc libstdc++ libsystypes
6.17 +REQUIRES_LIBS = l4re_c-util libmem libipc libstdc++ libsystypes libfsclient
6.18
6.19 PRIVATE_INCDIR = $(PKGDIR)/include $(PKGDIR)/include/fsserver \
6.20 $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/libfsserver/lib/files/client_file_accessor.cc Sun Apr 18 22:32:54 2021 +0200
7.3 @@ -0,0 +1,108 @@
7.4 +/*
7.5 + * A file accessor using the filesystem client interface.
7.6 + *
7.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or
7.10 + * modify it under the terms of the GNU General Public License as
7.11 + * published by the Free Software Foundation; either version 2 of
7.12 + * the License, or (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program; if not, write to the Free Software
7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 + * Boston, MA 02110-1301, USA
7.23 + */
7.24 +
7.25 +#include <stdio.h>
7.26 +#include <string.h>
7.27 +
7.28 +#include <algorithm>
7.29 +
7.30 +#include <fsclient/client.h>
7.31 +#include <systypes/fcntl.h>
7.32 +
7.33 +#include "client_file_accessor.h"
7.34 +
7.35 +
7.36 +
7.37 +ClientFileAccessor::ClientFileAccessor(const char *path, fileid_t fileid)
7.38 +: Accessor(fileid), _path(path)
7.39 +{
7.40 +}
7.41 +
7.42 +/* Return the size of the file. */
7.43 +
7.44 +offset_t ClientFileAccessor::get_size()
7.45 +{
7.46 + return _file->size;
7.47 +}
7.48 +
7.49 +/* Update the size of the file. */
7.50 +
7.51 +void ClientFileAccessor::set_size(offset_t size)
7.52 +{
7.53 + file_resize(_file, size);
7.54 +}
7.55 +
7.56 +/* Perform any closing operation on the file. */
7.57 +
7.58 +void ClientFileAccessor::close()
7.59 +{
7.60 + client_close(_file);
7.61 +}
7.62 +
7.63 +/* Perform any opening operation on the file. */
7.64 +
7.65 +void ClientFileAccessor::open()
7.66 +{
7.67 + _file = client_open(_path, O_RDWR);
7.68 +}
7.69 +
7.70 +/* Data transfer helper methods. */
7.71 +
7.72 +/* Fill the populated portion of a flexpage. */
7.73 +
7.74 +void ClientFileAccessor::fill_populated(Flexpage *flexpage)
7.75 +{
7.76 + offset_t filepos = flexpage->base_offset;
7.77 + offset_t addr = flexpage->base_addr;
7.78 +
7.79 + /* Tag the region with file state. */
7.80 +
7.81 + flexpage->region->fill(fileid, filepos);
7.82 +
7.83 + /* Fill the region with file content. */
7.84 +
7.85 + client_seek(_file, filepos, SEEK_SET);
7.86 + offset_t nread = client_read(_file, (char *) addr, flexpage->size);
7.87 +
7.88 + /* Pad the flexpage with zero. */
7.89 +
7.90 + memset((void *) (addr + nread), 0, flexpage->size - nread);
7.91 +}
7.92 +
7.93 +/* Flush the populated portion of a flexpage. */
7.94 +
7.95 +void ClientFileAccessor::flush_populated(Flexpage *flexpage)
7.96 +{
7.97 + offset_t filepos = flexpage->base_offset;
7.98 + offset_t addr = flexpage->base_addr;
7.99 + offset_t populated_size = std::min(flexpage->size, get_size() - filepos);
7.100 +
7.101 + /* Remove the file state tag from the region. */
7.102 +
7.103 + flexpage->region->flush();
7.104 +
7.105 + /* Copy the populated region to the file. */
7.106 +
7.107 + client_seek(_file, filepos, SEEK_SET);
7.108 + client_write(_file, (char *) addr, populated_size);
7.109 +}
7.110 +
7.111 +// vim: tabstop=4 expandtab shiftwidth=4
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/libfsserver/lib/files/client_file_opener.cc Sun Apr 18 22:32:54 2021 +0200
8.3 @@ -0,0 +1,46 @@
8.4 +/*
8.5 + * An opener for a file provided via the filesystem client interface.
8.6 + *
8.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
8.8 + *
8.9 + * This program is free software; you can redistribute it and/or
8.10 + * modify it under the terms of the GNU General Public License as
8.11 + * published by the Free Software Foundation; either version 2 of
8.12 + * the License, or (at your option) any later version.
8.13 + *
8.14 + * This program is distributed in the hope that it will be useful,
8.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 + * GNU General Public License for more details.
8.18 + *
8.19 + * You should have received a copy of the GNU General Public License
8.20 + * along with this program; if not, write to the Free Software
8.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
8.22 + * Boston, MA 02110-1301, USA
8.23 + */
8.24 +
8.25 +#include "client_file_accessor.h"
8.26 +#include "client_file_opener.h"
8.27 +
8.28 +/* Return a file identifier for the given 'path'. */
8.29 +
8.30 +fileid_t ClientFileOpener::get_fileid(const char *path)
8.31 +{
8.32 + _paths.insert(FilePathEntry(_counter, path));
8.33 +
8.34 + return _counter++;
8.35 +}
8.36 +
8.37 +/* Return a new accessor for 'fileid'. */
8.38 +
8.39 +Accessor *ClientFileOpener::make_accessor(fileid_t fileid)
8.40 +{
8.41 + FilePaths::iterator found = _paths.find(fileid);
8.42 +
8.43 + if (found != _paths.end())
8.44 + return new ClientFileAccessor(found->second, fileid);
8.45 + else
8.46 + return NULL;
8.47 +}
8.48 +
8.49 +// vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/servers/Makefile Sun Apr 18 22:31:55 2021 +0200
9.2 +++ b/servers/Makefile Sun Apr 18 22:32:54 2021 +0200
9.3 @@ -3,6 +3,7 @@
9.4
9.5 TARGET = \
9.6 dstest_block_server \
9.7 + dstest_client_server \
9.8 dstest_host_server \
9.9 dstest_pipe_server \
9.10 dstest_test_server
9.11 @@ -11,6 +12,8 @@
9.12
9.13 SRC_CC_dstest_block_server = block_file_server.cc
9.14
9.15 +SRC_CC_dstest_client_server = client_file_server.cc
9.16 +
9.17 SRC_CC_dstest_host_server = host_file_server.cc
9.18
9.19 SRC_CC_dstest_pipe_server = pipe_server.cc
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/servers/client_file_server.cc Sun Apr 18 22:32:54 2021 +0200
10.3 @@ -0,0 +1,88 @@
10.4 +/*
10.5 + * A dataspace server exposing file contents accessed via the filesystem client
10.6 + * interface.
10.7 + *
10.8 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
10.9 + *
10.10 + * This program is free software; you can redistribute it and/or
10.11 + * modify it under the terms of the GNU General Public License as
10.12 + * published by the Free Software Foundation; either version 2 of
10.13 + * the License, or (at your option) any later version.
10.14 + *
10.15 + * This program is distributed in the hope that it will be useful,
10.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.18 + * GNU General Public License for more details.
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License
10.21 + * along with this program; if not, write to the Free Software
10.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
10.23 + * Boston, MA 02110-1301, USA
10.24 + */
10.25 +
10.26 +#include <l4/sys/err.h>
10.27 +
10.28 +#include <ipc/thread.h>
10.29 +
10.30 +#include <stdio.h>
10.31 +#include <stdlib.h>
10.32 +
10.33 +#include <mem/memory_incremental.h>
10.34 +#include <fsserver/page_queue_shared.h>
10.35 +#include <fsserver/pages.h>
10.36 +#include <fsserver/resource_server.h>
10.37 +#include <fsserver/client_file_opener.h>
10.38 +
10.39 +
10.40 +
10.41 +/* Default number of pages for files. */
10.42 +
10.43 +const unsigned int MEMORY_PAGES = 20;
10.44 +
10.45 +
10.46 +
10.47 +/* Server program. */
10.48 +
10.49 +int main(int argc, char *argv[])
10.50 +{
10.51 + long err;
10.52 +
10.53 + /* Introduce concurrency control. */
10.54 +
10.55 + err = ipc_thread_init();
10.56 +
10.57 + if (err)
10.58 + {
10.59 + printf("Initialisation error: %s\n", l4sys_errtostr(err));
10.60 + return 1;
10.61 + }
10.62 +
10.63 + unsigned int memory_pages = MEMORY_PAGES;
10.64 +
10.65 + if (argc > 1)
10.66 + memory_pages = atoi(argv[1]);
10.67 +
10.68 + /* Some memory plus infrastructure. */
10.69 +
10.70 + MemoryIncremental mem(memory_pages);
10.71 + PageQueueShared queue;
10.72 + Pages pages(&mem, &queue);
10.73 + ClientFileOpener opener(&pages);
10.74 +
10.75 + /* Register a server associating it with the given object. */
10.76 +
10.77 + const char *server_name = (argc > 2) ? argv[2] : "server";
10.78 +
10.79 + ResourceServer server(&opener);
10.80 + err = server.bind(server_name);
10.81 +
10.82 + if (err)
10.83 + {
10.84 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
10.85 + return 1;
10.86 + }
10.87 +
10.88 + printf("Starting server using %d pages...\n", memory_pages);
10.89 + server.start();
10.90 + return 0;
10.91 +}