1.1 --- a/libfsserver/include/fsserver/ext2_filesystem.h Fri Sep 10 00:49:32 2021 +0200 1.2 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Fri Sep 10 23:16:41 2021 +0200 1.3 @@ -37,7 +37,7 @@ 1.4 Ext2FileOperations *_ops; 1.5 1.6 public: 1.7 - explicit Ext2Filesystem(Pages *pages, ext2_filsys fs); 1.8 + explicit Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs); 1.9 1.10 virtual ~Ext2Filesystem(); 1.11
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/libfsserver/include/fsserver/file_notifier_registry.h Fri Sep 10 23:16:41 2021 +0200 2.3 @@ -0,0 +1,59 @@ 2.4 +/* 2.5 + * A registry of objects supporting notifications. 2.6 + * 2.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 2.8 + * 2.9 + * This program is free software; you can redistribute it and/or 2.10 + * modify it under the terms of the GNU General Public License as 2.11 + * published by the Free Software Foundation; either version 2 of 2.12 + * the License, or (at your option) any later version. 2.13 + * 2.14 + * This program is distributed in the hope that it will be useful, 2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2.17 + * GNU General Public License for more details. 2.18 + * 2.19 + * You should have received a copy of the GNU General Public License 2.20 + * along with this program; if not, write to the Free Software 2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 2.22 + * Boston, MA 02110-1301, USA 2.23 + */ 2.24 + 2.25 +#pragma once 2.26 + 2.27 +#include <map> 2.28 +#include <mutex> 2.29 + 2.30 +#include <fsserver/file_notification.h> 2.31 +#include <mem/types.h> 2.32 + 2.33 + 2.34 + 2.35 +/* Mapping type from file identifiers to notification managers. */ 2.36 + 2.37 +typedef std::map<fileid_t, FileNotification *> FileNotifiers; 2.38 +typedef std::map<fileid_t, FileNotification *> FileNotifierEntry; 2.39 + 2.40 + 2.41 + 2.42 +/* A registry of directory access objects. */ 2.43 + 2.44 +class FileNotifierRegistry 2.45 +{ 2.46 +protected: 2.47 + FileNotifiers _notifiers; 2.48 + std::mutex _lock; 2.49 + 2.50 + FileNotification *_get(fileid_t fileid); 2.51 + 2.52 +public: 2.53 + explicit FileNotifierRegistry(); 2.54 + 2.55 + void attach(fileid_t fileid); 2.56 + 2.57 + void detach(fileid_t fileid); 2.58 + 2.59 + FileNotification *get(fileid_t fileid); 2.60 +}; 2.61 + 2.62 +// vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/libfsserver/include/fsserver/file_paging.h Fri Sep 10 00:49:32 2021 +0200 3.2 +++ b/libfsserver/include/fsserver/file_paging.h Fri Sep 10 23:16:41 2021 +0200 3.3 @@ -24,7 +24,7 @@ 3.4 #include <map> 3.5 #include <mutex> 3.6 3.7 -#include <fsserver/file_notification.h> 3.8 +#include <fsserver/file_notifier_registry.h> 3.9 #include <fsserver/file_opening.h> 3.10 #include <fsserver/page_mapper.h> 3.11 #include <fsserver/pager.h> 3.12 @@ -37,11 +37,6 @@ 3.13 typedef std::map<fileid_t, PageMapper *> FileMapping; 3.14 typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; 3.15 3.16 -/* Mapping type from file identifiers to notification managers. */ 3.17 - 3.18 -typedef std::map<fileid_t, FileNotification *> FileNotifiers; 3.19 -typedef std::map<fileid_t, FileNotification *> FileNotifierEntry; 3.20 - 3.21 3.22 3.23 /* A registry of mappers for accessors. */ 3.24 @@ -50,8 +45,8 @@ 3.25 { 3.26 protected: 3.27 Pages *_pages; 3.28 + FileNotifierRegistry *_notifiers; 3.29 FileMapping _mappers; 3.30 - FileNotifiers _notifiers; 3.31 std::mutex _lock; 3.32 3.33 /* Mapper registry access. */ 3.34 @@ -68,14 +63,8 @@ 3.35 3.36 long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 3.37 3.38 - /* Notification manager access. */ 3.39 - 3.40 - FileNotification *get_notifier(fileid_t fileid); 3.41 - 3.42 - void remove(fileid_t fileid, FileNotification *notifier); 3.43 - 3.44 public: 3.45 - explicit FilePaging(Pages *pages); 3.46 + explicit FilePaging(Pages *pages, FileNotifierRegistry *notifiers); 3.47 3.48 /* Pager initialisation methods. */ 3.49
4.1 --- a/libfsserver/include/fsserver/filesystem_resource.h Fri Sep 10 00:49:32 2021 +0200 4.2 +++ b/libfsserver/include/fsserver/filesystem_resource.h Fri Sep 10 23:16:41 2021 +0200 4.3 @@ -33,7 +33,7 @@ 4.4 public FilesystemObject 4.5 { 4.6 public: 4.7 - explicit FilesystemResource(Pages *pages); 4.8 + explicit FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers); 4.9 4.10 /* Server details. */ 4.11
5.1 --- a/libfsserver/lib/Makefile Fri Sep 10 00:49:32 2021 +0200 5.2 +++ b/libfsserver/lib/Makefile Fri Sep 10 23:16:41 2021 +0200 5.3 @@ -48,6 +48,7 @@ 5.4 files/ext2_file_opener.cc \ 5.5 files/ext2_file_operations.cc \ 5.6 files/ext2_filesystem.cc \ 5.7 + files/file_notifier_registry.cc \ 5.8 files/file_notification.cc \ 5.9 files/file_pager.cc \ 5.10 files/file_paging.cc \
6.1 --- a/libfsserver/lib/files/ext2_filesystem.cc Fri Sep 10 00:49:32 2021 +0200 6.2 +++ b/libfsserver/lib/files/ext2_filesystem.cc Fri Sep 10 23:16:41 2021 +0200 6.3 @@ -24,8 +24,8 @@ 6.4 #include "ext2_filesystem.h" 6.5 #include "resource_server.h" 6.6 6.7 -Ext2Filesystem::Ext2Filesystem(Pages *pages, ext2_filsys fs) 6.8 -: FilesystemResource(pages) 6.9 +Ext2Filesystem::Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs) 6.10 +: FilesystemResource(pages, notifiers) 6.11 { 6.12 _ops = new Ext2FileOperations(fs); 6.13 }
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/libfsserver/lib/files/file_notifier_registry.cc Fri Sep 10 23:16:41 2021 +0200 7.3 @@ -0,0 +1,86 @@ 7.4 +/* 7.5 + * General functionality supporting file notifications. 7.6 + * 7.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 7.8 + * 7.9 + * This program is free software; you can redistribute it and/or 7.10 + * modify it under the terms of the GNU General Public License as 7.11 + * published by the Free Software Foundation; either version 2 of 7.12 + * the License, or (at your option) any later version. 7.13 + * 7.14 + * This program is distributed in the hope that it will be useful, 7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7.17 + * GNU General Public License for more details. 7.18 + * 7.19 + * You should have received a copy of the GNU General Public License 7.20 + * along with this program; if not, write to the Free Software 7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 7.22 + * Boston, MA 02110-1301, USA 7.23 + */ 7.24 + 7.25 +#include "file_notifier_registry.h" 7.26 + 7.27 + 7.28 + 7.29 +FileNotifierRegistry::FileNotifierRegistry() 7.30 +{ 7.31 +} 7.32 + 7.33 + 7.34 + 7.35 +/* Obtain a file-specific notification manager. */ 7.36 + 7.37 +FileNotification *FileNotifierRegistry::_get(fileid_t fileid) 7.38 +{ 7.39 + FileNotifiers::iterator entry = _notifiers.find(fileid); 7.40 + 7.41 + if (entry != _notifiers.end()) 7.42 + return _notifiers[fileid]; 7.43 + else 7.44 + return NULL; 7.45 +} 7.46 + 7.47 +/* Register a notification manager for the given 'fileid'. */ 7.48 + 7.49 +void FileNotifierRegistry::attach(fileid_t fileid) 7.50 +{ 7.51 + std::lock_guard<std::mutex> guard(_lock); 7.52 + 7.53 + FileNotification *notifier = _get(fileid); 7.54 + 7.55 + if (notifier == NULL) 7.56 + { 7.57 + notifier = new FileNotification; 7.58 + _notifiers[fileid] = notifier; 7.59 + } 7.60 + 7.61 + notifier->attach(); 7.62 +} 7.63 + 7.64 +/* Detach from and potentially remove a notification manager for the given 7.65 + 'fileid'. */ 7.66 + 7.67 +void FileNotifierRegistry::detach(fileid_t fileid) 7.68 +{ 7.69 + std::lock_guard<std::mutex> guard(_lock); 7.70 + 7.71 + FileNotification *notifier = _get(fileid); 7.72 + 7.73 + if ((notifier != NULL) && (!notifier->detach())) 7.74 + { 7.75 + _notifiers.erase(fileid); 7.76 + delete notifier; 7.77 + } 7.78 +} 7.79 + 7.80 +/* Obtain a file-specific notification manager. */ 7.81 + 7.82 +FileNotification *FileNotifierRegistry::get(fileid_t fileid) 7.83 +{ 7.84 + std::lock_guard<std::mutex> guard(_lock); 7.85 + 7.86 + return _get(fileid); 7.87 +} 7.88 + 7.89 +// vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/libfsserver/lib/files/file_paging.cc Fri Sep 10 00:49:32 2021 +0200 8.2 +++ b/libfsserver/lib/files/file_paging.cc Fri Sep 10 23:16:41 2021 +0200 8.3 @@ -26,8 +26,8 @@ 8.4 8.5 8.6 8.7 -FilePaging::FilePaging(Pages *pages) 8.8 -: _pages(pages) 8.9 +FilePaging::FilePaging(Pages *pages, FileNotifierRegistry *notifiers) 8.10 +: _pages(pages), _notifiers(notifiers) 8.11 { 8.12 } 8.13 8.14 @@ -49,14 +49,6 @@ 8.15 return mapper; 8.16 } 8.17 8.18 -/* Remove a notification manager for the given 'fileid'. */ 8.19 - 8.20 -void FilePaging::remove(fileid_t fileid, FileNotification *notifier) 8.21 -{ 8.22 - _notifiers.erase(fileid); 8.23 - delete notifier; 8.24 -} 8.25 - 8.26 /* Remove a page mapper and its resources for the given 'fileid'. */ 8.27 8.28 void FilePaging::remove(fileid_t fileid, PageMapper *mapper) 8.29 @@ -76,11 +68,6 @@ 8.30 return; 8.31 8.32 _mappers[fileid] = mapper; 8.33 - 8.34 - FileNotification *notifier = new FileNotification; 8.35 - 8.36 - _notifiers[fileid] = notifier; 8.37 - notifier->attach(); 8.38 } 8.39 8.40 8.41 @@ -117,22 +104,11 @@ 8.42 *mapper = new PageMapper(accessor, _pages); 8.43 8.44 set(fileid, *mapper); 8.45 + _notifiers->attach(fileid); 8.46 8.47 return L4_EOK; 8.48 } 8.49 8.50 -/* Obtain a file-specific notification manager. */ 8.51 - 8.52 -FileNotification *FilePaging::get_notifier(fileid_t file) 8.53 -{ 8.54 - FileNotifiers::iterator entry = _notifiers.find(file); 8.55 - 8.56 - if (entry != _notifiers.end()) 8.57 - return _notifiers[file]; 8.58 - else 8.59 - return NULL; 8.60 -} 8.61 - 8.62 8.63 8.64 /* Return a pager initialised with a page mapper. */ 8.65 @@ -166,19 +142,14 @@ 8.66 if (!mapper->detach()) 8.67 remove(fileid, mapper); 8.68 8.69 - FileNotification *notifier = get_notifier(fileid); 8.70 - 8.71 - if ((notifier != NULL) && (!notifier->detach())) 8.72 - remove(fileid, notifier); 8.73 + _notifiers->detach(fileid); 8.74 } 8.75 8.76 /* Obtain a file-specific notification manager. */ 8.77 8.78 -FileNotification *FilePaging::notifier(fileid_t file) 8.79 +FileNotification *FilePaging::notifier(fileid_t fileid) 8.80 { 8.81 - std::lock_guard<std::mutex> guard(_lock); 8.82 - 8.83 - return get_notifier(file); 8.84 + return _notifiers->get(fileid); 8.85 } 8.86 8.87 // vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/libfsserver/lib/files/filesystem_resource.cc Fri Sep 10 00:49:32 2021 +0200 9.2 +++ b/libfsserver/lib/files/filesystem_resource.cc Fri Sep 10 23:16:41 2021 +0200 9.3 @@ -24,8 +24,8 @@ 9.4 9.5 /* Support for providing access to user-specific filesystems. */ 9.6 9.7 -FilesystemResource::FilesystemResource(Pages *pages) 9.8 -: FilePaging(pages) 9.9 +FilesystemResource::FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers) 9.10 +: FilePaging(pages, notifiers) 9.11 { 9.12 } 9.13
10.1 --- a/servers/block_file_server.cc Fri Sep 10 00:49:32 2021 +0200 10.2 +++ b/servers/block_file_server.cc Fri Sep 10 23:16:41 2021 +0200 10.3 @@ -66,7 +66,8 @@ 10.4 MemoryIncremental mem(memory_pages); 10.5 PageQueueShared queue; 10.6 Pages pages(&mem, &queue); 10.7 - FilePaging paging(&pages); 10.8 + FileNotifierRegistry notifiers; 10.9 + FilePaging paging(&pages, ¬ifiers); 10.10 BlockFileOpener opener(&paging); 10.11 10.12 /* Register a server associating it with the given object. */
11.1 --- a/servers/client_file_server.cc Fri Sep 10 00:49:32 2021 +0200 11.2 +++ b/servers/client_file_server.cc Fri Sep 10 23:16:41 2021 +0200 11.3 @@ -67,7 +67,8 @@ 11.4 MemoryIncremental mem(memory_pages); 11.5 PageQueueShared queue; 11.6 Pages pages(&mem, &queue); 11.7 - FilePaging paging(&pages); 11.8 + FileNotifierRegistry notifiers; 11.9 + FilePaging paging(&pages, ¬ifiers); 11.10 ClientFileOpener opener(&paging); 11.11 11.12 /* Register a server associating it with the given object. */
12.1 --- a/servers/ext2_file_server.cc Fri Sep 10 00:49:32 2021 +0200 12.2 +++ b/servers/ext2_file_server.cc Fri Sep 10 23:16:41 2021 +0200 12.3 @@ -94,7 +94,9 @@ 12.4 MemoryIncremental mem(memory_pages); 12.5 PageQueueShared queue; 12.6 Pages pages(&mem, &queue); 12.7 - Ext2Filesystem filesystem(&pages, fs); 12.8 + FileNotifierRegistry notifiers; 12.9 + FilePaging paging(&pages, ¬ifiers); 12.10 + Ext2Filesystem filesystem(&pages, ¬ifiers, fs); 12.11 12.12 /* Register a server associating it with the given object. */ 12.13
13.1 --- a/servers/host_file_server.cc Fri Sep 10 00:49:32 2021 +0200 13.2 +++ b/servers/host_file_server.cc Fri Sep 10 23:16:41 2021 +0200 13.3 @@ -66,7 +66,8 @@ 13.4 MemoryIncremental mem(memory_pages); 13.5 PageQueueShared queue; 13.6 Pages pages(&mem, &queue); 13.7 - FilePaging paging(&pages); 13.8 + FileNotifierRegistry notifiers; 13.9 + FilePaging paging(&pages, ¬ifiers); 13.10 HostFileOpener opener(&paging); 13.11 13.12 /* Register a server associating it with the given object. */
14.1 --- a/servers/test_file_server.cc Fri Sep 10 00:49:32 2021 +0200 14.2 +++ b/servers/test_file_server.cc Fri Sep 10 23:16:41 2021 +0200 14.3 @@ -65,7 +65,8 @@ 14.4 MemoryIncremental mem(memory_pages, page(REGION_PAGES)); 14.5 PageQueueShared queue; 14.6 Pages pages(&mem, &queue); 14.7 - FilePaging paging(&pages); 14.8 + FileNotifierRegistry notifiers; 14.9 + FilePaging paging(&pages, ¬ifiers); 14.10 TestFileOpener opener(&paging, page(FILE_PAGES)); 14.11 14.12 /* Register a server associating it with the given object. */