mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 15:18:20 +00:00
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:
committed by
Christian Helmuth
parent
8312950e2f
commit
b0935ef9b2
@ -86,23 +86,126 @@ class Vfs::Tar_file_system : public File_system
|
||||
void *data() const { return (char *)this + BLOCK_LEN; }
|
||||
};
|
||||
|
||||
class Node;
|
||||
|
||||
class Tar_vfs_handle : public Vfs_handle
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
|
||||
Record const *_record;
|
||||
Node const *_node;
|
||||
|
||||
public:
|
||||
|
||||
Tar_vfs_handle(File_system &fs, Allocator &alloc, int status_flags, Record const *record)
|
||||
: Vfs_handle(fs, fs, alloc, status_flags), _record(record)
|
||||
Tar_vfs_handle(File_system &fs, Allocator &alloc, int status_flags,
|
||||
Node const *node)
|
||||
: Vfs_handle(fs, fs, alloc, status_flags), _node(node)
|
||||
{ }
|
||||
|
||||
Record const *record() const { return _record; }
|
||||
virtual Read_result read(char *dst, file_size count,
|
||||
file_size &out_count) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct Tar_vfs_file_handle : Tar_vfs_handle
|
||||
{
|
||||
using Tar_vfs_handle::Tar_vfs_handle;
|
||||
|
||||
Read_result read(char *dst, file_size count,
|
||||
file_size &out_count) override
|
||||
{
|
||||
file_size const record_size = _node->record->size();
|
||||
|
||||
file_size const record_bytes_left = record_size >= seek()
|
||||
? record_size - seek() : 0;
|
||||
|
||||
count = min(record_bytes_left, count);
|
||||
|
||||
char const *data = (char *)_node->record->data() + seek();
|
||||
|
||||
memcpy(dst, data, count);
|
||||
|
||||
out_count = count;
|
||||
return READ_OK;
|
||||
}
|
||||
};
|
||||
|
||||
struct Tar_vfs_dir_handle : Tar_vfs_handle
|
||||
{
|
||||
using Tar_vfs_handle::Tar_vfs_handle;
|
||||
|
||||
Read_result read(char *dst, file_size count,
|
||||
file_size &out_count) override
|
||||
{
|
||||
if (count < sizeof(Dirent))
|
||||
return READ_ERR_INVALID;
|
||||
|
||||
Dirent *dirent = (Dirent*)dst;
|
||||
|
||||
/* initialize */
|
||||
*dirent = Dirent();
|
||||
|
||||
file_offset index = seek() / sizeof(Dirent);
|
||||
|
||||
Node const *node = _node->lookup_child(index);
|
||||
|
||||
if (!node)
|
||||
return READ_OK;
|
||||
|
||||
dirent->fileno = (Genode::addr_t)node;
|
||||
|
||||
Record const *record = node->record;
|
||||
|
||||
while (record && (record->type() == Record::TYPE_HARDLINK)) {
|
||||
Tar_file_system &tar_fs = static_cast<Tar_file_system&>(fs());
|
||||
Node const *target = tar_fs.dereference(record->linked_name());
|
||||
record = target ? target->record : 0;
|
||||
}
|
||||
|
||||
if (record) {
|
||||
switch (record->type()) {
|
||||
case Record::TYPE_FILE:
|
||||
dirent->type = DIRENT_TYPE_FILE; break;
|
||||
case Record::TYPE_SYMLINK:
|
||||
dirent->type = DIRENT_TYPE_SYMLINK; break;
|
||||
case Record::TYPE_DIR:
|
||||
dirent->type = DIRENT_TYPE_DIRECTORY; break;
|
||||
|
||||
default:
|
||||
Genode::error("unhandled record type ", record->type(), " "
|
||||
"for ", node->name);
|
||||
}
|
||||
} else {
|
||||
/* If no record exists, assume it is a directory */
|
||||
dirent->type = DIRENT_TYPE_DIRECTORY;
|
||||
}
|
||||
|
||||
strncpy(dirent->name, node->name, sizeof(dirent->name));
|
||||
|
||||
out_count = sizeof(Dirent);
|
||||
|
||||
return READ_OK;
|
||||
}
|
||||
};
|
||||
|
||||
struct Tar_vfs_symlink_handle : Tar_vfs_handle
|
||||
{
|
||||
using Tar_vfs_handle::Tar_vfs_handle;
|
||||
|
||||
Read_result read(char *buf, file_size buf_size,
|
||||
file_size &out_count) override
|
||||
{
|
||||
Record const *record = _node->record;
|
||||
|
||||
file_size const count = min(buf_size, 100ULL);
|
||||
|
||||
memcpy(buf, record->linked_name(), count);
|
||||
|
||||
out_count = count;
|
||||
|
||||
return READ_OK;
|
||||
}
|
||||
};
|
||||
|
||||
struct Scanner_policy_path_element
|
||||
{
|
||||
static bool identifier_char(char c, unsigned /* i */)
|
||||
@ -430,52 +533,6 @@ class Vfs::Tar_file_system : public File_system
|
||||
return STAT_OK;
|
||||
}
|
||||
|
||||
Dirent_result dirent(char const *path, file_offset index, Dirent &out) override
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
|
||||
if (!node)
|
||||
return DIRENT_ERR_INVALID_PATH;
|
||||
|
||||
node = node->lookup_child(index);
|
||||
|
||||
if (!node) {
|
||||
out.type = DIRENT_TYPE_END;
|
||||
return DIRENT_OK;
|
||||
}
|
||||
|
||||
out.fileno = (Genode::addr_t)node;
|
||||
|
||||
Record const *record = node->record;
|
||||
|
||||
while (record && (record->type() == Record::TYPE_HARDLINK)) {
|
||||
Node const *target = dereference(record->linked_name());
|
||||
record = target ? target->record : 0;
|
||||
}
|
||||
|
||||
if (record) {
|
||||
switch (record->type()) {
|
||||
case Record::TYPE_FILE:
|
||||
out.type = DIRENT_TYPE_FILE; break;
|
||||
case Record::TYPE_SYMLINK:
|
||||
out.type = DIRENT_TYPE_SYMLINK; break;
|
||||
case Record::TYPE_DIR:
|
||||
out.type = DIRENT_TYPE_DIRECTORY; break;
|
||||
|
||||
default:
|
||||
Genode::error("unhandled record type ", record->type(), " "
|
||||
"for ", node->name);
|
||||
}
|
||||
} else {
|
||||
/* If no record exists, assume it is a directory */
|
||||
out.type = DIRENT_TYPE_DIRECTORY;
|
||||
}
|
||||
|
||||
strncpy(out.name, node->name, sizeof(out.name));
|
||||
|
||||
return DIRENT_OK;
|
||||
}
|
||||
|
||||
Unlink_result unlink(char const *path) override
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
@ -485,24 +542,6 @@ class Vfs::Tar_file_system : public File_system
|
||||
return UNLINK_ERR_NO_PERM;
|
||||
}
|
||||
|
||||
Readlink_result readlink(char const *path, char *buf, file_size buf_size,
|
||||
file_size &out_len) override
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
Record const *record = node ? node->record : 0;
|
||||
|
||||
if (!record || (record->type() != Record::TYPE_SYMLINK))
|
||||
return READLINK_ERR_NO_ENTRY;
|
||||
|
||||
file_size const count = min(buf_size, 100ULL);
|
||||
|
||||
memcpy(buf, record->linked_name(), count);
|
||||
|
||||
out_len = count;
|
||||
|
||||
return READLINK_OK;
|
||||
}
|
||||
|
||||
Rename_result rename(char const *from, char const *to) override
|
||||
{
|
||||
if (_root_node.lookup(from) || _root_node.lookup(to))
|
||||
@ -510,16 +549,6 @@ class Vfs::Tar_file_system : public File_system
|
||||
return RENAME_ERR_NO_ENTRY;
|
||||
}
|
||||
|
||||
Mkdir_result mkdir(char const *, unsigned) override
|
||||
{
|
||||
return MKDIR_ERR_NO_PERM;
|
||||
}
|
||||
|
||||
Symlink_result symlink(char const *, char const *) override
|
||||
{
|
||||
return SYMLINK_ERR_NO_ENTRY;
|
||||
}
|
||||
|
||||
file_size num_dirent(char const *path) override
|
||||
{
|
||||
return _cached_num_dirent.num_dirent(path);
|
||||
@ -548,17 +577,46 @@ class Vfs::Tar_file_system : public File_system
|
||||
return node ? path : 0;
|
||||
}
|
||||
|
||||
Open_result open(char const *path, unsigned, Vfs_handle **out_handle, Genode::Allocator& alloc) override
|
||||
Open_result open(char const *path, unsigned, Vfs_handle **out_handle,
|
||||
Genode::Allocator& alloc) override
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
if (!node || !node->record || node->record->type() != Record::TYPE_FILE)
|
||||
return OPEN_ERR_UNACCESSIBLE;
|
||||
|
||||
*out_handle = new (alloc) Tar_vfs_handle(*this, alloc, 0, node->record);
|
||||
*out_handle = new (alloc) Tar_vfs_file_handle(*this, alloc, 0, node);
|
||||
|
||||
return OPEN_OK;
|
||||
}
|
||||
|
||||
Opendir_result opendir(char const *path, bool create,
|
||||
Vfs_handle **out_handle,
|
||||
Genode::Allocator& alloc) override
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
|
||||
if (!node ||
|
||||
(node->record && (node->record->type() != Record::TYPE_DIR)))
|
||||
return OPENDIR_ERR_LOOKUP_FAILED;
|
||||
|
||||
*out_handle = new (alloc) Tar_vfs_dir_handle(*this, alloc, 0, node);
|
||||
|
||||
return OPENDIR_OK;
|
||||
}
|
||||
|
||||
Openlink_result openlink(char const *path, bool create,
|
||||
Vfs_handle **out_handle, Allocator &alloc)
|
||||
{
|
||||
Node const *node = dereference(path);
|
||||
if (!node || !node->record ||
|
||||
node->record->type() != Record::TYPE_SYMLINK)
|
||||
return OPENLINK_ERR_LOOKUP_FAILED;
|
||||
|
||||
*out_handle = new (alloc) Tar_vfs_symlink_handle(*this, alloc, 0, node);
|
||||
|
||||
return OPENLINK_OK;
|
||||
}
|
||||
|
||||
void close(Vfs_handle *vfs_handle) override
|
||||
{
|
||||
Tar_vfs_handle *tar_handle =
|
||||
@ -587,24 +645,17 @@ class Vfs::Tar_file_system : public File_system
|
||||
return WRITE_ERR_INVALID;
|
||||
}
|
||||
|
||||
Read_result read(Vfs_handle *vfs_handle, char *dst, file_size count,
|
||||
file_size &out_count) override
|
||||
Read_result complete_read(Vfs_handle *vfs_handle, char *dst,
|
||||
file_size count, file_size &out_count) override
|
||||
{
|
||||
Tar_vfs_handle const *handle = static_cast<Tar_vfs_handle *>(vfs_handle);
|
||||
out_count = 0;
|
||||
|
||||
file_size const record_size = handle->record()->size();
|
||||
Tar_vfs_handle *handle = static_cast<Tar_vfs_handle *>(vfs_handle);
|
||||
|
||||
file_size const record_bytes_left = record_size >= handle->seek()
|
||||
? record_size - handle->seek() : 0;
|
||||
if (!handle)
|
||||
return READ_ERR_INVALID;
|
||||
|
||||
count = min(record_bytes_left, count);
|
||||
|
||||
char const *data = (char *)handle->record()->data() + handle->seek();
|
||||
|
||||
memcpy(dst, data, count);
|
||||
|
||||
out_count = count;
|
||||
return READ_OK;
|
||||
return handle->read(dst, count, out_count);
|
||||
}
|
||||
|
||||
Ftruncate_result ftruncate(Vfs_handle *handle, file_size) override
|
||||
|
Reference in New Issue
Block a user