1 /* 2 * A registry of objects supporting paging for files. 3 * 4 * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <map> 25 #include <mutex> 26 27 #include <fsserver/file_notification.h> 28 #include <fsserver/file_opening.h> 29 #include <fsserver/page_mapper.h> 30 #include <fsserver/pager.h> 31 #include <fsserver/pages.h> 32 33 34 35 /* Mapping type from file identifiers to page mappers. */ 36 37 typedef std::map<fileid_t, PageMapper *> FileMapping; 38 typedef std::pair<fileid_t, PageMapper *> FileMappingEntry; 39 40 /* Mapping type from file identifiers to notification managers. */ 41 42 typedef std::map<fileid_t, FileNotification *> FileNotifiers; 43 typedef std::map<fileid_t, FileNotification *> FileNotifierEntry; 44 45 46 47 /* A registry of mappers for accessors. */ 48 49 class FilePaging 50 { 51 protected: 52 Pages *_pages; 53 FileMapping _mappers; 54 FileNotifiers _notifiers; 55 std::mutex _lock; 56 57 /* Mapper registry access. */ 58 59 PageMapper *get(fileid_t fileid); 60 61 void remove(fileid_t fileid, PageMapper *mapper); 62 63 void set(fileid_t fileid, PageMapper *mapper); 64 65 /* Pager initialisation methods. */ 66 67 map_flags_t get_flags(flags_t flags); 68 69 long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 70 71 /* Notification manager access. */ 72 73 FileNotification *get_notifier(fileid_t fileid); 74 75 void remove(fileid_t fileid, FileNotification *notifier); 76 77 public: 78 explicit FilePaging(Pages *pages); 79 80 /* Pager initialisation methods. */ 81 82 long get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager); 83 84 /* Methods for the pager. */ 85 86 void detach_pager(fileid_t fileid, PageMapper *mapper); 87 88 FileNotification *notifier(fileid_t fileid); 89 }; 90 91 // vim: tabstop=4 expandtab shiftwidth=4