VFS: nonblocking interface

The VFS library can be used in single-threaded or multi-threaded
environments and depending on that, signals are handled by the same thread
which uses the VFS library or possibly by a different thread. If a VFS
plugin needs to block to wait for a signal, there is currently no way
which works reliably in both environments.

For this reason, this commit makes the interface of the VFS library
nonblocking, similar to the File_system session interface.

The most important changes are:

- Directories are created and opened with the 'opendir()' function and the
  directory entries are read with the recently introduced 'queue_read()'
  and 'complete_read()' functions.

- Symbolic links are created and opened with the 'openlink()' function and
  the link target is read with the 'queue_read()' and 'complete_read()'
  functions and written with the 'write()' function.

- The 'write()' function does not wait for signals anymore. This can have
  the effect that data written by a VFS library user has not been
  processed by a file system server yet when the library user asks for the
  size of the file or closes it (both done with RPC functions at the file
  system server). For this reason, a user of the VFS library should
  request synchronization before calling 'stat()' or 'close()'. To make
  sure that a file system server has processed all write request packets
  which a client submitted before the synchronization request,
  synchronization is now requested at the file system server with a
  synchronization packet instead of an RPC function. Because of this
  change, the synchronization interface of the VFS library is now split
  into 'queue_sync()' and 'complete_sync()' functions.

Fixes #2399
This commit is contained in:
Christian Prochaska
2017-08-15 20:51:53 +02:00
committed by Christian Helmuth
parent 8312950e2f
commit b0935ef9b2
49 changed files with 4361 additions and 2307 deletions

View File

@ -28,6 +28,63 @@ class Vfs::Rtc_file_system : public Single_file_system
Rtc::Connection _rtc;
class Rtc_vfs_handle : public Single_vfs_handle
{
private:
Rtc::Connection &_rtc;
public:
Rtc_vfs_handle(Directory_service &ds,
File_io_service &fs,
Genode::Allocator &alloc,
Rtc::Connection &rtc)
: Single_vfs_handle(ds, fs, alloc, 0),
_rtc(rtc) { }
/**
* Read the current time from the Rtc session
*
* On each read the current time is queried and afterwards formated
* as '%Y-%m-%d %H:%M\n'.
*/
Read_result read(char *dst, file_size count,
file_size &out_count) override
{
enum { TIMESTAMP_LEN = 17 };
if (seek() >= TIMESTAMP_LEN) {
out_count = 0;
return READ_OK;
}
Rtc::Timestamp ts = _rtc.current_time();
char buf[TIMESTAMP_LEN+1];
char *b = buf;
unsigned n = Genode::snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u\n",
ts.year, ts.month, ts.day, ts.hour, ts.minute);
n -= seek();
b += seek();
file_size len = count > n ? n : count;
Genode::memcpy(dst, b, len);
out_count = len;
return READ_OK;
}
Write_result write(char const *src, file_size count,
file_size &out_count) override
{
return WRITE_ERR_IO;
}
bool read_ready() { return true; }
};
public:
Rtc_file_system(Genode::Env &env,
@ -46,6 +103,18 @@ class Vfs::Rtc_file_system : public Single_file_system
** Directory-service interface **
*********************************/
Open_result open(char const *path, unsigned,
Vfs_handle **out_handle,
Allocator &alloc) override
{
if (!_single_file(path))
return OPEN_ERR_UNACCESSIBLE;
*out_handle = new (alloc) Rtc_vfs_handle(*this, *this, alloc,
_rtc);
return OPEN_OK;
}
Stat_result stat(char const *path, Stat &out) override
{
Stat_result result = Single_file_system::stat(path, out);
@ -53,53 +122,6 @@ class Vfs::Rtc_file_system : public Single_file_system
return result;
}
/********************************
** File I/O service interface **
********************************/
Write_result write(Vfs_handle *, char const *, file_size,
file_size &) override
{
return WRITE_ERR_IO;
}
/**
* Read the current time from the Rtc session
*
* On each read the current time is queried and afterwards formated
* as '%Y-%m-%d %H:%M\n'.
*/
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
file_size &out_count) override
{
enum { TIMESTAMP_LEN = 17 };
file_size seek = vfs_handle->seek();
if (seek >= TIMESTAMP_LEN) {
out_count = 0;
return READ_OK;
}
Rtc::Timestamp ts = _rtc.current_time();
char buf[TIMESTAMP_LEN+1];
char *b = buf;
unsigned n = Genode::snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u\n",
ts.year, ts.month, ts.day, ts.hour, ts.minute);
n -= seek;
b += seek;
file_size len = count > n ? n : count;
Genode::memcpy(dst, b, len);
out_count = len;
return READ_OK;
}
bool read_ready(Vfs_handle *) override { return true; }
};
#endif /* _INCLUDE__VFS__RTC_FILE_SYSTEM_H_ */