1.1 --- a/libfsserver/include/fsserver/accessor.h Sat Sep 11 19:44:57 2021 +0200 1.2 +++ b/libfsserver/include/fsserver/accessor.h Sun Sep 12 01:14:30 2021 +0200 1.3 @@ -30,6 +30,7 @@ 1.4 class Accessor 1.5 { 1.6 protected: 1.7 + bool _closed = false; 1.8 offset_t _size; 1.9 1.10 /* Data transfer helper methods. */
2.1 --- a/libfsserver/include/fsserver/ext2_filesystem.h Sat Sep 11 19:44:57 2021 +0200 2.2 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Sun Sep 12 01:14:30 2021 +0200 2.3 @@ -37,7 +37,7 @@ 2.4 Ext2FileOperations *_ops; 2.5 2.6 public: 2.7 - explicit Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs); 2.8 + explicit Ext2Filesystem(Pages *pages, ext2_filsys fs); 2.9 2.10 virtual ~Ext2Filesystem(); 2.11
3.1 --- a/libfsserver/include/fsserver/file_notifier_registry.h Sat Sep 11 19:44:57 2021 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,59 +0,0 @@ 3.4 -/* 3.5 - * A registry of objects supporting notifications. 3.6 - * 3.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 3.8 - * 3.9 - * This program is free software; you can redistribute it and/or 3.10 - * modify it under the terms of the GNU General Public License as 3.11 - * published by the Free Software Foundation; either version 2 of 3.12 - * the License, or (at your option) any later version. 3.13 - * 3.14 - * This program is distributed in the hope that it will be useful, 3.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.17 - * GNU General Public License for more details. 3.18 - * 3.19 - * You should have received a copy of the GNU General Public License 3.20 - * along with this program; if not, write to the Free Software 3.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 3.22 - * Boston, MA 02110-1301, USA 3.23 - */ 3.24 - 3.25 -#pragma once 3.26 - 3.27 -#include <map> 3.28 -#include <mutex> 3.29 - 3.30 -#include <fsserver/file_notification.h> 3.31 -#include <mem/types.h> 3.32 - 3.33 - 3.34 - 3.35 -/* Mapping type from file identifiers to notification managers. */ 3.36 - 3.37 -typedef std::map<fileid_t, FileNotification *> FileNotifiers; 3.38 -typedef std::map<fileid_t, FileNotification *> FileNotifierEntry; 3.39 - 3.40 - 3.41 - 3.42 -/* A registry of directory access objects. */ 3.43 - 3.44 -class FileNotifierRegistry 3.45 -{ 3.46 -protected: 3.47 - FileNotifiers _notifiers; 3.48 - std::mutex _lock; 3.49 - 3.50 - FileNotification *_get(fileid_t fileid); 3.51 - 3.52 -public: 3.53 - explicit FileNotifierRegistry(); 3.54 - 3.55 - void attach(fileid_t fileid); 3.56 - 3.57 - void detach(fileid_t fileid); 3.58 - 3.59 - FileNotification *get(fileid_t fileid); 3.60 -}; 3.61 - 3.62 -// vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/libfsserver/include/fsserver/file_pager.h Sat Sep 11 19:44:57 2021 +0200 4.2 +++ b/libfsserver/include/fsserver/file_pager.h Sun Sep 12 01:14:30 2021 +0200 4.3 @@ -33,6 +33,7 @@ 4.4 { 4.5 protected: 4.6 FilePaging *_paging; 4.7 + FileProvider *_provider; 4.8 4.9 /* Notification endpoint for event subscription. */ 4.10 4.11 @@ -45,7 +46,7 @@ 4.12 public: 4.13 fileid_t fileid; 4.14 4.15 - explicit FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, 4.16 + explicit FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags, 4.17 FilePaging *paging); 4.18 4.19 virtual void close();
5.1 --- a/libfsserver/include/fsserver/file_paging.h Sat Sep 11 19:44:57 2021 +0200 5.2 +++ b/libfsserver/include/fsserver/file_paging.h Sun Sep 12 01:14:30 2021 +0200 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * A registry of objects supporting paging for files. 5.6 + * A registry of filesystem objects. 5.7 * 5.8 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5.9 * 5.10 @@ -24,9 +24,9 @@ 5.11 #include <map> 5.12 #include <mutex> 5.13 5.14 -#include <fsserver/file_notifier_registry.h> 5.15 +#include <fsserver/accountable.h> 5.16 #include <fsserver/file_opening.h> 5.17 -#include <fsserver/page_mapper.h> 5.18 +#include <fsserver/file_provider.h> 5.19 #include <fsserver/pager.h> 5.20 #include <fsserver/pages.h> 5.21 5.22 @@ -34,37 +34,36 @@ 5.23 5.24 /* Mapping type from file identifiers to page mappers. */ 5.25 5.26 -typedef std::map<fileid_t, PageMapper *> FileMapping; 5.27 -typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; 5.28 +typedef std::map<fileid_t, Accountable *> FileMapping; 5.29 +typedef std::pair<fileid_t, Accountable *> FileMappingEntry; 5.30 5.31 5.32 5.33 -/* A registry of mappers for accessors. */ 5.34 +/* A registry of filesystem objects. */ 5.35 5.36 class FilePaging 5.37 { 5.38 protected: 5.39 Pages *_pages; 5.40 - FileNotifierRegistry *_notifiers; 5.41 - FileMapping _mappers; 5.42 + FileMapping _providers; 5.43 std::mutex _lock; 5.44 5.45 - /* Mapper registry access. */ 5.46 + /* Filesystem object access. */ 5.47 5.48 - PageMapper *get(fileid_t fileid); 5.49 + Accountable *get(fileid_t fileid); 5.50 5.51 - void remove(fileid_t fileid, PageMapper *mapper); 5.52 + void remove(fileid_t fileid, Accountable *obj); 5.53 5.54 - void set(fileid_t fileid, PageMapper *mapper); 5.55 + void set(fileid_t fileid, Accountable *obj); 5.56 5.57 /* Pager initialisation methods. */ 5.58 5.59 map_flags_t get_flags(flags_t flags); 5.60 5.61 - long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 5.62 + long get_provider(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, FileProvider **file_provider); 5.63 5.64 public: 5.65 - explicit FilePaging(Pages *pages, FileNotifierRegistry *notifiers); 5.66 + explicit FilePaging(Pages *pages); 5.67 5.68 /* Pager initialisation methods. */ 5.69 5.70 @@ -72,9 +71,7 @@ 5.71 5.72 /* Methods for the pager. */ 5.73 5.74 - void detach_pager(fileid_t fileid, PageMapper *mapper); 5.75 - 5.76 - FileNotification *notifier(fileid_t fileid); 5.77 + void detach_pager(fileid_t fileid, Accountable *mapper); 5.78 }; 5.79 5.80 // vim: tabstop=4 expandtab shiftwidth=4
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/libfsserver/include/fsserver/file_provider.h Sun Sep 12 01:14:30 2021 +0200 6.3 @@ -0,0 +1,44 @@ 6.4 +/* 6.5 + * An object encapsulating file resources. 6.6 + * 6.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 6.8 + * 6.9 + * This program is free software; you can redistribute it and/or 6.10 + * modify it under the terms of the GNU General Public License as 6.11 + * published by the Free Software Foundation; either version 2 of 6.12 + * the License, or (at your option) any later version. 6.13 + * 6.14 + * This program is distributed in the hope that it will be useful, 6.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 6.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6.17 + * GNU General Public License for more details. 6.18 + * 6.19 + * You should have received a copy of the GNU General Public License 6.20 + * along with this program; if not, write to the Free Software 6.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 6.22 + * Boston, MA 02110-1301, USA 6.23 + */ 6.24 + 6.25 +#pragma once 6.26 + 6.27 +#include <fsserver/file_notification.h> 6.28 +#include <fsserver/page_mapper.h> 6.29 + 6.30 + 6.31 + 6.32 +/* An object providing access to file functionality. */ 6.33 + 6.34 +class FileProvider : public FileNotification 6.35 +{ 6.36 +protected: 6.37 + PageMapper *_mapper; 6.38 + 6.39 +public: 6.40 + explicit FileProvider(PageMapper *mapper); 6.41 + 6.42 + virtual ~FileProvider(); 6.43 + 6.44 + PageMapper *mapper(); 6.45 +}; 6.46 + 6.47 +// vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/libfsserver/include/fsserver/filesystem_resource.h Sat Sep 11 19:44:57 2021 +0200 7.2 +++ b/libfsserver/include/fsserver/filesystem_resource.h Sun Sep 12 01:14:30 2021 +0200 7.3 @@ -33,7 +33,7 @@ 7.4 public FilesystemObject 7.5 { 7.6 public: 7.7 - explicit FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers); 7.8 + explicit FilesystemResource(Pages *pages); 7.9 7.10 /* Server details. */ 7.11
8.1 --- a/libfsserver/include/fsserver/page_mapper.h Sat Sep 11 19:44:57 2021 +0200 8.2 +++ b/libfsserver/include/fsserver/page_mapper.h Sun Sep 12 01:14:30 2021 +0200 8.3 @@ -23,7 +23,6 @@ 8.4 8.5 #include <fsserver/access_map.h> 8.6 #include <fsserver/accessor.h> 8.7 -#include <fsserver/accountable.h> 8.8 #include <fsserver/page_owner.h> 8.9 8.10 #include <mutex> 8.11 @@ -32,7 +31,7 @@ 8.12 8.13 /* A file mapper, associating flexpages with file regions. */ 8.14 8.15 -class PageMapper : public PageOwner, public Accountable 8.16 +class PageMapper : public PageOwner 8.17 { 8.18 protected: 8.19 AccessMap _map; 8.20 @@ -52,9 +51,7 @@ 8.21 public: 8.22 explicit PageMapper(Accessor *accessor, Pages *pages); 8.23 8.24 - /* Specialised accounting methods. */ 8.25 - 8.26 - unsigned int detach(); 8.27 + virtual ~PageMapper(); 8.28 8.29 Accessor *accessor() 8.30 { return _accessor; }
9.1 --- a/libfsserver/include/fsserver/pipe_accessor.h Sat Sep 11 19:44:57 2021 +0200 9.2 +++ b/libfsserver/include/fsserver/pipe_accessor.h Sun Sep 12 01:14:30 2021 +0200 9.3 @@ -44,10 +44,6 @@ 9.4 virtual offset_t get_size(); 9.5 9.6 virtual void set_size(offset_t size); 9.7 - 9.8 - virtual void close(); 9.9 - 9.10 - virtual void open(); 9.11 }; 9.12 9.13 // vim: tabstop=4 expandtab shiftwidth=4
10.1 --- a/libfsserver/lib/Makefile Sat Sep 11 19:44:57 2021 +0200 10.2 +++ b/libfsserver/lib/Makefile Sun Sep 12 01:14:30 2021 +0200 10.3 @@ -48,10 +48,10 @@ 10.4 files/ext2_file_opener.cc \ 10.5 files/ext2_file_operations.cc \ 10.6 files/ext2_filesystem.cc \ 10.7 - files/file_notifier_registry.cc \ 10.8 files/file_notification.cc \ 10.9 files/file_pager.cc \ 10.10 files/file_paging.cc \ 10.11 + files/file_provider.cc \ 10.12 files/filesystem_resource.cc \ 10.13 files/host_file_accessor.cc \ 10.14 files/host_file_opener.cc \
11.1 --- a/libfsserver/lib/files/ext2_file_accessor.cc Sat Sep 11 19:44:57 2021 +0200 11.2 +++ b/libfsserver/lib/files/ext2_file_accessor.cc Sun Sep 12 01:14:30 2021 +0200 11.3 @@ -54,7 +54,11 @@ 11.4 11.5 void Ext2FileAccessor::close() 11.6 { 11.7 + if (_closed) 11.8 + return; 11.9 + 11.10 _ops->close_file(_file); 11.11 + _closed = true; 11.12 } 11.13 11.14 /* Data transfer helper methods. */
12.1 --- a/libfsserver/lib/files/ext2_filesystem.cc Sat Sep 11 19:44:57 2021 +0200 12.2 +++ b/libfsserver/lib/files/ext2_filesystem.cc Sun Sep 12 01:14:30 2021 +0200 12.3 @@ -24,8 +24,8 @@ 12.4 #include "ext2_filesystem.h" 12.5 #include "resource_server.h" 12.6 12.7 -Ext2Filesystem::Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs) 12.8 -: FilesystemResource(pages, notifiers) 12.9 +Ext2Filesystem::Ext2Filesystem(Pages *pages, ext2_filsys fs) 12.10 +: FilesystemResource(pages) 12.11 { 12.12 _ops = new Ext2FileOperations(fs); 12.13 }
13.1 --- a/libfsserver/lib/files/file_notifier_registry.cc Sat Sep 11 19:44:57 2021 +0200 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,86 +0,0 @@ 13.4 -/* 13.5 - * General functionality supporting file notifications. 13.6 - * 13.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 13.8 - * 13.9 - * This program is free software; you can redistribute it and/or 13.10 - * modify it under the terms of the GNU General Public License as 13.11 - * published by the Free Software Foundation; either version 2 of 13.12 - * the License, or (at your option) any later version. 13.13 - * 13.14 - * This program is distributed in the hope that it will be useful, 13.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13.17 - * GNU General Public License for more details. 13.18 - * 13.19 - * You should have received a copy of the GNU General Public License 13.20 - * along with this program; if not, write to the Free Software 13.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, 13.22 - * Boston, MA 02110-1301, USA 13.23 - */ 13.24 - 13.25 -#include "file_notifier_registry.h" 13.26 - 13.27 - 13.28 - 13.29 -FileNotifierRegistry::FileNotifierRegistry() 13.30 -{ 13.31 -} 13.32 - 13.33 - 13.34 - 13.35 -/* Obtain a file-specific notification manager. */ 13.36 - 13.37 -FileNotification *FileNotifierRegistry::_get(fileid_t fileid) 13.38 -{ 13.39 - FileNotifiers::iterator entry = _notifiers.find(fileid); 13.40 - 13.41 - if (entry != _notifiers.end()) 13.42 - return _notifiers[fileid]; 13.43 - else 13.44 - return NULL; 13.45 -} 13.46 - 13.47 -/* Register a notification manager for the given 'fileid'. */ 13.48 - 13.49 -void FileNotifierRegistry::attach(fileid_t fileid) 13.50 -{ 13.51 - std::lock_guard<std::mutex> guard(_lock); 13.52 - 13.53 - FileNotification *notifier = _get(fileid); 13.54 - 13.55 - if (notifier == NULL) 13.56 - { 13.57 - notifier = new FileNotification; 13.58 - _notifiers[fileid] = notifier; 13.59 - } 13.60 - 13.61 - notifier->attach(); 13.62 -} 13.63 - 13.64 -/* Detach from and potentially remove a notification manager for the given 13.65 - 'fileid'. */ 13.66 - 13.67 -void FileNotifierRegistry::detach(fileid_t fileid) 13.68 -{ 13.69 - std::lock_guard<std::mutex> guard(_lock); 13.70 - 13.71 - FileNotification *notifier = _get(fileid); 13.72 - 13.73 - if ((notifier != NULL) && (!notifier->detach())) 13.74 - { 13.75 - _notifiers.erase(fileid); 13.76 - delete notifier; 13.77 - } 13.78 -} 13.79 - 13.80 -/* Obtain a file-specific notification manager. */ 13.81 - 13.82 -FileNotification *FileNotifierRegistry::get(fileid_t fileid) 13.83 -{ 13.84 - std::lock_guard<std::mutex> guard(_lock); 13.85 - 13.86 - return _get(fileid); 13.87 -} 13.88 - 13.89 -// vim: tabstop=4 expandtab shiftwidth=4
14.1 --- a/libfsserver/lib/files/file_pager.cc Sat Sep 11 19:44:57 2021 +0200 14.2 +++ b/libfsserver/lib/files/file_pager.cc Sun Sep 12 01:14:30 2021 +0200 14.3 @@ -24,12 +24,14 @@ 14.4 14.5 14.6 14.7 -/* Initialise a pager for a file with a unique file identifier and shared page 14.8 - mapper for moderating access to loaded pages. */ 14.9 +/* Initialise a pager for a file with a unique file identifier, file provider, 14.10 + mapping flags and a file paging coordinator. The provider offers a shared 14.11 + page mapper for moderating access to loaded pages. */ 14.12 14.13 -FilePager::FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, 14.14 +FilePager::FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags, 14.15 FilePaging *paging) 14.16 -: Pager(mapper, flags), _paging(paging), fileid(fileid) 14.17 +: Pager(provider->mapper(), flags), 14.18 + _paging(paging), _provider(provider), fileid(fileid) 14.19 { 14.20 } 14.21 14.22 @@ -50,14 +52,13 @@ 14.23 14.24 void FilePager::close() 14.25 { 14.26 - _paging->detach_pager(fileid, _mapper); 14.27 - 14.28 /* Notify other users of the file. */ 14.29 14.30 - FileNotification *notifier = _paging->notifier(fileid); 14.31 + _provider->notify_others(_endpoint, NOTIFY_PEER_CLOSED); 14.32 14.33 - if (notifier != NULL) 14.34 - notifier->notify_others(_endpoint, NOTIFY_PEER_CLOSED); 14.35 + /* Detach the pager, potentially removing the file provider. */ 14.36 + 14.37 + _paging->detach_pager(fileid, _provider); 14.38 } 14.39 14.40 14.41 @@ -70,11 +71,7 @@ 14.42 14.43 if (_resized) 14.44 { 14.45 - FileNotification *notifier = _paging->notifier(fileid); 14.46 - 14.47 - if (notifier != NULL) 14.48 - notifier->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); 14.49 - 14.50 + _provider->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); 14.51 _resized = false; 14.52 } 14.53 14.54 @@ -121,22 +118,13 @@ 14.55 /* Readers can subscribe to new data (at end), and pipe closed events. 14.56 Writers can subscribe to new space and pipe closed events. */ 14.57 14.58 - FileNotification *notifier = _paging->notifier(fileid); 14.59 - 14.60 - if (notifier == NULL) 14.61 - return -L4_ENOSYS; 14.62 - 14.63 - _endpoint = notifier->subscribe(endpoint, flags); 14.64 + _endpoint = _provider->subscribe(endpoint, flags); 14.65 return L4_EOK; 14.66 } 14.67 14.68 long FilePager::unsubscribe(l4_cap_idx_t endpoint) 14.69 { 14.70 - FileNotification *notifier = _paging->notifier(fileid); 14.71 - 14.72 - if (notifier != NULL) 14.73 - notifier->unsubscribe(_endpoint, endpoint); 14.74 - 14.75 + _provider->unsubscribe(_endpoint, endpoint); 14.76 return L4_EOK; 14.77 } 14.78
15.1 --- a/libfsserver/lib/files/file_paging.cc Sat Sep 11 19:44:57 2021 +0200 15.2 +++ b/libfsserver/lib/files/file_paging.cc Sun Sep 12 01:14:30 2021 +0200 15.3 @@ -26,48 +26,50 @@ 15.4 15.5 15.6 15.7 -FilePaging::FilePaging(Pages *pages, FileNotifierRegistry *notifiers) 15.8 -: _pages(pages), _notifiers(notifiers) 15.9 +/* The file paging coordinator provides a memory page collection to the page 15.10 + mappers it creates. */ 15.11 + 15.12 +FilePaging::FilePaging(Pages *pages) 15.13 +: _pages(pages) 15.14 { 15.15 } 15.16 15.17 15.18 15.19 -/* Return any registered page mapper for the given 'fileid' or NULL if no such 15.20 - mapper is registered. */ 15.21 +/* Return any registered provider for the given 'fileid' or NULL if no such 15.22 + provider is registered. */ 15.23 15.24 -PageMapper *FilePaging::get(fileid_t fileid) 15.25 +Accountable *FilePaging::get(fileid_t fileid) 15.26 { 15.27 - FileMapping::iterator entry = _mappers.find(fileid); 15.28 - PageMapper *mapper; 15.29 + FileMapping::iterator entry = _providers.find(fileid); 15.30 + Accountable *provider; 15.31 15.32 - if (entry == _mappers.end()) 15.33 - mapper = NULL; 15.34 + if (entry == _providers.end()) 15.35 + provider = NULL; 15.36 else 15.37 - mapper = entry->second; 15.38 + provider = entry->second; 15.39 15.40 - return mapper; 15.41 + return provider; 15.42 } 15.43 15.44 -/* Remove a page mapper and its resources for the given 'fileid'. */ 15.45 +/* Remove a provider and its resources for the given 'fileid'. */ 15.46 15.47 -void FilePaging::remove(fileid_t fileid, PageMapper *mapper) 15.48 +void FilePaging::remove(fileid_t fileid, Accountable *provider) 15.49 { 15.50 - _mappers.erase(fileid); 15.51 - delete mapper->accessor(); 15.52 - delete mapper; 15.53 + _providers.erase(fileid); 15.54 + delete provider; 15.55 } 15.56 15.57 -/* Register a page 'mapper' and a notification manager for the given 'fileid'. */ 15.58 +/* Register a 'provider' for the given 'fileid'. */ 15.59 15.60 -void FilePaging::set(fileid_t fileid, PageMapper *mapper) 15.61 +void FilePaging::set(fileid_t fileid, Accountable *provider) 15.62 { 15.63 - FileMapping::iterator entry = _mappers.find(fileid); 15.64 + FileMapping::iterator entry = _providers.find(fileid); 15.65 15.66 - if (entry != _mappers.end()) 15.67 + if (entry != _providers.end()) 15.68 return; 15.69 15.70 - _mappers[fileid] = mapper; 15.71 + _providers[fileid] = provider; 15.72 } 15.73 15.74 15.75 @@ -81,19 +83,30 @@ 15.76 15.77 15.78 15.79 -/* Obtain a page mapper for the 'fileid' or register a new one in the 15.80 +/* Obtain a provider for the 'fileid' or register a new one in the 15.81 paging object. */ 15.82 15.83 -long FilePaging::get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) 15.84 +long FilePaging::get_provider(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, FileProvider **file_provider) 15.85 { 15.86 - /* Obtain any registered page mapper. */ 15.87 + /* Obtain any registered provider. */ 15.88 + 15.89 + Accountable *provider = get(fileid); 15.90 15.91 - *mapper = get(fileid); 15.92 + if (provider != NULL) 15.93 + { 15.94 + /* Distinguish between file providers and other objects that may be 15.95 + registered. For files specifically, a file provider is needed 15.96 + because it will provide a page mapper. */ 15.97 + 15.98 + *file_provider = dynamic_cast<FileProvider *>(provider); 15.99 15.100 - if (*mapper != NULL) 15.101 - return L4_EOK; 15.102 + if ((*file_provider) != NULL) 15.103 + return L4_EOK; 15.104 + else 15.105 + return -L4_EIO; 15.106 + } 15.107 15.108 - /* Make an accessor and page mapper, registering the mapper. */ 15.109 + /* Make an accessor, page mapper, and a provider to encapsulate them. */ 15.110 15.111 Accessor *accessor; 15.112 long err = opening->make_accessor(path, flags, fileid, &accessor); 15.113 @@ -101,55 +114,48 @@ 15.114 if (err) 15.115 return err; 15.116 15.117 - *mapper = new PageMapper(accessor, _pages); 15.118 + PageMapper *mapper = new PageMapper(accessor, _pages); 15.119 + *file_provider = new FileProvider(mapper); 15.120 15.121 - set(fileid, *mapper); 15.122 - _notifiers->attach(fileid); 15.123 + /* Register the provider. */ 15.124 15.125 + set(fileid, *file_provider); 15.126 return L4_EOK; 15.127 } 15.128 15.129 15.130 15.131 -/* Return a pager initialised with a page mapper. */ 15.132 +/* Return a pager initialised with a provider, page mapper and accessor. */ 15.133 15.134 long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager) 15.135 { 15.136 std::lock_guard<std::mutex> guard(_lock); 15.137 15.138 - /* Obtain any existing page mapper registered for the file, or make a new 15.139 - page mapper. */ 15.140 + /* Obtain any existing provider registered for the file, or make a new 15.141 + provider. */ 15.142 15.143 - PageMapper *mapper; 15.144 - long err = get_mapper(opening, path, flags, fileid, &mapper); 15.145 + FileProvider *provider; 15.146 + long err = get_provider(opening, path, flags, fileid, &provider); 15.147 15.148 if (err) 15.149 return err; 15.150 15.151 - /* Initialise the pager with the mapper and a reference to this object for 15.152 - closing the mapper and accessor. */ 15.153 + /* Initialise the pager with the provider and a reference to this object for 15.154 + closing the provider, mapper and accessor. */ 15.155 15.156 - *pager = new FilePager(fileid, mapper, get_flags(flags), this); 15.157 + provider->attach(); 15.158 + *pager = new FilePager(fileid, provider, get_flags(flags), this); 15.159 return L4_EOK; 15.160 } 15.161 15.162 /* Detach a pager, potentially removing its resources. */ 15.163 15.164 -void FilePaging::detach_pager(fileid_t fileid, PageMapper *mapper) 15.165 +void FilePaging::detach_pager(fileid_t fileid, Accountable *provider) 15.166 { 15.167 std::lock_guard<std::mutex> guard(_lock); 15.168 15.169 - if (!mapper->detach()) 15.170 - remove(fileid, mapper); 15.171 - 15.172 - _notifiers->detach(fileid); 15.173 -} 15.174 - 15.175 -/* Obtain a file-specific notification manager. */ 15.176 - 15.177 -FileNotification *FilePaging::notifier(fileid_t fileid) 15.178 -{ 15.179 - return _notifiers->get(fileid); 15.180 + if (!provider->detach()) 15.181 + remove(fileid, provider); 15.182 } 15.183 15.184 // vim: tabstop=4 expandtab shiftwidth=4
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/libfsserver/lib/files/file_provider.cc Sun Sep 12 01:14:30 2021 +0200 16.3 @@ -0,0 +1,53 @@ 16.4 +/* 16.5 + * An object providing access to file functionality. 16.6 + * 16.7 + * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 16.8 + * 16.9 + * This program is free software; you can redistribute it and/or 16.10 + * modify it under the terms of the GNU General Public License as 16.11 + * published by the Free Software Foundation; either version 2 of 16.12 + * the License, or (at your option) any later version. 16.13 + * 16.14 + * This program is distributed in the hope that it will be useful, 16.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16.17 + * GNU General Public License for more details. 16.18 + * 16.19 + * You should have received a copy of the GNU General Public License 16.20 + * along with this program; if not, write to the Free Software 16.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, 16.22 + * Boston, MA 02110-1301, USA 16.23 + */ 16.24 + 16.25 +#include "file_provider.h" 16.26 + 16.27 + 16.28 + 16.29 +/* Initialise the provider with a page 'mapper' for the file's contents. */ 16.30 + 16.31 +FileProvider::FileProvider(PageMapper *mapper) 16.32 +: FileNotification(), _mapper(mapper) 16.33 +{ 16.34 +} 16.35 + 16.36 +/* Deallocate the provider's resources. */ 16.37 + 16.38 +FileProvider::~FileProvider() 16.39 +{ 16.40 + /* Accessors are allocated exclusively for page mappers for files, and 16.41 + so can be deleted here. In general, the page mapper may not have 16.42 + exclusive ownership of an accessor. */ 16.43 + 16.44 + Accessor *accessor = _mapper->accessor(); 16.45 + delete _mapper; 16.46 + delete accessor; 16.47 +} 16.48 + 16.49 +/* Return the page mapper provided. */ 16.50 + 16.51 +PageMapper *FileProvider::mapper() 16.52 +{ 16.53 + return _mapper; 16.54 +} 16.55 + 16.56 +// vim: tabstop=4 expandtab shiftwidth=4
17.1 --- a/libfsserver/lib/files/filesystem_resource.cc Sat Sep 11 19:44:57 2021 +0200 17.2 +++ b/libfsserver/lib/files/filesystem_resource.cc Sun Sep 12 01:14:30 2021 +0200 17.3 @@ -24,8 +24,8 @@ 17.4 17.5 /* Support for providing access to user-specific filesystems. */ 17.6 17.7 -FilesystemResource::FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers) 17.8 -: FilePaging(pages, notifiers) 17.9 +FilesystemResource::FilesystemResource(Pages *pages) 17.10 +: FilePaging(pages) 17.11 { 17.12 } 17.13
18.1 --- a/libfsserver/lib/files/host_file_accessor.cc Sat Sep 11 19:44:57 2021 +0200 18.2 +++ b/libfsserver/lib/files/host_file_accessor.cc Sun Sep 12 01:14:30 2021 +0200 18.3 @@ -57,7 +57,11 @@ 18.4 18.5 void HostFileAccessor::close() 18.6 { 18.7 + if (_closed) 18.8 + return; 18.9 + 18.10 fclose(_fp); 18.11 + _closed = true; 18.12 } 18.13 18.14 /* Data transfer helper methods. */
19.1 --- a/libfsserver/lib/generic/accessor.cc Sat Sep 11 19:44:57 2021 +0200 19.2 +++ b/libfsserver/lib/generic/accessor.cc Sun Sep 12 01:14:30 2021 +0200 19.3 @@ -32,6 +32,7 @@ 19.4 19.5 Accessor::~Accessor() 19.6 { 19.7 + close(); 19.8 } 19.9 19.10 /* Perform any closing operation on the file. */
20.1 --- a/libfsserver/lib/generic/pager.cc Sat Sep 11 19:44:57 2021 +0200 20.2 +++ b/libfsserver/lib/generic/pager.cc Sun Sep 12 01:14:30 2021 +0200 20.3 @@ -31,18 +31,12 @@ 20.4 Pager::Pager(PageMapper *mapper, map_flags_t flags) 20.5 : _start(0), _size(0), _mapper(mapper), _flags(flags) 20.6 { 20.7 - /* Some pagers may not be initialised with a mapper. */ 20.8 - 20.9 - if (_mapper != NULL) 20.10 - _mapper->attach(); 20.11 } 20.12 20.13 /* Close the pager. */ 20.14 20.15 void Pager::close() 20.16 { 20.17 - if (_mapper != NULL) 20.18 - _mapper->detach(); 20.19 } 20.20 20.21 /* Flush data to the file. */
21.1 --- a/libfsserver/lib/mapping/page_mapper.cc Sat Sep 11 19:44:57 2021 +0200 21.2 +++ b/libfsserver/lib/mapping/page_mapper.cc Sun Sep 12 01:14:30 2021 +0200 21.3 @@ -24,27 +24,19 @@ 21.4 21.5 21.6 21.7 +/* Provide mapped pages populated with the given 'accessor', with pages obtained 21.8 + from the given 'pages' collection. */ 21.9 + 21.10 PageMapper::PageMapper(Accessor *accessor, Pages *pages) 21.11 : _accessor(accessor), _pages(pages) 21.12 { 21.13 } 21.14 21.15 -/* Accounting methods. */ 21.16 +/* Upon deallocation, purge active pages. */ 21.17 21.18 -/* Detach a pager, purging active pages and closing the accessor if no more 21.19 - pagers are attached. Return whether any pagers are still attached. */ 21.20 - 21.21 -unsigned int PageMapper::detach() 21.22 +PageMapper::~PageMapper() 21.23 { 21.24 - unsigned int attached = Accountable::detach(); 21.25 - 21.26 - if (!attached) 21.27 - { 21.28 - _map.purge(this, _pages); 21.29 - _accessor->close(); 21.30 - } 21.31 - 21.32 - return attached; 21.33 + _map.purge(this, _pages); 21.34 } 21.35 21.36 /* Interface for the pager. */
22.1 --- a/libfsserver/lib/pipes/pipe_accessor.cc Sat Sep 11 19:44:57 2021 +0200 22.2 +++ b/libfsserver/lib/pipes/pipe_accessor.cc Sun Sep 12 01:14:30 2021 +0200 22.3 @@ -42,18 +42,6 @@ 22.4 _size = size; 22.5 } 22.6 22.7 -/* Perform any closing operation on the file. */ 22.8 - 22.9 -void PipeAccessor::close() 22.10 -{ 22.11 -} 22.12 - 22.13 -/* Perform any opening operation on the file. */ 22.14 - 22.15 -void PipeAccessor::open() 22.16 -{ 22.17 -} 22.18 - 22.19 /* Data transfer helper methods. */ 22.20 22.21 void PipeAccessor::fill_populated(Flexpage *flexpage)
23.1 --- a/libfsserver/lib/pipes/pipe_paging.cc Sat Sep 11 19:44:57 2021 +0200 23.2 +++ b/libfsserver/lib/pipes/pipe_paging.cc Sun Sep 12 01:14:30 2021 +0200 23.3 @@ -89,7 +89,6 @@ 23.4 23.5 if (mapper != NULL) 23.6 { 23.7 - mapper->detach(); 23.8 _regions[i] = NULL; 23.9 delete mapper; 23.10 } 23.11 @@ -115,7 +114,6 @@ 23.12 23.13 /* Initialise and record the mapper. */ 23.14 23.15 - mapper->attach(); 23.16 mapper->set_data_size(0); 23.17 23.18 _regions[_writing] = mapper;
24.1 --- a/servers/block_file_server.cc Sat Sep 11 19:44:57 2021 +0200 24.2 +++ b/servers/block_file_server.cc Sun Sep 12 01:14:30 2021 +0200 24.3 @@ -66,8 +66,7 @@ 24.4 MemoryIncremental mem(memory_pages); 24.5 PageQueueShared queue; 24.6 Pages pages(&mem, &queue); 24.7 - FileNotifierRegistry notifiers; 24.8 - FilePaging paging(&pages, ¬ifiers); 24.9 + FilePaging paging(&pages); 24.10 BlockFileOpener opener(&paging); 24.11 24.12 /* Register a server associating it with the given object. */
25.1 --- a/servers/client_file_server.cc Sat Sep 11 19:44:57 2021 +0200 25.2 +++ b/servers/client_file_server.cc Sun Sep 12 01:14:30 2021 +0200 25.3 @@ -67,8 +67,7 @@ 25.4 MemoryIncremental mem(memory_pages); 25.5 PageQueueShared queue; 25.6 Pages pages(&mem, &queue); 25.7 - FileNotifierRegistry notifiers; 25.8 - FilePaging paging(&pages, ¬ifiers); 25.9 + FilePaging paging(&pages); 25.10 ClientFileOpener opener(&paging); 25.11 25.12 /* Register a server associating it with the given object. */
26.1 --- a/servers/ext2_file_server.cc Sat Sep 11 19:44:57 2021 +0200 26.2 +++ b/servers/ext2_file_server.cc Sun Sep 12 01:14:30 2021 +0200 26.3 @@ -94,9 +94,8 @@ 26.4 MemoryIncremental mem(memory_pages); 26.5 PageQueueShared queue; 26.6 Pages pages(&mem, &queue); 26.7 - FileNotifierRegistry notifiers; 26.8 - FilePaging paging(&pages, ¬ifiers); 26.9 - Ext2Filesystem filesystem(&pages, ¬ifiers, fs); 26.10 + FilePaging paging(&pages); 26.11 + Ext2Filesystem filesystem(&pages, fs); 26.12 26.13 /* Register a server associating it with the given object. */ 26.14
27.1 --- a/servers/host_file_server.cc Sat Sep 11 19:44:57 2021 +0200 27.2 +++ b/servers/host_file_server.cc Sun Sep 12 01:14:30 2021 +0200 27.3 @@ -66,8 +66,7 @@ 27.4 MemoryIncremental mem(memory_pages); 27.5 PageQueueShared queue; 27.6 Pages pages(&mem, &queue); 27.7 - FileNotifierRegistry notifiers; 27.8 - FilePaging paging(&pages, ¬ifiers); 27.9 + FilePaging paging(&pages); 27.10 HostFileOpener opener(&paging); 27.11 27.12 /* Register a server associating it with the given object. */
28.1 --- a/servers/test_file_server.cc Sat Sep 11 19:44:57 2021 +0200 28.2 +++ b/servers/test_file_server.cc Sun Sep 12 01:14:30 2021 +0200 28.3 @@ -65,8 +65,7 @@ 28.4 MemoryIncremental mem(memory_pages, page(REGION_PAGES)); 28.5 PageQueueShared queue; 28.6 Pages pages(&mem, &queue); 28.7 - FileNotifierRegistry notifiers; 28.8 - FilePaging paging(&pages, ¬ifiers); 28.9 + FilePaging paging(&pages); 28.10 TestFileOpener opener(&paging, page(FILE_PAGES)); 28.11 28.12 /* Register a server associating it with the given object. */