Support select in libc VFS plugin by read_ready()

This commit is contained in:
Christian Helmuth 2017-02-01 11:28:15 +01:00 committed by Norman Feske
parent ba1bd071df
commit f9389109bf
22 changed files with 174 additions and 30 deletions

View File

@ -470,6 +470,8 @@ class Vfs::Rump_file_system : public File_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override
{
Rump_vfs_handle *handle =
@ -525,7 +527,8 @@ class Rump_factory : public Vfs::File_system_factory
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node config) override
Genode::Xml_node config,
Vfs::Io_response_handler &) override
{
return new (alloc) Vfs::Rump_file_system(config);
}
@ -538,10 +541,11 @@ extern "C" Vfs::File_system_factory *vfs_file_system_factory(void)
{
Vfs::File_system *create(Genode::Env &env,
Genode::Allocator &alloc,
Genode::Xml_node node) override
Genode::Xml_node node,
Vfs::Io_response_handler &io_handler) override
{
static Rump_factory factory(env, alloc);
return factory.create(env, alloc, node);
return factory.create(env, alloc, node, io_handler);
}
};

View File

@ -1,6 +1,6 @@
set build_components {
core init drivers/timer
test/libc_select
core init drivers/timer server/terminal_crosslink
test/libc_select test/libc_counter
}
build $build_components
@ -29,19 +29,33 @@ set config {
<resource name="RAM" quantum="2M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="terminal_crosslink">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Terminal"/> </provides>
</start>
<start name="test-libc_counter-source">
<resource name="RAM" quantum="8M"/>
<config ld_verbose="yes">
<vfs>
<dir name="dev"> <terminal/> <log/> </dir>
</vfs>
<libc stdin="/dev/terminal" stdout="/dev/terminal" stderr="/dev/log"/>
</config>
</start>
<start name="test-libc_select">
<resource name="RAM" quantum="4M"/>
<config>
<arg value="test-libc_select"/>
<arg value="/dev/log"/>
<arg value="/dev/terminal"/>
<!--
<arg value=":"/>
<arg value="/dev/log"/>
-->
<vfs>
<dir name="dev">
<log/> <null/> <zero/>
<log/> <null/> <zero/> <terminal/>
</dir>
</vfs>
<libc stdin="/dev/null" stdout="/dev/log" stderr="/dev/log"/>
@ -53,8 +67,8 @@ set config {
install_config $config
set boot_modules {
core init timer
test-libc_select
core init timer terminal_crosslink
test-libc_counter-source test-libc_select
ld.lib.so libc.lib.so libm.lib.so stdcxx.lib.so pthread.lib.so
libc_pipe.lib.so
}

View File

@ -2,11 +2,13 @@
* \brief libc file operations
* \author Christian Prochaska
* \author Norman Feske
* \author Emery Hemingway
* \author Christian Helmuth
* \date 2010-01-21
*/
/*
* Copyright (C) 2010-2013 Genode Labs GmbH
* Copyright (C) 2010-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.
@ -216,8 +218,10 @@ extern "C" int chdir(const char *path)
}
extern "C" int _close(int libc_fd) {
FD_FUNC_WRAPPER(close, libc_fd); }
extern "C" int _close(int libc_fd)
{
FD_FUNC_WRAPPER(close, libc_fd);
}
extern "C" int close(int libc_fd) { return _close(libc_fd); }
@ -538,8 +542,10 @@ extern "C" int pipe(int pipefd[2])
}
extern "C" ssize_t _read(int libc_fd, void *buf, ::size_t count) {
FD_FUNC_WRAPPER(read, libc_fd, buf, count); }
extern "C" ssize_t _read(int libc_fd, void *buf, ::size_t count)
{
FD_FUNC_WRAPPER(read, libc_fd, buf, count);
}
extern "C" ssize_t read(int libc_fd, void *buf, ::size_t count)

View File

@ -1,11 +1,12 @@
/*
* \brief File-operation utilities
* \author Christian Helmuth
* \author Emery Hemingway
* \date 2015-06-30
*/
/*
* Copyright (C) 2015 Genode Labs GmbH
* Copyright (C) 2015-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.
@ -72,5 +73,4 @@ static inline Libc::File_descriptor *libc_fd_to_fd(int libc_fd, const char *func
#define FNAME_FUNC_WRAPPER(func_name, path, ...) \
FNAME_FUNC_WRAPPER_GENERIC(return, func_name, path, ##__VA_ARGS__ )
#endif /* _LIBC_FILE_H_ */

View File

@ -1,11 +1,13 @@
/*
* \brief Libc plugin for using a process-local virtual file system
* \author Norman Feske
* \date 2014-04-09
* \brief Libc plugin for using a process-local virtual file system
* \author Norman Feske
* \author Christian Helmuth
* \author Emery Hemingway
* \date 2014-04-09
*/
/*
* Copyright (C) 2014-2016 Genode Labs GmbH
* Copyright (C) 2014-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.
@ -36,7 +38,7 @@
#include <vfs_plugin.h>
/* libc-internal includes */
#include <libc_mem_alloc.h>
#include "libc_mem_alloc.h"
#include "libc_errno.h"
#include "task.h"
@ -725,3 +727,72 @@ int Libc::Vfs_plugin::munmap(void *addr, ::size_t)
Libc::mem_alloc()->free(addr);
return 0;
}
bool Libc::Vfs_plugin::supports_select(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
/* return true if any file descriptor (which is set) belongs to the VFS */
for (int fd = 0; fd < nfds; ++fd) {
if (FD_ISSET(fd, readfds) || FD_ISSET(fd, writefds) || FD_ISSET(fd, exceptfds)) {
Libc::File_descriptor *fdo =
Libc::file_descriptor_allocator()->find_by_libc_fd(fd);
if (fdo && (fdo->plugin == this))
return true;
}
}
return false;
}
int Libc::Vfs_plugin::select(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
int nready = 0;
fd_set const in_readfds = *readfds;
fd_set const in_writefds = *writefds;
/* XXX exceptfds not supported */
/* clear fd sets */
FD_ZERO(readfds);
FD_ZERO(writefds);
FD_ZERO(exceptfds);
for (int fd = 0; fd < nfds; ++fd) {
Libc::File_descriptor *fdo =
Libc::file_descriptor_allocator()->find_by_libc_fd(fd);
/* handle only fds that belong to this plugin */
if (!fdo || (fdo->plugin != this))
continue;
Vfs::Vfs_handle *handle = vfs_handle(fdo);
if (!handle) continue;
if (FD_ISSET(fd, &in_readfds)) {
if (handle->fs().read_ready(handle)) {
FD_SET(fd, readfds);
++nready;
} else {
// handle->fs().notify_read_ready(handle);
}
}
if (FD_ISSET(fd, &in_writefds)) {
if (true /* XXX always writeable */) {
FD_SET(fd, writefds);
++nready;
}
}
/* XXX exceptfds not supported */
}
return nready;
}

View File

@ -1,11 +1,13 @@
/*
* \brief Libc plugin for using a process-local virtual file system
* \author Norman Feske
* \date 2014-04-09
* \brief Libc plugin for using a process-local virtual file system
* \author Norman Feske
* \author Emery Hemingway
* \author Christian Helmuth
* \date 2014-04-09
*/
/*
* Copyright (C) 2014-2016 Genode Labs GmbH
* Copyright (C) 2014-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.
@ -71,9 +73,6 @@ class Libc::Vfs_plugin : public Libc::Plugin
public:
/**
* Constructor
*/
Vfs_plugin(Libc::Env &env, Genode::Allocator &alloc)
:
_alloc(alloc), _root_dir(env.vfs())
@ -96,7 +95,7 @@ class Libc::Vfs_plugin : public Libc::Plugin
});
}
~Vfs_plugin() { }
~Vfs_plugin() final { }
bool supports_access(const char *, int) override { return true; }
bool supports_mkdir(const char *, mode_t) override { return true; }
@ -109,6 +108,10 @@ class Libc::Vfs_plugin : public Libc::Plugin
bool supports_unlink(const char *) override { return true; }
bool supports_mmap() override { return true; }
bool supports_select(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout) override;
Libc::File_descriptor *open(const char *, int, int libc_fd);
Libc::File_descriptor *open(const char *path, int flags) override
@ -138,6 +141,7 @@ class Libc::Vfs_plugin : public Libc::Plugin
ssize_t write(Libc::File_descriptor *, const void *, ::size_t ) override;
void *mmap(void *, ::size_t, int, int, Libc::File_descriptor *, ::off_t) override;
int munmap(void *, ::size_t) override;
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) override;
};
#endif

