mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-20 17:52:52 +00:00
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:
parent
260fc30be3
commit
800b4e44b1
@ -380,7 +380,7 @@ static void poll_all()
|
||||
{
|
||||
Vfs::Lxip_vfs_file_handle *handle = le->object();
|
||||
if (handle->file)
|
||||
handle->file->poll(true, handle->context);
|
||||
handle->file->poll(true, handle->context());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ class Vfs_audit::File_system : public Vfs::File_system
|
||||
void sync_state()
|
||||
{
|
||||
audit->seek(Vfs_handle::seek());
|
||||
audit->context = context;
|
||||
audit->context(context());
|
||||
}
|
||||
|
||||
Handle(Vfs_audit::File_system &fs,
|
||||
|
@ -369,7 +369,7 @@ struct Lwip::Socket_dir : Lwip::Directory
|
||||
h; h = h->next())
|
||||
{
|
||||
if (h->kind & mask) {
|
||||
io_handler.handle_io_response(h->context);
|
||||
io_handler.handle_io_response(h->context());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1609,7 +1609,7 @@ class Lwip::File_system final : public Vfs::File_system
|
||||
udp_dir.notify();
|
||||
|
||||
nameserver_handles.for_each([&] (Lwip_nameserver_handle &h) {
|
||||
io_handler.handle_io_response(h.context); });
|
||||
io_handler.handle_io_response(h.context()); });
|
||||
}
|
||||
|
||||
Vfs_netif(Vfs::Env &vfs_env,
|
||||
|
@ -314,7 +314,7 @@ class Vfs::Dir_file_system : public File_system
|
||||
vfs_handle.seek(index * sizeof(Dirent));
|
||||
|
||||
/* forward the handle context */
|
||||
vfs_handle.context = dir_vfs_handle->context;
|
||||
vfs_handle.context(dir_vfs_handle->context());
|
||||
|
||||
result = vfs_handle.fs().queue_read(&vfs_handle, sizeof(Dirent));
|
||||
}
|
||||
@ -951,7 +951,7 @@ class Vfs::Dir_file_system : public File_system
|
||||
|
||||
auto f = [&result, dir_vfs_handle] (Dir_vfs_handle::Subdir_handle_element &e) {
|
||||
/* forward the handle context */
|
||||
e.vfs_handle.context = dir_vfs_handle->context;
|
||||
e.vfs_handle.context(dir_vfs_handle->context());
|
||||
e.synced = false;
|
||||
|
||||
if (!e.vfs_handle.fs().queue_sync(&e.vfs_handle)) {
|
||||
|
@ -26,6 +26,13 @@ namespace Vfs{
|
||||
|
||||
class Vfs::Vfs_handle
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Opaque handle context
|
||||
*/
|
||||
struct Context { };
|
||||
|
||||
private:
|
||||
|
||||
Directory_service &_ds;
|
||||
@ -33,6 +40,7 @@ class Vfs::Vfs_handle
|
||||
Genode::Allocator &_alloc;
|
||||
int _status_flags;
|
||||
file_size _seek = 0;
|
||||
Context *_context = nullptr;
|
||||
|
||||
/*
|
||||
* Noncopyable
|
||||
@ -42,13 +50,6 @@ class Vfs::Vfs_handle
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Opaque handle context
|
||||
*/
|
||||
struct Context : List<Context>::Element { };
|
||||
|
||||
Context *context = nullptr;
|
||||
|
||||
class Guard
|
||||
{
|
||||
private:
|
||||
@ -89,6 +90,8 @@ class Vfs::Vfs_handle
|
||||
Directory_service &ds() { return _ds; }
|
||||
File_io_service &fs() { return _fs; }
|
||||
Allocator &alloc() { return _alloc; }
|
||||
void context(Context *context) { _context = context; }
|
||||
Context *context() const { return _context; }
|
||||
|
||||
int status_flags() const { return _status_flags; }
|
||||
|
||||
@ -125,7 +128,7 @@ class Vfs::Vfs_watch_handle
|
||||
/**
|
||||
* Opaque handle context
|
||||
*/
|
||||
struct Context : List<Context>::Element { };
|
||||
struct Context { };
|
||||
|
||||
private:
|
||||
|
||||
|
@ -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);
|
||||
|
@ -44,15 +44,15 @@ class Vfs::Terminal_file_system : public Single_file_system
|
||||
{
|
||||
Genode::Entrypoint &_ep;
|
||||
Io_response_handler &_io_handler;
|
||||
Vfs_handle::Context *_context = nullptr;
|
||||
Vfs_handle *_handle = nullptr;
|
||||
|
||||
Post_signal_hook(Genode::Entrypoint &ep,
|
||||
Io_response_handler &io_handler)
|
||||
: _ep(ep), _io_handler(io_handler) { }
|
||||
|
||||
void arm(Vfs_handle::Context *context)
|
||||
void arm(Vfs_handle &handle)
|
||||
{
|
||||
_context = context;
|
||||
_handle = &handle;
|
||||
_ep.schedule_post_signal_hook(this);
|
||||
}
|
||||
|
||||
@ -65,8 +65,8 @@ class Vfs::Terminal_file_system : public Single_file_system
|
||||
* this object in a signal handler.
|
||||
*/
|
||||
|
||||
_io_handler.handle_io_response(_context);
|
||||
_context = nullptr;
|
||||
_io_handler.handle_io_response(_handle ? _handle->context() : nullptr);
|
||||
_handle = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -88,7 +88,7 @@ class Vfs::Terminal_file_system : public Single_file_system
|
||||
void _handle_read_avail()
|
||||
{
|
||||
_handle_registry.for_each([this] (Registered_handle &h) {
|
||||
_post_signal_hook.arm(h.context);
|
||||
_post_signal_hook.arm(h);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ struct Vfs_server::Symlink : Io_node
|
||||
: Io_node(space, link_path, mode, node_io_handler)
|
||||
{
|
||||
assert_openlink(vfs.openlink(link_path, create, &_handle, alloc));
|
||||
_handle->context = &context();
|
||||
_handle->context(&context());
|
||||
}
|
||||
|
||||
~Symlink() { _handle->close(); }
|
||||
@ -446,7 +446,7 @@ class Vfs_server::File : public Io_node
|
||||
|
||||
assert_open(vfs.open(file_path, vfs_mode, &_handle, alloc));
|
||||
_leaf_path = vfs.leaf_path(path());
|
||||
_handle->context = &context();
|
||||
_handle->context(&context());
|
||||
}
|
||||
|
||||
~File() { _handle->close(); }
|
||||
@ -499,7 +499,7 @@ struct Vfs_server::Directory : Io_node
|
||||
: Io_node(space, dir_path, READ_ONLY, node_io_handler)
|
||||
{
|
||||
assert_opendir(vfs.opendir(dir_path, create, &_handle, alloc));
|
||||
_handle->context = &context();
|
||||
_handle->context(&context());
|
||||
}
|
||||
|
||||
~Directory() { _handle->close(); }
|
||||
|
@ -78,7 +78,8 @@ struct Noux::Vfs_dataspace
|
||||
return;
|
||||
|
||||
Vfs_handle_context read_context;
|
||||
file->context = &read_context;
|
||||
Vfs::Vfs_handle::Guard guard(file);
|
||||
file->context(&read_context);
|
||||
|
||||
ds = ram.alloc(stat_out.size);
|
||||
|
||||
@ -124,7 +125,6 @@ struct Noux::Vfs_dataspace
|
||||
}
|
||||
|
||||
rm.detach(addr);
|
||||
root_dir.close(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,8 +646,9 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
vfs_io_waiter.wait_for_io();
|
||||
|
||||
Vfs_handle_context read_context;
|
||||
Vfs::Vfs_handle::Guard guard(symlink_handle);
|
||||
|
||||
symlink_handle->context = &read_context;
|
||||
symlink_handle->context(&read_context);
|
||||
|
||||
Vfs::file_size out_count = 0;
|
||||
Vfs::File_io_service::Read_result read_result;
|
||||
@ -669,8 +670,6 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
r.wakeup();
|
||||
});
|
||||
|
||||
symlink_handle->ds().close(symlink_handle);
|
||||
|
||||
_sysio.readlink_out.count = out_count;
|
||||
|
||||
break;
|
||||
@ -781,8 +780,9 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
vfs_io_waiter.wait_for_io();
|
||||
|
||||
Vfs_handle_context sync_context;
|
||||
Vfs::Vfs_handle::Guard guard(symlink_handle);
|
||||
|
||||
symlink_handle->context = &sync_context;
|
||||
symlink_handle->context(&sync_context);
|
||||
|
||||
while (symlink_handle->fs().complete_sync(symlink_handle) ==
|
||||
Vfs::File_io_service::SYNC_QUEUED)
|
||||
@ -793,8 +793,6 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
r.wakeup();
|
||||
});
|
||||
|
||||
symlink_handle->ds().close(symlink_handle);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -913,8 +911,9 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
vfs_io_waiter.wait_for_io();
|
||||
|
||||
Vfs_handle_context sync_context;
|
||||
Vfs::Vfs_handle::Guard guard(sync_handle);
|
||||
|
||||
sync_handle->context = &sync_context;
|
||||
sync_handle->context(&sync_context);
|
||||
|
||||
while (sync_handle->fs().complete_sync(sync_handle) ==
|
||||
Vfs::File_io_service::SYNC_QUEUED)
|
||||
@ -925,8 +924,6 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
|
||||
r.wakeup();
|
||||
});
|
||||
|
||||
sync_handle->ds().close(sync_handle);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user