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_notifier_registry.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 41 42 /* A registry of mappers for accessors. */ 43 44 class FilePaging 45 { 46 protected: 47 Pages *_pages; 48 FileNotifierRegistry *_notifiers; 49 FileMapping _mappers; 50 std::mutex _lock; 51 52 /* Mapper registry access. */ 53 54 PageMapper *get(fileid_t fileid); 55 56 void remove(fileid_t fileid, PageMapper *mapper); 57 58 void set(fileid_t fileid, PageMapper *mapper); 59 60 /* Pager initialisation methods. */ 61 62 map_flags_t get_flags(flags_t flags); 63 64 long get_mapper(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, PageMapper **mapper); 65 66 public: 67 explicit FilePaging(Pages *pages, FileNotifierRegistry *notifiers); 68 69 /* Pager initialisation methods. */ 70 71 long get_pager(FileOpening *opening, const char *path, flags_t flags, fileid_t fileid, Pager **pager); 72 73 /* Methods for the pager. */ 74 75 void detach_pager(fileid_t fileid, PageMapper *mapper); 76 77 FileNotification *notifier(fileid_t fileid); 78 }; 79 80 // vim: tabstop=4 expandtab shiftwidth=4