View File

@ -21,7 +21,8 @@
struct Jitterentropy_factory : Vfs::File_system_factory
{
Vfs::File_system *create(Genode::Env&, Genode::Allocator &alloc,
Genode::Xml_node node) override
Genode::Xml_node node,
Vfs::Io_response_handler &) override
{
return new (alloc) Jitterentropy_file_system(node);
}

View File

@ -98,6 +98,8 @@ class Jitterentropy_file_system : public Vfs::Single_file_system
return READ_OK;
}
bool read_ready(Vfs::Vfs_handle *) override { return true; }
};
#endif /* _JITTERENTROPY_FILE_SYSTEM_H_ */

View File

@ -1,11 +1,13 @@
/*
* \brief Directory file system
* \author Norman Feske
* \author Emery Hemingway
* \author Christian Helmuth
* \date 2012-04-23
*/
/*
* Copyright (C) 2011-2016 Genode Labs GmbH
* Copyright (C) 2011-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.
@ -601,6 +603,14 @@ class Vfs::Dir_file_system : public File_system
{
return FTRUNCATE_ERR_NO_PERM;
}
bool read_ready(Vfs_handle *handle) override
{
if (&handle->fs() == this)
return true;
return handle->fs().read_ready(handle);
}
};
#endif /* _INCLUDE__VFS__DIR_FILE_SYSTEM_H_ */

