# HG changeset patch # User Paul Boddie # Date 1631402070 -7200 # Node ID 1c25ab9b76794feeb7a86523e466ca7b504a8da2 # Parent 31144210aa37014b371f041e269d60204ce96f2e Introduced file provider objects to manage notifications for each file and to provide access to each file's page mapper. This eliminates the file notification manager registry previously introduced. diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/accessor.h --- a/libfsserver/include/fsserver/accessor.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/accessor.h Sun Sep 12 01:14:30 2021 +0200 @@ -30,6 +30,7 @@ class Accessor { protected: + bool _closed = false; offset_t _size; /* Data transfer helper methods. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/ext2_filesystem.h --- a/libfsserver/include/fsserver/ext2_filesystem.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/ext2_filesystem.h Sun Sep 12 01:14:30 2021 +0200 @@ -37,7 +37,7 @@ Ext2FileOperations *_ops; public: - explicit Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs); + explicit Ext2Filesystem(Pages *pages, ext2_filsys fs); virtual ~Ext2Filesystem(); diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/file_notifier_registry.h --- a/libfsserver/include/fsserver/file_notifier_registry.h Sat Sep 11 19:44:57 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * 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 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/file_pager.h --- a/libfsserver/include/fsserver/file_pager.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/file_pager.h Sun Sep 12 01:14:30 2021 +0200 @@ -33,6 +33,7 @@ { protected: FilePaging *_paging; + FileProvider *_provider; /* Notification endpoint for event subscription. */ @@ -45,7 +46,7 @@ public: fileid_t fileid; - explicit FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, + explicit FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags, FilePaging *paging); virtual void close(); diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/file_paging.h --- a/libfsserver/include/fsserver/file_paging.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/file_paging.h Sun Sep 12 01:14:30 2021 +0200 @@ -1,5 +1,5 @@ /* - * A registry of objects supporting paging for files. + * A registry of filesystem objects. * * Copyright (C) 2021 Paul Boddie * @@ -24,9 +24,9 @@ #include #include -#include +#include #include -#include +#include #include #include @@ -34,37 +34,36 @@ /* Mapping type from file identifiers to page mappers. */ -typedef std::map FileMapping; -typedef std::pair FileMappingEntry; +typedef std::map FileMapping; +typedef std::pair FileMappingEntry; -/* A registry of mappers for accessors. */ +/* A registry of filesystem objects. */ class FilePaging { protected: Pages *_pages; - FileNotifierRegistry *_notifiers; - FileMapping _mappers; + FileMapping _providers; std::mutex _lock; - /* Mapper registry access. */ + /* Filesystem object access. */ - PageMapper *get(fileid_t fileid); + Accountable *get(fileid_t fileid); - void remove(fileid_t fileid, PageMapper *mapper); + void remove(fileid_t fileid, Accountable *obj); - void set(fileid_t fileid, PageMapper *mapper); + void set(fileid_t fileid, Accountable *obj); /* Pager initialisation methods. */ map_flags_t get_flags(flags_t flags); - long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); + long get_provider(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, FileProvider **file_provider); public: - explicit FilePaging(Pages *pages, FileNotifierRegistry *notifiers); + explicit FilePaging(Pages *pages); /* Pager initialisation methods. */ @@ -72,9 +71,7 @@ /* Methods for the pager. */ - void detach_pager(fileid_t fileid, PageMapper *mapper); - - FileNotification *notifier(fileid_t fileid); + void detach_pager(fileid_t fileid, Accountable *mapper); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/file_provider.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/include/fsserver/file_provider.h Sun Sep 12 01:14:30 2021 +0200 @@ -0,0 +1,44 @@ +/* + * An object encapsulating file resources. + * + * 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 + + + +/* An object providing access to file functionality. */ + +class FileProvider : public FileNotification +{ +protected: + PageMapper *_mapper; + +public: + explicit FileProvider(PageMapper *mapper); + + virtual ~FileProvider(); + + PageMapper *mapper(); +}; + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/filesystem_resource.h --- a/libfsserver/include/fsserver/filesystem_resource.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/filesystem_resource.h Sun Sep 12 01:14:30 2021 +0200 @@ -33,7 +33,7 @@ public FilesystemObject { public: - explicit FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers); + explicit FilesystemResource(Pages *pages); /* Server details. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/page_mapper.h --- a/libfsserver/include/fsserver/page_mapper.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/page_mapper.h Sun Sep 12 01:14:30 2021 +0200 @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -32,7 +31,7 @@ /* A file mapper, associating flexpages with file regions. */ -class PageMapper : public PageOwner, public Accountable +class PageMapper : public PageOwner { protected: AccessMap _map; @@ -52,9 +51,7 @@ public: explicit PageMapper(Accessor *accessor, Pages *pages); - /* Specialised accounting methods. */ - - unsigned int detach(); + virtual ~PageMapper(); Accessor *accessor() { return _accessor; } diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/include/fsserver/pipe_accessor.h --- a/libfsserver/include/fsserver/pipe_accessor.h Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/include/fsserver/pipe_accessor.h Sun Sep 12 01:14:30 2021 +0200 @@ -44,10 +44,6 @@ virtual offset_t get_size(); virtual void set_size(offset_t size); - - virtual void close(); - - virtual void open(); }; // vim: tabstop=4 expandtab shiftwidth=4 diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/Makefile --- a/libfsserver/lib/Makefile Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/Makefile Sun Sep 12 01:14:30 2021 +0200 @@ -48,10 +48,10 @@ 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 \ + files/file_provider.cc \ files/filesystem_resource.cc \ files/host_file_accessor.cc \ files/host_file_opener.cc \ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/ext2_file_accessor.cc --- a/libfsserver/lib/files/ext2_file_accessor.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/ext2_file_accessor.cc Sun Sep 12 01:14:30 2021 +0200 @@ -54,7 +54,11 @@ void Ext2FileAccessor::close() { + if (_closed) + return; + _ops->close_file(_file); + _closed = true; } /* Data transfer helper methods. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/ext2_filesystem.cc --- a/libfsserver/lib/files/ext2_filesystem.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/ext2_filesystem.cc Sun Sep 12 01:14:30 2021 +0200 @@ -24,8 +24,8 @@ #include "ext2_filesystem.h" #include "resource_server.h" -Ext2Filesystem::Ext2Filesystem(Pages *pages, FileNotifierRegistry *notifiers, ext2_filsys fs) -: FilesystemResource(pages, notifiers) +Ext2Filesystem::Ext2Filesystem(Pages *pages, ext2_filsys fs) +: FilesystemResource(pages) { _ops = new Ext2FileOperations(fs); } diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/file_notifier_registry.cc --- a/libfsserver/lib/files/file_notifier_registry.cc Sat Sep 11 19:44:57 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * 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 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/file_pager.cc --- a/libfsserver/lib/files/file_pager.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/file_pager.cc Sun Sep 12 01:14:30 2021 +0200 @@ -24,12 +24,14 @@ -/* Initialise a pager for a file with a unique file identifier and shared page - mapper for moderating access to loaded pages. */ +/* Initialise a pager for a file with a unique file identifier, file provider, + mapping flags and a file paging coordinator. The provider offers a shared + page mapper for moderating access to loaded pages. */ -FilePager::FilePager(fileid_t fileid, PageMapper *mapper, map_flags_t flags, +FilePager::FilePager(fileid_t fileid, FileProvider *provider, map_flags_t flags, FilePaging *paging) -: Pager(mapper, flags), _paging(paging), fileid(fileid) +: Pager(provider->mapper(), flags), + _paging(paging), _provider(provider), fileid(fileid) { } @@ -50,14 +52,13 @@ void FilePager::close() { - _paging->detach_pager(fileid, _mapper); - /* Notify other users of the file. */ - FileNotification *notifier = _paging->notifier(fileid); + _provider->notify_others(_endpoint, NOTIFY_PEER_CLOSED); - if (notifier != NULL) - notifier->notify_others(_endpoint, NOTIFY_PEER_CLOSED); + /* Detach the pager, potentially removing the file provider. */ + + _paging->detach_pager(fileid, _provider); } @@ -70,11 +71,7 @@ if (_resized) { - FileNotification *notifier = _paging->notifier(fileid); - - if (notifier != NULL) - notifier->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); - + _provider->notify_others(_endpoint, NOTIFY_CONTENT_AVAILABLE); _resized = false; } @@ -121,22 +118,13 @@ /* Readers can subscribe to new data (at end), and pipe closed events. Writers can subscribe to new space and pipe closed events. */ - FileNotification *notifier = _paging->notifier(fileid); - - if (notifier == NULL) - return -L4_ENOSYS; - - _endpoint = notifier->subscribe(endpoint, flags); + _endpoint = _provider->subscribe(endpoint, flags); return L4_EOK; } long FilePager::unsubscribe(l4_cap_idx_t endpoint) { - FileNotification *notifier = _paging->notifier(fileid); - - if (notifier != NULL) - notifier->unsubscribe(_endpoint, endpoint); - + _provider->unsubscribe(_endpoint, endpoint); return L4_EOK; } diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/file_paging.cc --- a/libfsserver/lib/files/file_paging.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/file_paging.cc Sun Sep 12 01:14:30 2021 +0200 @@ -26,48 +26,50 @@ -FilePaging::FilePaging(Pages *pages, FileNotifierRegistry *notifiers) -: _pages(pages), _notifiers(notifiers) +/* The file paging coordinator provides a memory page collection to the page + mappers it creates. */ + +FilePaging::FilePaging(Pages *pages) +: _pages(pages) { } -/* Return any registered page mapper for the given 'fileid' or NULL if no such - mapper is registered. */ +/* Return any registered provider for the given 'fileid' or NULL if no such + provider is registered. */ -PageMapper *FilePaging::get(fileid_t fileid) +Accountable *FilePaging::get(fileid_t fileid) { - FileMapping::iterator entry = _mappers.find(fileid); - PageMapper *mapper; + FileMapping::iterator entry = _providers.find(fileid); + Accountable *provider; - if (entry == _mappers.end()) - mapper = NULL; + if (entry == _providers.end()) + provider = NULL; else - mapper = entry->second; + provider = entry->second; - return mapper; + return provider; } -/* Remove a page mapper and its resources for the given 'fileid'. */ +/* Remove a provider and its resources for the given 'fileid'. */ -void FilePaging::remove(fileid_t fileid, PageMapper *mapper) +void FilePaging::remove(fileid_t fileid, Accountable *provider) { - _mappers.erase(fileid); - delete mapper->accessor(); - delete mapper; + _providers.erase(fileid); + delete provider; } -/* Register a page 'mapper' and a notification manager for the given 'fileid'. */ +/* Register a 'provider' for the given 'fileid'. */ -void FilePaging::set(fileid_t fileid, PageMapper *mapper) +void FilePaging::set(fileid_t fileid, Accountable *provider) { - FileMapping::iterator entry = _mappers.find(fileid); + FileMapping::iterator entry = _providers.find(fileid); - if (entry != _mappers.end()) + if (entry != _providers.end()) return; - _mappers[fileid] = mapper; + _providers[fileid] = provider; } @@ -81,19 +83,30 @@ -/* Obtain a page mapper for the 'fileid' or register a new one in the +/* Obtain a provider for the 'fileid' or register a new one in the paging object. */ -long FilePaging::get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper) +long FilePaging::get_provider(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, FileProvider **file_provider) { - /* Obtain any registered page mapper. */ + /* Obtain any registered provider. */ + + Accountable *provider = get(fileid); - *mapper = get(fileid); + if (provider != NULL) + { + /* Distinguish between file providers and other objects that may be + registered. For files specifically, a file provider is needed + because it will provide a page mapper. */ + + *file_provider = dynamic_cast(provider); - if (*mapper != NULL) - return L4_EOK; + if ((*file_provider) != NULL) + return L4_EOK; + else + return -L4_EIO; + } - /* Make an accessor and page mapper, registering the mapper. */ + /* Make an accessor, page mapper, and a provider to encapsulate them. */ Accessor *accessor; long err = opening->make_accessor(path, flags, fileid, &accessor); @@ -101,55 +114,48 @@ if (err) return err; - *mapper = new PageMapper(accessor, _pages); + PageMapper *mapper = new PageMapper(accessor, _pages); + *file_provider = new FileProvider(mapper); - set(fileid, *mapper); - _notifiers->attach(fileid); + /* Register the provider. */ + set(fileid, *file_provider); return L4_EOK; } -/* Return a pager initialised with a page mapper. */ +/* Return a pager initialised with a provider, page mapper and accessor. */ long FilePaging::get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager) { std::lock_guard guard(_lock); - /* Obtain any existing page mapper registered for the file, or make a new - page mapper. */ + /* Obtain any existing provider registered for the file, or make a new + provider. */ - PageMapper *mapper; - long err = get_mapper(opening, path, flags, fileid, &mapper); + FileProvider *provider; + long err = get_provider(opening, path, flags, fileid, &provider); if (err) return err; - /* Initialise the pager with the mapper and a reference to this object for - closing the mapper and accessor. */ + /* Initialise the pager with the provider and a reference to this object for + closing the provider, mapper and accessor. */ - *pager = new FilePager(fileid, mapper, get_flags(flags), this); + provider->attach(); + *pager = new FilePager(fileid, provider, get_flags(flags), this); return L4_EOK; } /* Detach a pager, potentially removing its resources. */ -void FilePaging::detach_pager(fileid_t fileid, PageMapper *mapper) +void FilePaging::detach_pager(fileid_t fileid, Accountable *provider) { std::lock_guard guard(_lock); - if (!mapper->detach()) - remove(fileid, mapper); - - _notifiers->detach(fileid); -} - -/* Obtain a file-specific notification manager. */ - -FileNotification *FilePaging::notifier(fileid_t fileid) -{ - return _notifiers->get(fileid); + if (!provider->detach()) + remove(fileid, provider); } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/file_provider.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfsserver/lib/files/file_provider.cc Sun Sep 12 01:14:30 2021 +0200 @@ -0,0 +1,53 @@ +/* + * An object providing access to file functionality. + * + * 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_provider.h" + + + +/* Initialise the provider with a page 'mapper' for the file's contents. */ + +FileProvider::FileProvider(PageMapper *mapper) +: FileNotification(), _mapper(mapper) +{ +} + +/* Deallocate the provider's resources. */ + +FileProvider::~FileProvider() +{ + /* Accessors are allocated exclusively for page mappers for files, and + so can be deleted here. In general, the page mapper may not have + exclusive ownership of an accessor. */ + + Accessor *accessor = _mapper->accessor(); + delete _mapper; + delete accessor; +} + +/* Return the page mapper provided. */ + +PageMapper *FileProvider::mapper() +{ + return _mapper; +} + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/filesystem_resource.cc --- a/libfsserver/lib/files/filesystem_resource.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/filesystem_resource.cc Sun Sep 12 01:14:30 2021 +0200 @@ -24,8 +24,8 @@ /* Support for providing access to user-specific filesystems. */ -FilesystemResource::FilesystemResource(Pages *pages, FileNotifierRegistry *notifiers) -: FilePaging(pages, notifiers) +FilesystemResource::FilesystemResource(Pages *pages) +: FilePaging(pages) { } diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/files/host_file_accessor.cc --- a/libfsserver/lib/files/host_file_accessor.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/files/host_file_accessor.cc Sun Sep 12 01:14:30 2021 +0200 @@ -57,7 +57,11 @@ void HostFileAccessor::close() { + if (_closed) + return; + fclose(_fp); + _closed = true; } /* Data transfer helper methods. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/generic/accessor.cc --- a/libfsserver/lib/generic/accessor.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/generic/accessor.cc Sun Sep 12 01:14:30 2021 +0200 @@ -32,6 +32,7 @@ Accessor::~Accessor() { + close(); } /* Perform any closing operation on the file. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/generic/pager.cc --- a/libfsserver/lib/generic/pager.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/generic/pager.cc Sun Sep 12 01:14:30 2021 +0200 @@ -31,18 +31,12 @@ Pager::Pager(PageMapper *mapper, map_flags_t flags) : _start(0), _size(0), _mapper(mapper), _flags(flags) { - /* Some pagers may not be initialised with a mapper. */ - - if (_mapper != NULL) - _mapper->attach(); } /* Close the pager. */ void Pager::close() { - if (_mapper != NULL) - _mapper->detach(); } /* Flush data to the file. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/mapping/page_mapper.cc --- a/libfsserver/lib/mapping/page_mapper.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/mapping/page_mapper.cc Sun Sep 12 01:14:30 2021 +0200 @@ -24,27 +24,19 @@ +/* Provide mapped pages populated with the given 'accessor', with pages obtained + from the given 'pages' collection. */ + PageMapper::PageMapper(Accessor *accessor, Pages *pages) : _accessor(accessor), _pages(pages) { } -/* Accounting methods. */ +/* Upon deallocation, purge active pages. */ -/* Detach a pager, purging active pages and closing the accessor if no more - pagers are attached. Return whether any pagers are still attached. */ - -unsigned int PageMapper::detach() +PageMapper::~PageMapper() { - unsigned int attached = Accountable::detach(); - - if (!attached) - { - _map.purge(this, _pages); - _accessor->close(); - } - - return attached; + _map.purge(this, _pages); } /* Interface for the pager. */ diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/pipes/pipe_accessor.cc --- a/libfsserver/lib/pipes/pipe_accessor.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_accessor.cc Sun Sep 12 01:14:30 2021 +0200 @@ -42,18 +42,6 @@ _size = size; } -/* Perform any closing operation on the file. */ - -void PipeAccessor::close() -{ -} - -/* Perform any opening operation on the file. */ - -void PipeAccessor::open() -{ -} - /* Data transfer helper methods. */ void PipeAccessor::fill_populated(Flexpage *flexpage) diff -r 31144210aa37 -r 1c25ab9b7679 libfsserver/lib/pipes/pipe_paging.cc --- a/libfsserver/lib/pipes/pipe_paging.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_paging.cc Sun Sep 12 01:14:30 2021 +0200 @@ -89,7 +89,6 @@ if (mapper != NULL) { - mapper->detach(); _regions[i] = NULL; delete mapper; } @@ -115,7 +114,6 @@ /* Initialise and record the mapper. */ - mapper->attach(); mapper->set_data_size(0); _regions[_writing] = mapper; diff -r 31144210aa37 -r 1c25ab9b7679 servers/block_file_server.cc --- a/servers/block_file_server.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/servers/block_file_server.cc Sun Sep 12 01:14:30 2021 +0200 @@ -66,8 +66,7 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FileNotifierRegistry notifiers; - FilePaging paging(&pages, ¬ifiers); + FilePaging paging(&pages); BlockFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 31144210aa37 -r 1c25ab9b7679 servers/client_file_server.cc --- a/servers/client_file_server.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/servers/client_file_server.cc Sun Sep 12 01:14:30 2021 +0200 @@ -67,8 +67,7 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FileNotifierRegistry notifiers; - FilePaging paging(&pages, ¬ifiers); + FilePaging paging(&pages); ClientFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 31144210aa37 -r 1c25ab9b7679 servers/ext2_file_server.cc --- a/servers/ext2_file_server.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/servers/ext2_file_server.cc Sun Sep 12 01:14:30 2021 +0200 @@ -94,9 +94,8 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FileNotifierRegistry notifiers; - FilePaging paging(&pages, ¬ifiers); - Ext2Filesystem filesystem(&pages, ¬ifiers, fs); + FilePaging paging(&pages); + Ext2Filesystem filesystem(&pages, fs); /* Register a server associating it with the given object. */ diff -r 31144210aa37 -r 1c25ab9b7679 servers/host_file_server.cc --- a/servers/host_file_server.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/servers/host_file_server.cc Sun Sep 12 01:14:30 2021 +0200 @@ -66,8 +66,7 @@ MemoryIncremental mem(memory_pages); PageQueueShared queue; Pages pages(&mem, &queue); - FileNotifierRegistry notifiers; - FilePaging paging(&pages, ¬ifiers); + FilePaging paging(&pages); HostFileOpener opener(&paging); /* Register a server associating it with the given object. */ diff -r 31144210aa37 -r 1c25ab9b7679 servers/test_file_server.cc --- a/servers/test_file_server.cc Sat Sep 11 19:44:57 2021 +0200 +++ b/servers/test_file_server.cc Sun Sep 12 01:14:30 2021 +0200 @@ -65,8 +65,7 @@ MemoryIncremental mem(memory_pages, page(REGION_PAGES)); PageQueueShared queue; Pages pages(&mem, &queue); - FileNotifierRegistry notifiers; - FilePaging paging(&pages, ¬ifiers); + FilePaging paging(&pages); TestFileOpener opener(&paging, page(FILE_PAGES)); /* Register a server associating it with the given object. */