# HG changeset patch # User Paul Boddie # Date 1631308601 -7200 # Node ID 955a946c32f3594c377e5125c74fe39375ca1de9 # Parent 2e3954ae6bdbd55e7fd3ba400095c7f94feea4c6 Introduced a separate notifier registry for files. diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/include/fsserver/ext2_filesystem.h --- a/libfsserver/include/fsserver/ext2_filesystem.h Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Fri Sep 10 23:16:41 2021 +0200 @@ -37,7 +37,7 @@ Ext2FileOperations *_ops; public: - explicit Ext2Filesystem(Pages *pages, ext2_filsys fs); + explicit Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs); virtual ~Ext2Filesystem(); diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/include/fsserver/file_notifier_registry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/file_notifier_registry.h Fri Sep 10 23:16:41 2021 +0200 @@ -0,0 +1,59 @@ +/* + * A registry of objects supporting notifications. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include +#include + +#include +#include + + + +/* Mapping type from file identifiers to notification managers. */ + +typedef std::map FileNotifiers; +typedef std::map FileNotifierEntry; + + + +/* A registry of directory access objects. */ + +class FileNotifierRegistry +{ +protected: + FileNotifiers _notifiers; + std::mutex _lock; + + FileNotification *_get(fileid_t fileid); + +public: + explicit FileNotifierRegistry(); + + void attach(fileid_t fileid); + + void detach(fileid_t fileid); + + FileNotification *get(fileid_t fileid); +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/include/fsserver/file_paging.h --- a/libfsserver/include/fsserver/file_paging.h Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/include/fsserver/file_paging.h Fri Sep 10 23:16:41 2021 +0200 @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -37,11 +37,6 @@ typedef std::map FileMapping; typedef std::pair FileMappingEntry; -/* Mapping type from file identifiers to notification managers. */ - -typedef std::map FileNotifiers; -typedef std::map FileNotifierEntry; - /* A registry of mappers for accessors. */ @@ -50,8 +45,8 @@ { protected: Pages *_pages; + FileNotifierRegistry *_notifiers; FileMapping _mappers; - FileNotifiers _notifiers; std::mutex _lock; /* Mapper registry access. */ @@ -68,14 +63,8 @@ long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); - /* Notification manager access. */ - - FileNotification *get_notifier(fileid_t fileid); - - void remove(fileid_t fileid, FileNotification *notifier); - public: - explicit FilePaging(Pages *pages); + explicit FilePaging(Pages *pages, FileNotifierRegistry *notifiers); /* Pager initialisation methods. */ diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/include/fsserver/filesystem_resource.h --- a/libfsserver/include/fsserver/filesystem_resource.h Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/include/fsserver/filesystem_resource.h Fri Sep 10 23:16:41 2021 +0200 @@ -33,7 +33,7 @@ public FilesystemObject { public: - explicit FilesystemResource(Pages *pages); + explicit FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers); /* Server details. */ diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/lib/Makefile Fri Sep 10 23:16:41 2021 +0200 @@ -48,6 +48,7 @@ files/ext2_file_opener.cc \ files/ext2_file_operations.cc \ files/ext2_filesystem.cc \ + files/file_notifier_registry.cc \ files/file_notification.cc \ files/file_pager.cc \ files/file_paging.cc \ diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/lib/files/ext2_filesystem.cc --- a/libfsserver/lib/files/ext2_filesystem.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/lib/files/ext2_filesystem.cc Fri Sep 10 23:16:41 2021 +0200 @@ -24,8 +24,8 @@ #include "ext2_filesystem.h" #include "resource_server.h" -Ext2Filesystem::Ext2Filesystem(Pages *pages, ext2_filsys fs) -: FilesystemResource(pages) +Ext2Filesystem::Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs) +: FilesystemResource(pages, notifiers) { _ops = new Ext2FileOperations(fs); } diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/lib/files/file_notifier_registry.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/file_notifier_registry.cc Fri Sep 10 23:16:41 2021 +0200 @@ -0,0 +1,86 @@ +/* + * General functionality supporting file notifications. + * + * Copyright (C) 2021 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include "file_notifier_registry.h" + + + +FileNotifierRegistry::FileNotifierRegistry() +{ +} + + + +/* Obtain a file-specific notification manager. */ + +FileNotification *FileNotifierRegistry::_get(fileid_t fileid) +{ + FileNotifiers::iterator entry = _notifiers.find(fileid); + + if (entry != _notifiers.end()) + return _notifiers[fileid]; + else + return NULL; +} + +/* Register a notification manager for the given 'fileid'. */ + +void FileNotifierRegistry::attach(fileid_t fileid) +{ + std::lock_guard guard(_lock); + + FileNotification *notifier = _get(fileid); + + if (notifier == NULL) + { + notifier = new FileNotification; + _notifiers[fileid] = notifier; + } + + notifier->attach(); +} + +/* Detach from and potentially remove a notification manager for the given + 'fileid'. */ + +void FileNotifierRegistry::detach(fileid_t fileid) +{ + std::lock_guard guard(_lock); + + FileNotification *notifier = _get(fileid); + + if ((notifier != NULL) && (!notifier->detach())) + { + _notifiers.erase(fileid); + delete notifier; + } +} + +/* Obtain a file-specific notification manager. */ + +FileNotification *FileNotifierRegistry::get(fileid_t fileid) +{ + std::lock_guard guard(_lock); + + return _get(fileid); +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/lib/files/file_paging.cc --- a/libfsserver/lib/files/file_paging.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/lib/files/file_paging.cc Fri Sep 10 23:16:41 2021 +0200 @@ -26,8 +26,8 @@ -FilePaging::FilePaging(Pages *pages) -: _pages(pages) +FilePaging::FilePaging(Pages *pages, FileNotifierRegistry *notifiers) +: _pages(pages), _notifiers(notifiers) { } @@ -49,14 +49,6 @@ return mapper; } -/* Remove a notification manager for the given 'fileid'. */ - -void FilePaging::remove(fileid_t fileid, FileNotification *notifier) -{ - _notifiers.erase(fileid); - delete notifier; -} - /* Remove a page mapper and its resources for the given 'fileid'. */ void FilePaging::remove(fileid_t fileid, PageMapper *mapper) @@ -76,11 +68,6 @@ return; _mappers[fileid] = mapper; - - FileNotification *notifier = new FileNotification; - - _notifiers[fileid] = notifier; - notifier->attach(); } @@ -117,22 +104,11 @@ *mapper = new PageMapper(accessor, _pages); set(fileid, *mapper); + _notifiers->attach(fileid); return L4_EOK; } -/* Obtain a file-specific notification manager. */ - -FileNotification *FilePaging::get_notifier(fileid_t file) -{ - FileNotifiers::iterator entry = _notifiers.find(file); - - if (entry != _notifiers.end()) - return _notifiers[file]; - else - return NULL; -} - /* Return a pager initialised with a page mapper. */ @@ -166,19 +142,14 @@ if (!mapper->detach()) remove(fileid, mapper); - FileNotification *notifier = get_notifier(fileid); - - if ((notifier != NULL) && (!notifier->detach())) - remove(fileid, notifier); + _notifiers->detach(fileid); } /* Obtain a file-specific notification manager. */ -FileNotification *FilePaging::notifier(fileid_t file) +FileNotification *FilePaging::notifier(fileid_t fileid) { - std::lock_guard guard(_lock); - - return get_notifier(file); + return _notifiers->get(fileid); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 2e3954ae6bdb -r 955a946c32f3 libfsserver/lib/files/filesystem_resource.cc --- a/libfsserver/lib/files/filesystem_resource.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/libfsserver/lib/files/filesystem_resource.cc Fri Sep 10 23:16:41 2021 +0200 @@ -24,8 +24,8 @@ /* Support for providing access to user-specific filesystems. */ -FilesystemResource::FilesystemResource(Pages *pages) -: FilePaging(pages) +FilesystemResource::FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers) +: FilePaging(pages, notifiers) { } diff -r 2e3954ae6bdb -r 955a946c32f3 servers/block_file_server.cc --- a/servers/block_file_server.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/servers/block_file_server.cc Fri Sep 10 23:16:41 2021 +0200 @@ -66,7 +66,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FilePaging paging(&pages); + FileNotifierRegistry notifiers; + FilePaging paging(&pages, ¬ifiers); BlockFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 2e3954ae6bdb -r 955a946c32f3 servers/client_file_server.cc --- a/servers/client_file_server.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/servers/client_file_server.cc Fri Sep 10 23:16:41 2021 +0200 @@ -67,7 +67,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FilePaging paging(&pages); + FileNotifierRegistry notifiers; + FilePaging paging(&pages, ¬ifiers); ClientFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 2e3954ae6bdb -r 955a946c32f3 servers/ext2_file_server.cc --- a/servers/ext2_file_server.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/servers/ext2_file_server.cc Fri Sep 10 23:16:41 2021 +0200 @@ -94,7 +94,9 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - Ext2Filesystem filesystem(&pages, fs); + FileNotifierRegistry notifiers; + FilePaging paging(&pages, ¬ifiers); + Ext2Filesystem filesystem(&pages, ¬ifiers, fs); /* Register a server associating it with the given object. */ diff -r 2e3954ae6bdb -r 955a946c32f3 servers/host_file_server.cc --- a/servers/host_file_server.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/servers/host_file_server.cc Fri Sep 10 23:16:41 2021 +0200 @@ -66,7 +66,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FilePaging paging(&pages); + FileNotifierRegistry notifiers; + FilePaging paging(&pages, ¬ifiers); HostFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 2e3954ae6bdb -r 955a946c32f3 servers/test_file_server.cc --- a/servers/test_file_server.cc Fri Sep 10 00:49:32 2021 +0200 +++ b/servers/test_file_server.cc Fri Sep 10 23:16:41 2021 +0200 @@ -65,7 +65,8 @@ MemoryIncremental mem(memory_pages, page(REGION_PAGES)); PageQueueShared queue; Pages pages(&mem, &queue); - FilePaging paging(&pages); + FileNotifierRegistry notifiers; + FilePaging paging(&pages, ¬ifiers); TestFileOpener opener(&paging, page(FILE_PAGES)); /* Register a server associating it with the given object. */