From d649451c3d75882d8f5bea5351f0cc5edc3749ad Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 28 Jun 2017 14:19:26 +0200 Subject: [PATCH] fs_rom: trigger deferred ROM-update signal This patch ensures that fs_rom delivers a ROM-update notification in the case where the underlying file was changed in-between requesting the initial ROM content and registering the signal handler. --- repos/os/src/server/fs_rom/main.cc | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/repos/os/src/server/fs_rom/main.cc b/repos/os/src/server/fs_rom/main.cc index 63d1482177..1e5a4c6e46 100755 --- a/repos/os/src/server/fs_rom/main.cc +++ b/repos/os/src/server/fs_rom/main.cc @@ -100,6 +100,13 @@ class Fs_rom::Rom_session_component : */ struct Open_compound_dir_failed { }; + /* + * Version number used to track the need for ROM update notifications + */ + struct Version { unsigned value; }; + Version _curr_version { 0 }; + Version _handed_out_version { ~0U }; + /** * Open compound directory of specified file * @@ -300,6 +307,12 @@ class Fs_rom::Rom_session_component : } } + void _notify_client_about_new_version() + { + if (_sigh.valid() && _curr_version.value != _handed_out_version.value) + Genode::Signal_transmitter(_sigh).submit(); + } + public: /** @@ -346,11 +359,15 @@ class Fs_rom::Rom_session_component : { _update_dataspace(); Genode::Dataspace_capability ds = _file_ds.cap(); + _handed_out_version = _curr_version; return Genode::static_cap_cast(ds); } - void sigh(Genode::Signal_context_capability sigh) { - _sigh = sigh; } + void sigh(Genode::Signal_context_capability sigh) + { + _sigh = sigh; + _notify_client_about_new_version(); + } /** * If packet corresponds to this session then process and return true. @@ -362,16 +379,19 @@ class Fs_rom::Rom_session_component : switch (packet.operation()) { case File_system::Packet_descriptor::CONTENT_CHANGED: + + _curr_version = Version { _curr_version.value + 1 }; + if ((_file_handle.constructed() && (*_file_handle == packet.handle())) || (_compound_dir_handle.constructed() && (*_compound_dir_handle == packet.handle()))) { - if (_sigh.valid()) - Genode::Signal_transmitter(_sigh).submit(); + _notify_client_about_new_version(); return true; } return false; case File_system::Packet_descriptor::READ: { + if (!(_file_handle.constructed() && (*_file_handle == packet.handle()))) return false; @@ -389,6 +409,7 @@ class Fs_rom::Rom_session_component : } default: + Genode::error("discarding strange packet acknowledgement"); return true; }