mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
lxip: VFS plugin
Provides file-system compatible to libc socket-fs requirements. This includes pseudo file for network configuration.
This commit is contained in:
parent
1f29e1854a
commit
304f2eaf38
@ -78,7 +78,18 @@ namespace Lxip {
|
||||
};
|
||||
|
||||
enum Ioctl_cmd {
|
||||
LINUX_FIONREAD = 0x541b /* == SIOCINQ */
|
||||
LINUX_FIONREAD = 0x541b, /* == SIOCINQ */
|
||||
LINUX_IFADDR = 0x8915, /* == SIOCGIFADDR */
|
||||
};
|
||||
|
||||
/*
|
||||
* Must match errno values from lx_emul.h
|
||||
*/
|
||||
enum Io_result {
|
||||
LINUX_EAGAIN = -35,
|
||||
LINUX_EINPROGRESS = -36,
|
||||
LINUX_EALREADY = -37,
|
||||
LINUX_EISCONN = -56,
|
||||
};
|
||||
}
|
||||
|
||||
|
21
repos/dde_linux/lib/mk/vfs_lxip.mk
Normal file
21
repos/dde_linux/lib/mk/vfs_lxip.mk
Normal file
@ -0,0 +1,21 @@
|
||||
SHARED_LIB = yes
|
||||
|
||||
VFS_DIR = $(REP_DIR)/src/lib/vfs/lxip
|
||||
LXIP_DIR = $(REP_DIR)/src/lib/lxip
|
||||
|
||||
LIBS += lxip lxip_include
|
||||
INC_DIR += $(VFS_DIR)
|
||||
LD_OPT += --version-script=$(VFS_DIR)/symbol.map
|
||||
SRC_CC = vfs.cc
|
||||
|
||||
vpath %.cc $(REP_DIR)/src/lib/vfs/lxip
|
||||
|
||||
SETUP_SUFFIX =
|
||||
CC_OPT += -DSETUP_SUFFIX=$(SETUP_SUFFIX)
|
||||
|
||||
CC_OPT += -U__linux__ -D__KERNEL__
|
||||
CC_OPT += -DCONFIG_INET -DCONFIG_BASE_SMALL=0 -DCONFIG_DEBUG_LOCK_ALLOC \
|
||||
-DCONFIG_IP_PNP_DHCP
|
||||
|
||||
CC_C_OPT += -include $(LXIP_DIR)/include/lx_emul.h
|
||||
CC_CXX_OPT = -fpermissive
|
103
repos/dde_linux/run/vfs_cfg.run
Normal file
103
repos/dde_linux/run/vfs_cfg.run
Normal file
@ -0,0 +1,103 @@
|
||||
set build_components {
|
||||
core init
|
||||
drivers/nic
|
||||
drivers/timer
|
||||
lib/vfs/lxip
|
||||
server/vfs
|
||||
server/dynamic_rom
|
||||
}
|
||||
|
||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||
append_platform_drv_build_components
|
||||
|
||||
build $build_components
|
||||
|
||||
create_boot_directory
|
||||
|
||||
set config {
|
||||
<config verbose="yes">
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RAM"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
<start name="nic_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides> <service name="Nic"/> </provides>
|
||||
</start>
|
||||
|
||||
<start name="dynamic_rom">
|
||||
<resource name="RAM" quantum="4M"/>
|
||||
<provides><service name="ROM"/> </provides>
|
||||
<config verbose="yes">
|
||||
<rom name="socket_fs.config"><inline description="static">
|
||||
<config>
|
||||
<vfs>
|
||||
<lxip ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1" nameserver="8.8.8.8"/>
|
||||
</vfs>
|
||||
</config>
|
||||
</inline>
|
||||
<sleep milliseconds="2500"/> <inline description="dynamic">
|
||||
<config>
|
||||
<vfs>
|
||||
<lxip dhcp="yes"/>
|
||||
</vfs>
|
||||
</config>
|
||||
</inline>
|
||||
<sleep milliseconds="2500"/>
|
||||
</rom>
|
||||
</config>
|
||||
</start>
|
||||
|
||||
<start name="socket_fs">
|
||||
<binary name="vfs"/>
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<provides> <service name="File_system"/> </provides>
|
||||
<configfile name="socket_fs.config"/>
|
||||
<route>
|
||||
<service name="ROM" label="socket_fs.config"> <child name="dynamic_rom"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append config {
|
||||
</config>
|
||||
}
|
||||
|
||||
install_config $config
|
||||
|
||||
set boot_modules {
|
||||
core init timer nic_drv vfs dynamic_rom
|
||||
ld.lib.so vfs_lxip.lib.so lxip.lib.so
|
||||
}
|
||||
|
||||
append_platform_drv_boot_modules
|
||||
|
||||
build_boot_image $boot_modules
|
||||
|
||||
puts "#################################################################"
|
||||
puts "## run simultaneous ping to 10.0.2.55 and <dynamic IP address> ##"
|
||||
puts "#################################################################"
|
||||
sleep 1
|
||||
|
||||
append qemu_args " -nographic -net nic,model=e1000 -net tap,ifname=tap0,downscript=no,script=no "
|
||||
|
||||
run_genode_until forever
|
||||
|
||||
# vi: set ft=tcl :
|
108
repos/dde_linux/run/vfs_lxip.run
Normal file
108
repos/dde_linux/run/vfs_lxip.run
Normal file
@ -0,0 +1,108 @@
|
||||
assert_spec linux
|
||||
|
||||
set build_components {
|
||||
core init
|
||||
drivers/timer drivers/nic
|
||||
server/tcp_terminal
|
||||
test/terminal_echo
|
||||
lib/vfs/lxip
|
||||
test/vfs_lxip
|
||||
}
|
||||
|
||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||
append_platform_drv_build_components
|
||||
|
||||
build $build_components
|
||||
|
||||
create_boot_directory
|
||||
|
||||
set config {
|
||||
<config verbose="yes">
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
<start name="nic_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides> <service name="Nic"/> </provides>
|
||||
</start>
|
||||
<!--
|
||||
<start name="tcp_terminal">
|
||||
<resource name="RAM" quantum="10M"/>
|
||||
<provides> <service name="Terminal"/> </provides>
|
||||
<config ld_verbose="yes">
|
||||
<policy label="test-terminal_echo" port="8888"/>
|
||||
<libc stdout="/dev/log">
|
||||
<vfs>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
<dir name="socket">
|
||||
<lxip ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1"/>
|
||||
</dir>
|
||||
</vfs>
|
||||
</libc>
|
||||
</config>
|
||||
</start>
|
||||
-->
|
||||
<!-- use telnet on the client to connect to the test component -->
|
||||
<start name="test-vfs_lxip">
|
||||
<resource name="RAM" quantum="48M"/>
|
||||
<config>
|
||||
<libc stdout="/dev/log" stderr="/dev/log">
|
||||
<vfs>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
<dir name="socket">
|
||||
<lxip ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1" nameserver="8.8.8.8"/>
|
||||
</dir>
|
||||
</vfs>
|
||||
</libc>
|
||||
</config>
|
||||
</start>
|
||||
<!--
|
||||
<start name="test-terminal_echo">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
</start>
|
||||
-->
|
||||
}
|
||||
|
||||
append_platform_drv_config
|
||||
|
||||
append config {
|
||||
</config>
|
||||
}
|
||||
|
||||
install_config $config
|
||||
|
||||
set boot_modules {
|
||||
core init timer
|
||||
nic_drv
|
||||
ld.lib.so libc.lib.so libc_lock_pipe.lib.so
|
||||
libm.lib.so
|
||||
vfs_lxip.lib.so lxip.lib.so
|
||||
tcp_terminal
|
||||
test-terminal_echo
|
||||
test-vfs_lxip
|
||||
}
|
||||
|
||||
append_platform_drv_boot_modules
|
||||
|
||||
build_boot_image $boot_modules
|
||||
|
||||
run_genode_until forever
|
||||
|
||||
# vi: set ft=tcl :
|
9
repos/dde_linux/src/lib/vfs/lxip/symbol.map
Normal file
9
repos/dde_linux/src/lib/vfs/lxip/symbol.map
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
global:
|
||||
|
||||
vfs_file_system_factory;
|
||||
|
||||
local:
|
||||
|
||||
*;
|
||||
};
|
2
repos/dde_linux/src/lib/vfs/lxip/target.mk
Normal file
2
repos/dde_linux/src/lib/vfs/lxip/target.mk
Normal file
@ -0,0 +1,2 @@
|
||||
TARGET = dummy-vfs_lxip
|
||||
LIBS = vfs_lxip
|
1653
repos/dde_linux/src/lib/vfs/lxip/vfs.cc
Normal file
1653
repos/dde_linux/src/lib/vfs/lxip/vfs.cc
Normal file
File diff suppressed because it is too large
Load Diff
271
repos/dde_linux/src/test/vfs_lxip/main.cc
Normal file
271
repos/dde_linux/src/test/vfs_lxip/main.cc
Normal file
@ -0,0 +1,271 @@
|
||||
/*
|
||||
* \brief Simple test for lxip VFS plugin
|
||||
* \author Emery Hemingway
|
||||
* \author Josef Söntgen
|
||||
* \author Christian Helmuth
|
||||
* \date 2016-10-17
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016-2017 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
|
||||
static void ls_socket_fs(char const *path, bool top = true)
|
||||
{
|
||||
if (top)
|
||||
printf("recursive listing of %s:\n", path);
|
||||
|
||||
DIR *dp = opendir(path);
|
||||
if (dp == NULL) {
|
||||
perror("opendir");
|
||||
abort();
|
||||
}
|
||||
|
||||
struct dirent *dent = NULL;
|
||||
while ((dent = readdir(dp))) {
|
||||
int d = dent->d_type == DT_DIR;
|
||||
printf(" %s %s/%s\n", d ? "d" : "f", path, dent->d_name);
|
||||
|
||||
if (d) {
|
||||
char subdir[128];
|
||||
snprintf(subdir, sizeof(subdir), "%s/%s", path, dent->d_name);
|
||||
ls_socket_fs(subdir, false);
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
|
||||
|
||||
static int remove_sock_dir(char const *sock_root, char const *sock_fd)
|
||||
{
|
||||
char sock_dir[64];
|
||||
snprintf(sock_dir, sizeof(sock_dir), "%s/%s", sock_root, sock_fd);
|
||||
return unlink(sock_dir);
|
||||
}
|
||||
|
||||
|
||||
static int recv_client(char const *sock_root, char const *sock_fd)
|
||||
{
|
||||
char sock_data[96];
|
||||
snprintf(sock_data, sizeof(sock_data), "%s/%s/data", sock_root, sock_fd);
|
||||
|
||||
int fd = open(sock_data, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char dst;
|
||||
ssize_t n = read(fd, &dst, 1);
|
||||
printf("receiving data from client %s\n",
|
||||
n > 0 ? "successful" : "failed");
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int send_client(char const *sock_root, char const *sock_fd,
|
||||
char const *src, size_t len)
|
||||
{
|
||||
char sock_data[96];
|
||||
snprintf(sock_data, sizeof(sock_data), "%s/%s/data", sock_root, sock_fd);
|
||||
|
||||
int fd = open(sock_data, O_WRONLY);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t n = write(fd, src, len);
|
||||
printf("sending data to client %s\n",
|
||||
n > 0 && (size_t)n == len ? "successful" : "failed");
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void sock_info(char const *sock_root, char const *sock_fd)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
char local[96];
|
||||
snprintf(local, sizeof(local), "%s/%s/local", sock_root, sock_fd);
|
||||
|
||||
int fdl = open(local, O_RDONLY);
|
||||
if (fdl == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
|
||||
n = read(fdl, local, sizeof(local));
|
||||
local[n-1] = '\0';
|
||||
printf("local: %s\n", local);
|
||||
close(fdl);
|
||||
|
||||
char remote[96];
|
||||
snprintf(remote, sizeof(remote), "%s/%s/remote", sock_root, sock_fd);
|
||||
|
||||
int fdr = open(remote, O_RDONLY);
|
||||
if (fdr == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
|
||||
n = read(fdr, remote, sizeof(remote));
|
||||
remote[n-1] = '\0';
|
||||
printf("remote: %s\n", remote);
|
||||
close(fdr);
|
||||
}
|
||||
|
||||
|
||||
static int test_bind_accept(char const *sock_root, char const *sock_fd)
|
||||
{
|
||||
ssize_t n;
|
||||
|
||||
/* bind */
|
||||
char sock_bind[96];
|
||||
snprintf(sock_bind, sizeof(sock_bind), "%s/%s/bind", sock_root, sock_fd);
|
||||
|
||||
int fdb = open(sock_bind, O_RDWR);
|
||||
if (fdb == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char addr[] = "0.0.0.0:80";
|
||||
n = write(fdb, addr, sizeof(addr));
|
||||
printf("binding to: %s %s\n", addr, n > 0 ? "success" : "failed");
|
||||
close(fdb);
|
||||
|
||||
char sock_listen[96];
|
||||
snprintf(sock_listen, sizeof(sock_listen), "%s/%s/listen", sock_root, sock_fd);
|
||||
|
||||
int fdl = open(sock_listen, O_RDWR);
|
||||
if (fdl == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char backlog[] = "5";
|
||||
n = write(fdl, backlog, sizeof(backlog));
|
||||
printf("listen backlog: %s %s\n", backlog, n > 0 ? "success" : "failed");
|
||||
close(fdl);
|
||||
|
||||
|
||||
/* accept */
|
||||
int res = 0;
|
||||
while (1) {
|
||||
char sock_accept[96];
|
||||
snprintf(sock_accept, sizeof(sock_accept), "%s/%s/accept", sock_root, sock_fd);
|
||||
|
||||
ls_socket_fs(sock_root);
|
||||
|
||||
int fda = open(sock_accept, O_RDWR);
|
||||
if (fda == -1) {
|
||||
perror("open");
|
||||
res = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
char client_fd[8] = { 0 };
|
||||
res = read(fda, client_fd, sizeof(client_fd));
|
||||
close(fda);
|
||||
|
||||
if (res < 0) break;
|
||||
else if (res == 0) continue;
|
||||
|
||||
client_fd[res-1] = '\0';
|
||||
|
||||
printf("accept socket: %s\n", client_fd);
|
||||
|
||||
sock_info(sock_root, client_fd);
|
||||
|
||||
char hello[] = "hello w0rld!\n";
|
||||
recv_client(sock_root, client_fd);
|
||||
send_client(sock_root, client_fd, hello, sizeof(hello));
|
||||
remove_sock_dir(sock_root, client_fd);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static int test_connect_recv(char const *sock_root, char const *sock_fd)
|
||||
{
|
||||
char sock_connect[96];
|
||||
snprintf(sock_connect, sizeof(sock_connect), "%s/%s/connect", sock_root, sock_fd);
|
||||
|
||||
int fd = open(sock_connect, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char host[] = "10.0.2.1:80";
|
||||
ssize_t n = write(fd, host, sizeof(host));
|
||||
(void)n;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
static void test_proto(char const *sock_root, char const *proto)
|
||||
{
|
||||
char proto_root[64];
|
||||
snprintf(proto_root, sizeof(proto_root), "%s/%s", sock_root, proto);
|
||||
|
||||
ls_socket_fs(proto_root);
|
||||
|
||||
char new_socket_path[64];
|
||||
snprintf(new_socket_path, sizeof(new_socket_path), "%s/new_socket", proto_root);
|
||||
|
||||
int fd = open(new_socket_path, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("open");
|
||||
abort();
|
||||
}
|
||||
|
||||
char sock_path[16];
|
||||
size_t n = read(fd, sock_path, sizeof(sock_path));
|
||||
sock_path[n-1] = '\0';
|
||||
close(fd);
|
||||
|
||||
ls_socket_fs(proto_root);
|
||||
|
||||
char sock_dir[64];
|
||||
snprintf(sock_dir, sizeof(sock_dir), "%s/%s", sock_root, sock_path);
|
||||
|
||||
ls_socket_fs(sock_dir);
|
||||
|
||||
test_bind_accept(sock_root, sock_path);
|
||||
// test_connect_recv(proto_root, sock_fd);
|
||||
|
||||
ls_socket_fs(sock_dir);
|
||||
|
||||
remove_sock_dir(sock_root, sock_path);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
char const *socket_fs = "/socket";
|
||||
|
||||
ls_socket_fs(socket_fs);
|
||||
test_proto(socket_fs, "tcp");
|
||||
test_proto(socket_fs, "udp");
|
||||
ls_socket_fs(socket_fs);
|
||||
}
|
3
repos/dde_linux/src/test/vfs_lxip/target.mk
Normal file
3
repos/dde_linux/src/test/vfs_lxip/target.mk
Normal file
@ -0,0 +1,3 @@
|
||||
TARGET = test-vfs_lxip
|
||||
SRC_CC = main.cc
|
||||
LIBS = posix
|
Loading…
Reference in New Issue
Block a user