Reduce Vfs::Vfs_handle::Context to empty struct type

The "Vfs::Vfs_handle" type should not contain any public members that
can be initialized by the VFS internally and by the application, so
remove inheritance from the "Genode::list::Element" class. The VFS
plugins must instead use lists of "Vfs::Vfs_handle" sub-classes, the
lifetime of which are always managed by the plugin.

Ref #3036
This commit is contained in:
Emery Hemingway
2018-11-11 23:47:15 +01:00
committed by Norman Feske
parent 260fc30be3
commit 800b4e44b1
10 changed files with 65 additions and 59 deletions

View File

@ -70,16 +70,19 @@ class Vfs::Fs_file_system : public File_system
struct Fs_vfs_handle : Vfs_handle,
private ::File_system::Node,
private Handle_space::Element,
private List<Fs_vfs_handle>::Element,
private Handle_state
{
friend Genode::Id_space<::File_system::Node>;
friend Genode::List<Fs_vfs_handle>;
using Genode::List<Fs_vfs_handle>::Element::next;
using Handle_state::queued_read_state;
using Handle_state::queued_read_packet;
using Handle_state::queued_sync_packet;
using Handle_state::queued_sync_state;
using Handle_state::read_ready_state;
friend class Genode::Id_space<::File_system::Node>;
::File_system::Connection &_fs;
Io_response_handler &_io_handler;
@ -345,11 +348,14 @@ class Vfs::Fs_file_system : public File_system
}
};
struct Fs_vfs_watch_handle : Vfs_watch_handle,
private ::File_system::Node,
private Handle_space::Element
struct Fs_vfs_watch_handle final : Vfs_watch_handle,
private ::File_system::Node,
private Handle_space::Element,
private List<Fs_vfs_watch_handle>::Element
{
friend class Genode::Id_space<::File_system::Node>;
friend Genode::Id_space<::File_system::Node>;
friend Genode::List<Fs_vfs_watch_handle>;
using Genode::List<Fs_vfs_watch_handle>::Element::next;
::File_system::Watch_handle const fs_handle;
@ -369,10 +375,9 @@ class Vfs::Fs_file_system : public File_system
Genode::Entrypoint &_ep;
Io_response_handler &_io_handler;
Watch_response_handler &_watch_handler;
List<Vfs_handle::Context> _context_list { };
Lock _list_lock { };
bool _notify_all { false };
List<Fs_vfs_handle> _io_handle_list { };
Lock _list_lock { };
bool _notify_all { false };
Post_signal_hook(Vfs::Env &env)
:
@ -381,7 +386,7 @@ class Vfs::Fs_file_system : public File_system
_watch_handler(env.watch_handler())
{ }
void arm_io_event(Vfs_handle::Context *context)
void arm_io_event(Fs_vfs_handle *context)
{
if (!context) {
Lock::Guard list_guard(_list_lock);
@ -389,7 +394,7 @@ class Vfs::Fs_file_system : public File_system
} else {
Lock::Guard list_guard(_list_lock);
for (Vfs_handle::Context *list_context = _context_list.first();
for (Fs_vfs_handle *list_context = _io_handle_list.first();
list_context;
list_context = list_context->next())
{
@ -399,7 +404,7 @@ class Vfs::Fs_file_system : public File_system
}
}
_context_list.insert(context);
_io_handle_list.insert(context);
}
_ep.schedule_post_signal_hook(this);
@ -407,7 +412,7 @@ class Vfs::Fs_file_system : public File_system
void function() override
{
Vfs_handle::Context *context = nullptr;
Fs_vfs_handle *handle = nullptr;
do {
bool notify_all = false;
@ -415,20 +420,23 @@ class Vfs::Fs_file_system : public File_system
{
Lock::Guard list_guard(_list_lock);
context = _context_list.first();
_context_list.remove(context);
handle = _io_handle_list.first();
_io_handle_list.remove(handle);
if (!context && _notify_all) {
if (!handle && _notify_all) {
notify_all = true;
_notify_all = false;
}
}
if (context || notify_all)
_io_handler.handle_io_response(context);
if (handle) {
_io_handler.handle_io_response(handle->context());
} else if (notify_all) {
_io_handler.handle_io_response(nullptr);
}
/* done if no contexts and all notified */
} while (context);
} while (handle);
}
};
@ -544,13 +552,13 @@ class Vfs::Fs_file_system : public File_system
switch (packet.operation()) {
case Packet_descriptor::READ_READY:
handle.read_ready_state = Handle_state::Read_ready_state::READY;
_post_signal_hook.arm_io_event(handle.context);
_post_signal_hook.arm_io_event(&handle);
break;
case Packet_descriptor::READ:
handle.queued_read_packet = packet;
handle.queued_read_state = Handle_state::Queued_state::ACK;
_post_signal_hook.arm_io_event(handle.context);
_post_signal_hook.arm_io_event(&handle);
break;
case Packet_descriptor::WRITE:
@ -564,7 +572,7 @@ class Vfs::Fs_file_system : public File_system
case Packet_descriptor::SYNC:
handle.queued_sync_packet = packet;
handle.queued_sync_state = Handle_state::Queued_state::ACK;
_post_signal_hook.arm_io_event(handle.context);
_post_signal_hook.arm_io_event(&handle);
break;
case Packet_descriptor::CONTENT_CHANGED:
@ -896,8 +904,6 @@ class Vfs::Fs_file_system : public File_system
void close(Vfs_handle *vfs_handle) override
{
if (!vfs_handle) return;
Lock::Guard guard(_lock);
Fs_vfs_handle *fs_handle = static_cast<Fs_vfs_handle *>(vfs_handle);