View File

@ -76,6 +76,11 @@ struct Vfs::File_io_service
file_size &out_count)
{ return read(vfs_handle, dst, count, out_count); }
/**
* Return true if the handle has readable data
*/
virtual bool read_ready(Vfs_handle *) = 0;
/***************
** Ftruncate **

View File

@ -312,6 +312,8 @@ class Vfs::Block_file_system : public Single_file_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;

View File

@ -629,6 +629,8 @@ class Vfs::Fs_file_system : public File_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override
{
Fs_vfs_handle const *handle = static_cast<Fs_vfs_handle *>(vfs_handle);

View File

@ -96,6 +96,8 @@ class Vfs::Inline_file_system : public Single_file_system
out_count = num_bytes;
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__INLINE_FILE_SYSTEM_H_ */

View File

@ -90,6 +90,8 @@ class Vfs::Log_file_system : public Single_file_system
out_count = 0;
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return false; }
};
#endif /* _INCLUDE__VFS__LOG_FILE_SYSTEM_H_ */

View File

@ -53,6 +53,8 @@ struct Vfs::Null_file_system : Single_file_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return false; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;

View File

@ -764,6 +764,8 @@ class Vfs::Ram_file_system : public Vfs::File_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size len) override
{
if ((vfs_handle->status_flags() & OPEN_MODE_ACCMODE) == OPEN_MODE_RDONLY)

View File

@ -142,6 +142,8 @@ class Vfs::Rom_file_system : public Single_file_system
out_count = num_bytes;
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__ROM_FILE_SYSTEM_H_ */

View File

@ -98,6 +98,8 @@ class Vfs::Rtc_file_system : public Single_file_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__RTC_FILE_SYSTEM_H_ */

View File

@ -82,6 +82,8 @@ class Vfs::Symlink_file_system : public Single_file_system
Read_result read(Vfs_handle *, char *, file_size, file_size &) override {
return READ_ERR_INVALID; }
bool read_ready(Vfs_handle *) override { return false; }
Ftruncate_result ftruncate(Vfs_handle *, file_size) override {
return FTRUNCATE_ERR_NO_PERM; }
};

View File

@ -611,6 +611,8 @@ class Vfs::Tar_file_system : public File_system
{
return FTRUNCATE_ERR_NO_PERM;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__TAR_FILE_SYSTEM_H_ */

View File

@ -101,6 +101,11 @@ class Vfs::Terminal_file_system : public Single_file_system
return _read(vfs_handle, dst, count, out_count);
}
bool read_ready(Vfs_handle *) override
{
return _terminal.avail();
}
Ftruncate_result ftruncate(Vfs_handle *vfs_handle, file_size) override
{
return FTRUNCATE_OK;

View File

@ -53,6 +53,8 @@ struct Vfs::Zero_file_system : Single_file_system
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__ZERO_FILE_SYSTEM_H_ */