VFS: Replace global response handlers with local handlers

Replace the I/O response handler that is passed to the VFS at
construction with an object that is dynamically attached to handles.
This object shall also accept read-ready notifications, and plugins are
encouraged to keep handles awaiting ready-ready notifications separate
from handles that await I/O progress.

Replace the use of handle lists in plugins with handle queues, this
makes the code easier to understand and the ordering of notifications to
the application more explicit.

These changes replace the use of the Post_signal_hook from all VFS
plugins, applications must assume that read-ready and I/O notifications
occur during I/O signal dispatch and use an Io_progress_handler at its
entrypoints to defer response until after signal dispatching.

Fix #3257
This commit is contained in:
Emery Hemingway
2019-03-25 15:41:43 +01:00
committed by Christian Helmuth
parent e2ff776b35
commit a635873568
27 changed files with 1397 additions and 1341 deletions

View File

@@ -532,7 +532,7 @@ class Genode::File_content
};
class Genode::Watcher : Interface, Vfs::Vfs_watch_handle::Context
class Genode::Watcher
{
private:
@@ -542,14 +542,17 @@ class Genode::Watcher : Interface, Vfs::Vfs_watch_handle::Context
Watcher(Watcher const &);
Watcher &operator = (Watcher const &);
Vfs::Vfs_watch_handle mutable *_handle = nullptr;
Vfs::Vfs_watch_handle mutable *_handle { nullptr };
void _watch(Vfs::File_system &fs, Allocator &alloc, Directory::Path const path)
void _watch(Vfs::File_system &fs, Allocator &alloc, Directory::Path const path,
Vfs::Watch_response_handler &handler)
{
Vfs::Directory_service::Watch_result res =
fs.watch(path.string(), &_handle, alloc);
if (res != Vfs::Directory_service::WATCH_OK)
if (res == Vfs::Directory_service::WATCH_OK)
_handle->handler(&handler);
else
error("failed to watch '", path, "'");
}
@@ -560,21 +563,21 @@ class Genode::Watcher : Interface, Vfs::Vfs_watch_handle::Context
public:
Watcher(Directory const &dir, Directory::Path const &rel_path)
Watcher(Directory const &dir, Directory::Path const &rel_path,
Vfs::Watch_response_handler &handler)
{
_watch(_mutable(dir)._fs, _mutable(dir)._alloc,
Directory::join(dir._path, rel_path));
_handle->context(this);
Directory::join(dir._path, rel_path), handler);
}
~Watcher() { _handle->fs().close(_handle); }
virtual void handle_watch_notification() { }
};
template <typename T>
class Genode::Watch_handler : Watcher
class Genode::Watch_handler : public Vfs::Watch_response_handler,
private Watcher
{
private:
@@ -586,10 +589,10 @@ class Genode::Watch_handler : Watcher
Watch_handler(Directory &dir, Directory::Path const &rel_path,
T &obj, void (T::*member)())
:
Watcher(dir, rel_path), _obj(obj), _member(member)
Watcher(dir, rel_path, *this), _obj(obj), _member(member)
{ }
void handle_watch_notification() override { (_obj.*_member)(); }
void watch_response() override { (_obj.*_member)(); }
};
#endif /* _INCLUDE__GEMS__VFS_H_ */